RTEditor/src/main/java/com/onegravity/rteditor/RTEditText.java
public void setText(RTText rtText) {
        assertRegistration();

        if (rtText.getFormat() instanceof RTFormat.Html) {
            if (mUseRTFormatting) {
                RTText rtSpanned = rtText.convertTo(RTFormat.SPANNED, mMediaFactory);

                super.setText(rtSpanned.getText(), TextView.BufferType.EDITABLE);
                addSpanWatcher();

                // collect all current media
                Spannable text = getText();
                for (MediaSpan span : text.getSpans(0, text.length(), MediaSpan.class)) {
                    mOriginalMedia.add(span.getMedia());
                }

                Effects.cleanupParagraphs(this);
            } else {
                RTText rtPlainText = rtText.convertTo(RTFormat.PLAIN_TEXT, mMediaFactory);
                super.setText(rtPlainText.getText());
            }
        } else if (rtText.getFormat() instanceof RTFormat.PlainText) {
            CharSequence text = rtText.getText();
            super.setText(text == null ? "" : text.toString());
        }

        onSelectionChanged(0, 0);
    }
public void setText(RTText rtText) {
        assertRegistration();

        if (rtText.getFormat() instanceof RTFormat.Html) {
            if (mUseRTFormatting) {
                RTText rtSpanned = rtText.convertTo(RTFormat.SPANNED, mMediaFactory);

                super.setText(rtSpanned.getText(), TextView.BufferType.EDITABLE);
                addSpanWatcher();

                // collect all current media
                Spannable text = getText();
                for (MediaSpan span : text.getSpans(0, text.length(), MediaSpan.class)) {
                    mOriginalMedia.add(span.getMedia());
                }

                Effects.cleanupParagraphs(this);
            } else {
                RTText rtPlainText = rtText.convertTo(RTFormat.PLAIN_TEXT, mMediaFactory);
                super.setText(rtPlainText.getText());
            }
        } else if (rtText.getFormat() instanceof RTFormat.PlainText) {
            CharSequence text = rtText.getText();
            super.setText(text == null ? "" : text.toString());
        }

        onSelectionChanged(0, 0);
    }
Set the text for this editor.
<p>
It will convert the text from rich text to plain text if the editor's
mode is set to use plain text. or to a spanned text (only supported
formatting) if the editor's mode is set to use rich text
<p>
We need to prevent onSelectionChanged() to do anything as long as
setText() hasn't finished because the Layout doesn't seem to update
before setText has finished but onSelectionChanged will still be called
during setText and will receive the out-dated Layout which doesn't allow
us to apply styles and such.