Giter Club home page Giter Club logo

Comments (6)

1gravity avatar 1gravity commented on June 19, 2024

I can't reproduce the issue, it works perfectly for me, mRTMessageField.getText(RTFormat.HTML) returns html for Italic and Bold. The rich text editor is used in thousands of installations, if there was indeed that issue, my users would have complained already.
You can save the text in the demo app and reload it which will show you that the formatting is indeed saved.

from android-rteditor.

jakubkrolewski avatar jakubkrolewski commented on June 19, 2024

The saved HTML file is completely empty, but that's another problem.
I tested on Nexus 5, Android 4.4.4.
I debugged the problem a little bit. In ConverterSpannedToHtml class, the line 251:
List<CharacterStyle> spanList = Arrays.asList(text.getSpans(start, end, CharacterStyle.class));
returns a single element list with
0 = {StyleSpan@830046449792} mStyle = 1.
I don't know why it's not the BoldSpan as it was initially inserted, but that's what's there.
I propose to fix the problem by generating a html tag both from the BoldSpan and StyleSpan. It not only fixes the problem I describe, but also make the ConverterSpannedToHtml a better general purpose tool.

from android-rteditor.

1gravity avatar 1gravity commented on June 19, 2024

My Nexus 5 (although running Android M) has no such issue. Also tested it on an S3 running KitKat.

I don't want a workaround for an issue if the root cause isn't known and might lead to other (yet unknown) issues. As I said thousands of users use this component and no one has ever reported anything like this so let's find out what's special about your device.

Anything out of the ordinary on your device? rooted? custom 4.4.4? any suspicious apps installed? do you use a custom font?
What happens if you rotate the screen to landscape, is the bold text still there?

BTW I suggest you contact me by email to solve this: [email protected]

from android-rteditor.

jakubkrolewski avatar jakubkrolewski commented on June 19, 2024

After some more tests I've found the proper scenario to reproduce the problem:

  1. Enable "don't keep activities" in the developer options
  2. Start demo activity
  3. Press "bold"
  4. Type "Hello"
  5. Press HOME
  6. Go back to the demo application

That should be it.

The problem is that the onSaveInstanceState method in TextView uses the TextUtils#writeToParcel method for saving text and this method can handle only built-in spans. I don't think that it's possible to extend this mechanism for custom spans.
I see two possible solutions for the problem of saving and restoring state:

  1. Copy the whole spans parcelling mechanism and modify the copied code to support custom spans
  2. Use the built-in mechanism, but after restoring text convert all the spans to custom versions (I know that we can easily convert a StyleSpan to BoldSpan, but I don't know if that's so easy for other spans in the library).

from android-rteditor.

1gravity avatar 1gravity commented on June 19, 2024

I went for option 3 ;-).

The proper way to handle this is to save the view state in onSaveInstanceState and restore it in onRestoreInstanceState. By saving the text as html and restoring it from that html we can retain all custom span objects.

Fixed with 9ac8f6a

from android-rteditor.

jakubkrolewski avatar jakubkrolewski commented on June 19, 2024

Indeed, the third solution sounds better:)
It works great now. Thanks :)

from android-rteditor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.