Code example for Editable

Methods: getSelectionEnd, getSelectionStart, length, replace, setSelection, toString

0
            int prevSelectionStart = Selection.getSelectionStart(mEditable);
            int prevSelectionEnd = Selection.getSelectionEnd(mEditable);
            int prevEditableLength = mEditable.length();
            int prevCompositionStart = getComposingSpanStart(mEditable);
            int prevCompositionEnd = getComposingSpanEnd(mEditable);
            String prevText = mEditable.toString();
 
            selectionStart = Math.min(selectionStart, text.length());
            selectionEnd = Math.min(selectionEnd, text.length());
            compositionStart = Math.min(compositionStart, text.length());
            compositionEnd = Math.min(compositionEnd, text.length());
 
            boolean textUnchanged = prevText.equals(text);
 
            if (textUnchanged
                    && prevSelectionStart == selectionStart && prevSelectionEnd == selectionEnd
                    && prevCompositionStart == compositionStart
                    && prevCompositionEnd == compositionEnd) {
                // Nothing has changed; don't need to do anything 
                return; 
            } 
 
            // When a programmatic change has been made to the editable field, both the start 
            // and end positions for the composition will equal zero. In this case we cancel the 
            // active composition in the editor as this no longer is relevant. 
            if (textUnchanged && compositionStart == 0 && compositionEnd == 0) {
                cancelComposition(); 
            } 
 
            if (!textUnchanged) {
                mEditable.replace(0, mEditable.length(), text);
            } 
            Selection.setSelection(mEditable, selectionStart, selectionEnd);
            super.setComposingRegion(compositionStart, compositionEnd);
 
            if (textUnchanged || prevText.equals("")) {