diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin/LatinIME.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/LatinIME.java | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 0e1c4dc31..16eab4bc4 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -439,6 +439,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction mHandler.onCreate(); DEBUG = LatinImeLogger.sDBG; + // TODO: Resolve mutual dependencies of {@link #loadSettings()} and {@link #initSuggest()}. loadSettings(); initSuggest(); @@ -476,6 +477,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction final InputAttributes inputAttributes = new InputAttributes(getCurrentInputEditorInfo(), isFullscreenMode()); mSettings.loadSettings(locale, inputAttributes); + // May need to reset the contacts dictionary depending on the user settings. resetContactsDictionary(null == mSuggest ? null : mSuggest.getContactsDictionary()); } @@ -745,6 +747,11 @@ public final class LatinIME extends InputMethodService implements KeyboardAction mRecapitalizeStatus.deactivate(); mCurrentlyPressedHardwareKeys.clear(); + // Note: the following does a round-trip IPC on the main thread: be careful + final Locale currentLocale = mSubtypeSwitcher.getCurrentSubtypeLocale(); + if (null != mSuggest && null != currentLocale && !currentLocale.equals(mSuggest.mLocale)) { + initSuggest(); + } if (mSuggestionStripView != null) { // This will set the punctuation suggestions if next word suggestion is off; // otherwise it will clear the suggestion strip. @@ -797,8 +804,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction // to the user dictionary. if (null != mPositionalInfoForUserDictPendingAddition && mPositionalInfoForUserDictPendingAddition.tryReplaceWithActualWord( - mConnection, editorInfo, mLastSelectionEnd, - mSubtypeSwitcher.getCurrentSubtypeLocale())) { + mConnection, editorInfo, mLastSelectionEnd, currentLocale)) { mPositionalInfoForUserDictPendingAddition = null; } // If tryReplaceWithActualWord returns false, we don't know what word was @@ -1678,7 +1684,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction private SuggestedWords getSuggestedWordsGestureLocked(final InputPointers batchPointers) { mLatinIme.mWordComposer.setBatchInputPointers(batchPointers); final SuggestedWords suggestedWords = - mLatinIme.getSuggestedWords(Suggest.SESSION_GESTURE); + mLatinIme.getSuggestedWordsOrOlderSuggestions(Suggest.SESSION_GESTURE); final int suggestionCount = suggestedWords.size(); if (suggestionCount <= 1) { final String mostProbableSuggestion = (suggestionCount == 0) ? null @@ -1970,9 +1976,12 @@ public final class LatinIME extends InputMethodService implements KeyboardAction // If we have a recapitalize in progress, use it; otherwise, create a new one. if (!mRecapitalizeStatus.isActive() || !mRecapitalizeStatus.isSetAt(mLastSelectionStart, mLastSelectionEnd)) { + final CharSequence selectedText = + mConnection.getSelectedText(0 /* flags, 0 for no styles */); + if (TextUtils.isEmpty(selectedText)) return; // Race condition with the input connection mRecapitalizeStatus.initialize(mLastSelectionStart, mLastSelectionEnd, - mConnection.getSelectedText(0 /* flags, 0 for no styles */).toString(), - mSettings.getCurrentLocale(), mSettings.getWordSeparators()); + selectedText.toString(), mSettings.getCurrentLocale(), + mSettings.getWordSeparators()); // We trim leading and trailing whitespace. mRecapitalizeStatus.trim(); // Trimming the object may have changed the length of the string, and we need to @@ -2152,7 +2161,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction return; } - final SuggestedWords suggestedWords = getSuggestedWords(Suggest.SESSION_TYPING); + final SuggestedWords suggestedWords = + getSuggestedWordsOrOlderSuggestions(Suggest.SESSION_TYPING); final String typedWord = mWordComposer.getTypedWord(); showSuggestionStrip(suggestedWords, typedWord); } @@ -2162,7 +2172,6 @@ public final class LatinIME extends InputMethodService implements KeyboardAction if (keyboard == null || mSuggest == 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 // should just skip whitespace if any, so 1. @@ -2170,10 +2179,13 @@ public final class LatinIME extends InputMethodService implements KeyboardAction final String prevWord = mConnection.getNthPreviousWord(mSettings.getCurrent().mWordSeparators, mWordComposer.isComposingWord() ? 2 : 1); - final SuggestedWords suggestedWords = mSuggest.getSuggestedWords(mWordComposer, - prevWord, keyboard.getProximityInfo(), mSettings.getCurrent().mCorrectionEnabled, - sessionId); - return maybeRetrieveOlderSuggestions(typedWord, suggestedWords); + return mSuggest.getSuggestedWords(mWordComposer, prevWord, keyboard.getProximityInfo(), + mSettings.getCurrent().mCorrectionEnabled, sessionId); + } + + private SuggestedWords getSuggestedWordsOrOlderSuggestions(final int sessionId) { + return maybeRetrieveOlderSuggestions(mWordComposer.getTypedWord(), + getSuggestedWords(sessionId)); } private SuggestedWords maybeRetrieveOlderSuggestions(final String typedWord, @@ -2186,7 +2198,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction // old suggestions. Also, if we are showing the "add to dictionary" hint, we need to // revert to suggestions - although it is unclear how we can come here if it's displayed. if (suggestedWords.size() > 1 || typedWord.length() <= 1 - || suggestedWords.mTypedWordValid + || suggestedWords.mTypedWordValid || null == mSuggestionStripView || mSuggestionStripView.isShowingAddToDictionaryHint()) { return suggestedWords; } else { @@ -2577,8 +2589,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction // Outside LatinIME, only used by the {@link InputTestsBase} test suite. @UsedForTesting void loadKeyboard() { - // When the device locale is changed in SetupWizard etc., this method may get called via - // onConfigurationChanged before SoftInputWindow is shown. + // TODO: Why are we calling {@link #loadSettings()} and {@link #initSuggest()} in a + // different order than in {@link #onStartInputView}? initSuggest(); loadSettings(); if (mKeyboardSwitcher.getMainKeyboardView() != null) { |