Bug 781038 - Part 2: Extract setSpan() and setSelection() boilerplate into a convenience method. r=blassey

This commit is contained in:
Chris Peterson 2012-08-07 16:14:23 -07:00
parent 4f473d04af
commit 3a4e55169e

View File

@ -95,8 +95,7 @@ class GeckoInputConnection
private int mCompositionStart = NO_COMPOSITION_STRING;
private boolean mCommittingText;
private KeyCharacterMap mKeyCharacterMap;
private Editable mEditable;
private Editable.Factory mEditableFactory;
private final Editable mEditable;
private boolean mBatchMode;
private ExtractedTextRequest mUpdateRequest;
private final ExtractedText mUpdateExtract = new ExtractedText();
@ -110,9 +109,8 @@ class GeckoInputConnection
protected GeckoInputConnection(View targetView) {
super(targetView, true);
mEditableFactory = Editable.Factory.getInstance();
initEditable("");
mEditable = Editable.Factory.getInstance().newEditable("");
spanAndSelectEditable();
mIMEState = IME_STATE_DISABLED;
mIMETypeHint = "";
mIMEActionHint = "";
@ -1152,16 +1150,13 @@ class GeckoInputConnection
int prevLength = mEditable.length();
mEditable.removeSpan(this);
mEditable.replace(0, prevLength, contents);
int newLength = mEditable.length();
mEditable.setSpan(this, 0, newLength, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
Selection.setSelection(mEditable, newLength);
spanAndSelectEditable();
}
private void initEditable(String contents) {
mEditable = mEditableFactory.newEditable(contents);
int newLength = mEditable.length();
mEditable.setSpan(this, 0, newLength, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
Selection.setSelection(mEditable, newLength);
private void spanAndSelectEditable() {
int length = mEditable.length();
mEditable.setSpan(this, 0, length, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
Selection.setSelection(mEditable, length);
}
protected final boolean hasCompositionString() {