diff options
Diffstat (limited to 'java/src')
-rw-r--r-- | java/src/com/android/inputmethod/latin/LatinIME.java | 96 |
1 files changed, 34 insertions, 62 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index a2b33e1a7..594529500 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,38 +1691,43 @@ 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. - updateBigramPredictions(); - return; + final CharSequence typedWord; + final SuggestedWords suggestions; + if (isPredictions || !mWordComposer.isComposingWord()) { + if (!mCurrentSettings.mBigramPredictionEnabled) { + setPunctuationSuggestions(); + return; + } + typedWord = ""; + suggestions = updateBigramPredictions(typedWord); + } else { + typedWord = mWordComposer.getTypedWord(); + suggestions = updateSuggestions(typedWord); } + if (null != suggestions && suggestions.size() > 0) { + showSuggestions(suggestions, typedWord); + } else { + clearSuggestions(); + } + } + + private SuggestedWords updateSuggestions(final CharSequence typedWord) { // TODO: May need a better way of retrieving previous word final CharSequence prevWord = mConnection.getPreviousWord(mCurrentSettings.mWordSeparators); - final CharSequence typedWord = mWordComposer.getTypedWord(); // getSuggestedWords handles gracefully a null value of prevWord final SuggestedWords suggestedWords = mSuggest.getSuggestedWords(mWordComposer, prevWord, mKeyboardSwitcher.getKeyboard().getProximityInfo(), @@ -1737,7 +1742,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen if (suggestedWords.size() > 1 || typedWord.length() == 1 || !suggestedWords.mTypedWordValid || mSuggestionsView.isShowingAddToDictionaryHint()) { - showSuggestions(suggestedWords, typedWord); + return suggestedWords; } else { SuggestedWords previousSuggestions = mSuggestionsView.getSuggestions(); if (previousSuggestions == mCurrentSettings.mSuggestPuncList) { @@ -1746,18 +1751,18 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen final ArrayList<SuggestedWords.SuggestedWordInfo> typedWordAndPreviousSuggestions = SuggestedWords.getTypedWordAndPreviousSuggestions( typedWord, previousSuggestions); - final SuggestedWords obsoleteSuggestedWords = - new SuggestedWords(typedWordAndPreviousSuggestions, + return new SuggestedWords(typedWordAndPreviousSuggestions, false /* typedWordValid */, false /* hasAutoCorrectionCandidate */, false /* isPunctuationSuggestions */, true /* isObsoleteSuggestions */, false /* isPrediction */); - 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,44 +1929,11 @@ 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; - } - - if (!mCurrentSettings.mBigramPredictionEnabled) { - setPunctuationSuggestions(); - return; - } - - final SuggestedWords suggestedWords; - if (mCurrentSettings.mCorrectionEnabled) { - final CharSequence prevWord = mConnection.getThisWord(mCurrentSettings.mWordSeparators); - if (!TextUtils.isEmpty(prevWord)) { - suggestedWords = mSuggest.getSuggestedWords(mWordComposer, - prevWord, mKeyboardSwitcher.getKeyboard().getProximityInfo(), - mCurrentSettings.mCorrectionEnabled, true); - } else { - suggestedWords = null; - } - } else { - suggestedWords = null; - } - - if (null != suggestedWords && suggestedWords.size() > 0) { - // Explicitly supply an empty typed word (the no-second-arg version of - // showSuggestions will retrieve the word near the cursor, we don't want that here) - showSuggestions(suggestedWords, ""); - } else { - clearSuggestions(); - } + private SuggestedWords updateBigramPredictions(final CharSequence typedWord) { + final CharSequence prevWord = mConnection.getThisWord(mCurrentSettings.mWordSeparators); + return mSuggest.getSuggestedWords(mWordComposer, + prevWord, mKeyboardSwitcher.getKeyboard().getProximityInfo(), + mCurrentSettings.mCorrectionEnabled, true); } public void setPunctuationSuggestions() { |