RTEditor/src/main/java/com/onegravity/rteditor/RTManager.java
private void insertImage(final RTEditText editor, final RTImage image) {
        if (image != null && editor != null) {
            Selection selection = new Selection(editor);
            Editable str = editor.getText();

            // Unicode Character 'OBJECT REPLACEMENT CHARACTER' (U+FFFC)
            // see http://www.fileformat.info/info/unicode/char/fffc/index.htm
            str.insert(selection.start(), "\uFFFC");

            try {
                // now add the actual image and inform the RTOperationManager about the operation
                Spannable oldSpannable = editor.cloneSpannable();

                ImageSpan imageSpan = new ImageSpan(image, false);
                str.setSpan(imageSpan, selection.start(), selection.end() + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                int selStartAfter = editor.getSelectionStart();
                int selEndAfter = editor.getSelectionEnd();
                editor.onAddMedia(image);

                Spannable newSpannable = editor.cloneSpannable();

                mOPManager.executed(editor, new RTOperationManager.TextChangeOperation(oldSpannable, newSpannable,
                        selection.start(), selection.end(), selStartAfter, selEndAfter));
            } catch (OutOfMemoryError e) {
                str.delete(selection.start(), selection.end() + 1);
                mRTApi.makeText(R.string.rte_add_image_error, Toast.LENGTH_LONG).show();
            }
        }
    }
private void insertImage(final RTEditText editor, final RTImage image) {
        if (image != null && editor != null) {
            Selection selection = new Selection(editor);
            Editable str = editor.getText();

            // Unicode Character 'OBJECT REPLACEMENT CHARACTER' (U+FFFC)
            // see http://www.fileformat.info/info/unicode/char/fffc/index.htm
            str.insert(selection.start(), "\uFFFC");

            try {
                // now add the actual image and inform the RTOperationManager about the operation
                Spannable oldSpannable = editor.cloneSpannable();

                ImageSpan imageSpan = new ImageSpan(image, false);
                str.setSpan(imageSpan, selection.start(), selection.end() + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                int selStartAfter = editor.getSelectionStart();
                int selEndAfter = editor.getSelectionEnd();
                editor.onAddMedia(image);

                Spannable newSpannable = editor.cloneSpannable();

                mOPManager.executed(editor, new RTOperationManager.TextChangeOperation(oldSpannable, newSpannable,
                        selection.start(), selection.end(), selStartAfter, selEndAfter));
            } catch (OutOfMemoryError e) {
                str.delete(selection.start(), selection.end() + 1);
                mRTApi.makeText(R.string.rte_add_image_error, Toast.LENGTH_LONG).show();
            }
        }
    }
/* called from onEventMainThread(MediaEvent)