Fix an NPE
Also remove an unused method and make 2 private variables final. Bug: 8461093 Change-Id: I676d93fda28e82eb5a6978f2e7ad5a0add2cbecfmain
parent
48d8d8d0ae
commit
740da0d8d0
|
@ -60,11 +60,11 @@ public final class RichInputConnection {
|
||||||
* This contains the committed text immediately preceding the cursor and the composing
|
* This contains the committed text immediately preceding the cursor and the composing
|
||||||
* text if any. It is refreshed when the cursor moves by calling upon the TextView.
|
* text if any. It is refreshed when the cursor moves by calling upon the TextView.
|
||||||
*/
|
*/
|
||||||
private StringBuilder mCommittedTextBeforeComposingText = new StringBuilder();
|
private final StringBuilder mCommittedTextBeforeComposingText = new StringBuilder();
|
||||||
/**
|
/**
|
||||||
* This contains the currently composing text, as LatinIME thinks the TextView is seeing it.
|
* This contains the currently composing text, as LatinIME thinks the TextView is seeing it.
|
||||||
*/
|
*/
|
||||||
private StringBuilder mComposingText = new StringBuilder();
|
private final StringBuilder mComposingText = new StringBuilder();
|
||||||
// A hint on how many characters to cache from the TextView. A good value of this is given by
|
// A hint on how many characters to cache from the TextView. A good value of this is given by
|
||||||
// how many characters we need to be able to almost always find the caps mode.
|
// how many characters we need to be able to almost always find the caps mode.
|
||||||
private static final int DEFAULT_TEXT_CACHE_SIZE = 100;
|
private static final int DEFAULT_TEXT_CACHE_SIZE = 100;
|
||||||
|
@ -334,13 +334,15 @@ public final class RichInputConnection {
|
||||||
mCurrentCursorPosition = end;
|
mCurrentCursorPosition = end;
|
||||||
final CharSequence textBeforeCursor =
|
final CharSequence textBeforeCursor =
|
||||||
getTextBeforeCursor(DEFAULT_TEXT_CACHE_SIZE + (end - start), 0);
|
getTextBeforeCursor(DEFAULT_TEXT_CACHE_SIZE + (end - start), 0);
|
||||||
final int indexOfStartOfComposingText =
|
|
||||||
Math.max(textBeforeCursor.length() - (end - start), 0);
|
|
||||||
mComposingText.append(textBeforeCursor.subSequence(indexOfStartOfComposingText,
|
|
||||||
textBeforeCursor.length()));
|
|
||||||
mCommittedTextBeforeComposingText.setLength(0);
|
mCommittedTextBeforeComposingText.setLength(0);
|
||||||
mCommittedTextBeforeComposingText.append(
|
if (!TextUtils.isEmpty(textBeforeCursor)) {
|
||||||
textBeforeCursor.subSequence(0, indexOfStartOfComposingText));
|
final int indexOfStartOfComposingText =
|
||||||
|
Math.max(textBeforeCursor.length() - (end - start), 0);
|
||||||
|
mComposingText.append(textBeforeCursor.subSequence(indexOfStartOfComposingText,
|
||||||
|
textBeforeCursor.length()));
|
||||||
|
mCommittedTextBeforeComposingText.append(
|
||||||
|
textBeforeCursor.subSequence(0, indexOfStartOfComposingText));
|
||||||
|
}
|
||||||
if (null != mIC) {
|
if (null != mIC) {
|
||||||
mIC.setComposingRegion(start, end);
|
mIC.setComposingRegion(start, end);
|
||||||
}
|
}
|
||||||
|
@ -502,16 +504,6 @@ public final class RichInputConnection {
|
||||||
return (r == null) ? null : r.mWord;
|
return (r == null) ? null : r.mWord;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getCursorPosition() {
|
|
||||||
mIC = mParent.getCurrentInputConnection();
|
|
||||||
if (null == mIC) return INVALID_CURSOR_POSITION;
|
|
||||||
final ExtractedText extracted = mIC.getExtractedText(new ExtractedTextRequest(), 0);
|
|
||||||
if (extracted == null) {
|
|
||||||
return INVALID_CURSOR_POSITION;
|
|
||||||
}
|
|
||||||
return extracted.startOffset + extracted.selectionStart;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the text surrounding the cursor.
|
* Returns the text surrounding the cursor.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue