diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin/LatinIME.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/LatinIME.java | 73 |
1 files changed, 36 insertions, 37 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 953d87beb..64b9f3364 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -979,7 +979,10 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar .setTypedWordValid(false) .setHasMinimalSuggestion(false); // When in fullscreen mode, show completions generated by the application - setSuggestions(builder.build()); + final SuggestedWords words = builder.build(); + final boolean isAutoCorrection = false; + setSuggestions(words, isAutoCorrection); + setAutoCorrectionIndicator(isAutoCorrection); // TODO: is this the right thing to do? What should we auto-correct to in // this case? This says to keep whatever the user typed. mWordComposer.setAutoCorrection(mWordComposer.getTypedWord()); @@ -1111,12 +1114,12 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // and the composingStateManager about it. private void resetEntireInputState() { resetComposingState(true /* alsoResetLastComposedWord */); + mComposingStateManager.onFinishComposingText(); updateSuggestions(); final InputConnection ic = getCurrentInputConnection(); if (ic != null) { ic.finishComposingText(); } - mComposingStateManager.onFinishComposingText(); mVoiceProxy.setVoiceInputHighlighted(false); } @@ -1533,8 +1536,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // it entirely and resume suggestions on the previous word, we'd like to still // have touch coordinates for it. resetComposingState(false /* alsoResetLastComposedWord */); - clearSuggestions(); mComposingStateManager.onFinishComposingText(); + clearSuggestions(); } } if (isComposingWord) { @@ -1712,35 +1715,32 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } public void clearSuggestions() { - setSuggestions(SuggestedWords.EMPTY); + setSuggestions(SuggestedWords.EMPTY, false); + setAutoCorrectionIndicator(false); } - public void setSuggestions(SuggestedWords words) { + public void setSuggestions(final SuggestedWords words, final boolean isAutoCorrection) { if (mSuggestionsView != null) { mSuggestionsView.setSuggestions(words); - mKeyboardSwitcher.onAutoCorrectionStateChanged( - words.hasWordAboveAutoCorrectionScoreThreshold()); + mKeyboardSwitcher.onAutoCorrectionStateChanged(isAutoCorrection); } + } + private void setAutoCorrectionIndicator(final boolean newAutoCorrectionIndicator) { // Put a blue underline to a word in TextView which will be auto-corrected. final InputConnection ic = getCurrentInputConnection(); if (ic != null) { final boolean oldAutoCorrectionIndicator = mComposingStateManager.isAutoCorrectionIndicatorOn(); - final boolean newAutoCorrectionIndicator = Utils.willAutoCorrect(words); if (oldAutoCorrectionIndicator != newAutoCorrectionIndicator) { mComposingStateManager.setAutoCorrectionIndicatorOn(newAutoCorrectionIndicator); if (DEBUG) { Log.d(TAG, "Flip the indicator. " + oldAutoCorrectionIndicator + " -> " + newAutoCorrectionIndicator); - if (mComposingStateManager.isComposing() && newAutoCorrectionIndicator - != mComposingStateManager.isAutoCorrectionIndicatorOn()) { - throw new RuntimeException("Couldn't flip the indicator!"); - } } - final CharSequence textWithUnderline = - getTextWithUnderline(mWordComposer.getTypedWord()); - if (!TextUtils.isEmpty(textWithUnderline)) { + if (mWordComposer.isComposingWord()) { + final CharSequence textWithUnderline = + getTextWithUnderline(mWordComposer.getTypedWord()); ic.setComposingText(textWithUnderline, 1); } } @@ -1827,28 +1827,28 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar builder.addTypedWordAndPreviousSuggestions(typedWord, previousSuggestions); } } + if (Utils.shouldBlockAutoCorrectionBySafetyNet(builder, mSuggest)) { + builder.setShouldBlockAutoCorrectionBySafetyNet(); + } showSuggestions(builder.build(), typedWord); } - public void showSuggestions(SuggestedWords suggestedWords, CharSequence typedWord) { - final boolean shouldBlockAutoCorrectionBySafetyNet = - Utils.shouldBlockAutoCorrectionBySafetyNet(suggestedWords, mSuggest); - if (shouldBlockAutoCorrectionBySafetyNet) { - suggestedWords.setShouldBlockAutoCorrection(); - } - setSuggestions(suggestedWords); + public void showSuggestions(final SuggestedWords suggestedWords, final CharSequence typedWord) { + final CharSequence autoCorrection; if (suggestedWords.size() > 0) { - if (shouldBlockAutoCorrectionBySafetyNet) { - mWordComposer.setAutoCorrection(typedWord); - } else if (suggestedWords.hasAutoCorrectionWord()) { - mWordComposer.setAutoCorrection(suggestedWords.getWord(1)); + if (!suggestedWords.mShouldBlockAutoCorrectionBySafetyNet + && suggestedWords.hasAutoCorrectionWord()) { + autoCorrection = suggestedWords.getWord(1); } else { - mWordComposer.setAutoCorrection(typedWord); + autoCorrection = typedWord; } } else { - // TODO: replace with mWordComposer.deleteAutoCorrection()? - mWordComposer.setAutoCorrection(null); + autoCorrection = null; } + mWordComposer.setAutoCorrection(autoCorrection); + final boolean isAutoCorrection = suggestedWords.willAutoCorrect(); + setSuggestions(suggestedWords, isAutoCorrection); + setAutoCorrectionIndicator(isAutoCorrection); setSuggestionStripShown(isSuggestionsStripVisible()); } @@ -1885,7 +1885,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar @Override public void pickSuggestionManually(final int index, final CharSequence suggestion) { mComposingStateManager.onFinishComposingText(); - final SuggestedWords suggestions = mSuggestionsView.getSuggestions(); + final SuggestedWords suggestedWords = mSuggestionsView.getSuggestions(); mVoiceProxy.flushAndLogAllTextModificationCounters(index, suggestion, mSettingsValues.mWordSeparators); @@ -1896,12 +1896,11 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar mSuggestionsView.clear(); } mKeyboardSwitcher.updateShiftState(); + resetComposingState(true /* alsoResetLastComposedWord */); final InputConnection ic = getCurrentInputConnection(); if (ic != null) { - ic.beginBatchEdit(); final CompletionInfo completionInfo = mApplicationSpecifiedCompletions[index]; ic.commitCompletion(completionInfo); - ic.endBatchEdit(); } return; } @@ -1910,8 +1909,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (suggestion.length() == 1 && isShowingPunctuationList()) { // Word separators are suggested before the user inputs something. // So, LatinImeLogger logs "" as a user's input. - LatinImeLogger.logOnManualSuggestion( - "", suggestion.toString(), index, suggestions.mWords); + LatinImeLogger.logOnManualSuggestion("", suggestion.toString(), index, suggestedWords); // Rely on onCodeInput to do the complicated swapping/stripping logic consistently. final int primaryCode = suggestion.charAt(0); onCodeInput(primaryCode, new int[] { primaryCode }, @@ -1922,7 +1920,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // We need to log before we commit, because the word composer will store away the user // typed word. LatinImeLogger.logOnManualSuggestion(mWordComposer.getTypedWord().toString(), - suggestion.toString(), index, suggestions.mWords); + suggestion.toString(), index, suggestedWords); mExpectingUpdateSelection = true; commitChosenWord(suggestion, LastComposedWord.COMMIT_TYPE_MANUAL_PICK, LastComposedWord.NOT_A_SEPARATOR); @@ -2021,7 +2019,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } public void setPunctuationSuggestions() { - setSuggestions(mSettingsValues.mSuggestPuncList); + setSuggestions(mSettingsValues.mSuggestPuncList, false); + setAutoCorrectionIndicator(false); setSuggestionStripShown(isSuggestionsStripVisible()); } @@ -2414,7 +2413,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar switch (position) { case 0: Intent intent = CompatUtils.getInputLanguageSelectionIntent( - Utils.getInputMethodId(mImm, getPackageName()), + Utils.getInputMethodId(getPackageName()), Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_CLEAR_TOP); |