aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorTadashi G. Takaoka <takaoka@google.com>2012-10-02 22:41:25 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2012-10-02 22:41:25 -0700
commitace7d1285dc1d4ba42d4f767698c5b6078ecbac2 (patch)
tree4ffba8ea02830105f386734a431e7f0565c51587 /java/src
parentde102ede499cd3baf93561d06c5fe3e663276d2e (diff)
parentd445b56ce14152b30143302899790af255691148 (diff)
downloadlatinime-ace7d1285dc1d4ba42d4f767698c5b6078ecbac2.tar.gz
latinime-ace7d1285dc1d4ba42d4f767698c5b6078ecbac2.tar.xz
latinime-ace7d1285dc1d4ba42d4f767698c5b6078ecbac2.zip
am d445b56c: Fix possible NPE caused while monkey test
* commit 'd445b56ce14152b30143302899790af255691148': Fix possible NPE caused while monkey test
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java6
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java8
-rw-r--r--java/src/com/android/inputmethod/latin/WordComposer.java18
3 files changed, 21 insertions, 11 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index 88d7b667f..e99e956e2 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -390,7 +390,11 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
}
public int getManualCapsMode() {
- switch (getKeyboard().mId.mElementId) {
+ final Keyboard keyboard = getKeyboard();
+ if (keyboard == null) {
+ return WordComposer.CAPS_MODE_OFF;
+ }
+ switch (keyboard.mId.mElementId) {
case KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED:
case KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED:
return WordComposer.CAPS_MODE_MANUAL_SHIFT_LOCKED;
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 311355374..fe6ad4901 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1910,6 +1910,10 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
}
private SuggestedWords getSuggestedWords(final int sessionId) {
+ final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
+ if (keyboard == null) {
+ return SuggestedWords.EMPTY;
+ }
final String typedWord = mWordComposer.getTypedWord();
// Get the word on which we should search the bigrams. If we are composing a word, it's
// whatever is *before* the half-committed word in the buffer, hence 2; if we aren't, we
@@ -1919,8 +1923,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
mConnection.getNthPreviousWord(mCurrentSettings.mWordSeparators,
mWordComposer.isComposingWord() ? 2 : 1);
final SuggestedWords suggestedWords = mSuggest.getSuggestedWords(mWordComposer,
- prevWord, mKeyboardSwitcher.getKeyboard().getProximityInfo(),
- mCurrentSettings.mCorrectionEnabled, sessionId);
+ prevWord, keyboard.getProximityInfo(), mCurrentSettings.mCorrectionEnabled,
+ sessionId);
return maybeRetrieveOlderSuggestions(typedWord, suggestedWords);
}
diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java
index 8a1bbed12..da0071adc 100644
--- a/java/src/com/android/inputmethod/latin/WordComposer.java
+++ b/java/src/com/android/inputmethod/latin/WordComposer.java
@@ -177,14 +177,16 @@ public final class WordComposer {
* Internal method to retrieve reasonable proximity info for a character.
*/
private void addKeyInfo(final int codePoint, final Keyboard keyboard) {
- final Key key = keyboard.getKey(codePoint);
- if (key != null) {
- final int x = key.mX + key.mWidth / 2;
- final int y = key.mY + key.mHeight / 2;
- add(codePoint, x, y);
- return;
+ final int x, y;
+ final Key key;
+ if (keyboard != null && (key = keyboard.getKey(codePoint)) != null) {
+ x = key.mX + key.mWidth / 2;
+ y = key.mY + key.mHeight / 2;
+ } else {
+ x = Constants.NOT_A_COORDINATE;
+ y = Constants.NOT_A_COORDINATE;
}
- add(codePoint, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE);
+ add(codePoint, x, y);
}
/**
@@ -195,7 +197,7 @@ public final class WordComposer {
reset();
final int length = word.length();
for (int i = 0; i < length; i = Character.offsetByCodePoints(word, i, 1)) {
- int codePoint = Character.codePointAt(word, i);
+ final int codePoint = Character.codePointAt(word, i);
addKeyInfo(codePoint, keyboard);
}
mIsResumed = true;