diff options
author | 2012-07-05 01:45:08 -0700 | |
---|---|---|
committer | 2012-07-05 01:45:08 -0700 | |
commit | ac3ad6ef9f78eae844b47bd12e313966e522096c (patch) | |
tree | d87c0a4b883fe7cad0e03d053321fc77d2df68a6 /java/src/com/android/inputmethod/latin/LatinIME.java | |
parent | 15d35321702a3ef308d7804f5cd16494feeb3ae7 (diff) | |
parent | 7ed22f1f72dfa14b13ad6775617fd9e89f0ca224 (diff) | |
download | latinime-ac3ad6ef9f78eae844b47bd12e313966e522096c.tar.gz latinime-ac3ad6ef9f78eae844b47bd12e313966e522096c.tar.xz latinime-ac3ad6ef9f78eae844b47bd12e313966e522096c.zip |
Merge "Factorize some common code (A49)"
Diffstat (limited to 'java/src/com/android/inputmethod/latin/LatinIME.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/LatinIME.java | 46 |
1 files changed, 16 insertions, 30 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index a2b33e1a7..fba8d4a34 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1003,7 +1003,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // the composing word, reset the last composed word, tell the inputconnection about it. private void resetEntireInputState() { resetComposingState(true /* alsoResetLastComposedWord */); - updateSuggestionsOrPredictions(false /* isPredictions */); + clearSuggestions(); mConnection.finishComposingText(); } @@ -1691,35 +1691,27 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } public void updateSuggestionsOrPredictions(final boolean isPredictions) { - if (isPredictions) { - updateBigramPredictions(); - } else { - updateSuggestions(); - } - } - - private void updateSuggestions() { mHandler.cancelUpdateSuggestions(); mHandler.cancelUpdateBigramPredictions(); // Check if we have a suggestion engine attached. - if ((mSuggest == null || !mCurrentSettings.isSuggestionsRequested(mDisplayOrientation))) { + if (mSuggest == null || !mCurrentSettings.isSuggestionsRequested(mDisplayOrientation)) { if (mWordComposer.isComposingWord()) { - Log.w(TAG, "Called updateSuggestions but suggestions were not requested!"); + Log.w(TAG, "Called updateSuggestionsOrPredictions but suggestions were not " + + "requested!"); mWordComposer.setAutoCorrection(mWordComposer.getTypedWord()); } return; } - if (!mWordComposer.isComposingWord()) { - // We are never called with an empty word composer, but if because of a bug - // we are, what we should do here is just call updateBigramsPredictions. This will - // update the predictions if the "predict next word" option is on, or display - // punctuation signs if it's off. + if (isPredictions || !mWordComposer.isComposingWord()) { updateBigramPredictions(); - return; + } else { + updateSuggestions(); } + } + private void updateSuggestions() { // TODO: May need a better way of retrieving previous word final CharSequence prevWord = mConnection.getPreviousWord(mCurrentSettings.mWordSeparators); final CharSequence typedWord = mWordComposer.getTypedWord(); @@ -1737,6 +1729,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen if (suggestedWords.size() > 1 || typedWord.length() == 1 || !suggestedWords.mTypedWordValid || mSuggestionsView.isShowingAddToDictionaryHint()) { + // We know suggestedWords.size() > 1 showSuggestions(suggestedWords, typedWord); } else { SuggestedWords previousSuggestions = mSuggestionsView.getSuggestions(); @@ -1753,11 +1746,15 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen false /* isPunctuationSuggestions */, true /* isObsoleteSuggestions */, false /* isPrediction */); + // getTypedWordAndPreviousSuggestions never returns an empty array, so we know we have + // at least one element here. showSuggestions(obsoleteSuggestedWords, typedWord); } } - public void showSuggestions(final SuggestedWords suggestedWords, final CharSequence typedWord) { + private void showSuggestions(final SuggestedWords suggestedWords, + final CharSequence typedWord) { + // This method is only ever called by updateSuggestions or updateBigramPredictions. final CharSequence autoCorrection; if (suggestedWords.size() > 0) { if (suggestedWords.mWillAutoCorrect) { @@ -1924,18 +1921,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen separatorCode, prevWord); } - public void updateBigramPredictions() { - mHandler.cancelUpdateSuggestions(); - mHandler.cancelUpdateBigramPredictions(); - - if (mSuggest == null || !mCurrentSettings.isSuggestionsRequested(mDisplayOrientation)) { - if (mWordComposer.isComposingWord()) { - Log.w(TAG, "Called updateBigramPredictions but suggestions were not requested!"); - mWordComposer.setAutoCorrection(mWordComposer.getTypedWord()); - } - return; - } - + private void updateBigramPredictions() { if (!mCurrentSettings.mBigramPredictionEnabled) { setPunctuationSuggestions(); return; |