diff options
author | 2014-03-25 15:35:20 +0900 | |
---|---|---|
committer | 2014-03-25 15:35:20 +0900 | |
commit | adfb262797023c4ca57bb470e547f90c88f638ca (patch) | |
tree | 86b052bdeab30de2ee27d5ead6b5e20086f3ace6 /java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java | |
parent | 37b9562fd7b593c90d7ab383ec650f39a7c0f621 (diff) | |
download | latinime-adfb262797023c4ca57bb470e547f90c88f638ca.tar.gz latinime-adfb262797023c4ca57bb470e547f90c88f638ca.tar.xz latinime-adfb262797023c4ca57bb470e547f90c88f638ca.zip |
Remove logic related to dictionary loading from LatinIME.
Make mSuggest final and give DictionaryFacilitator the
responsibility to manage dictionary loading state.
This can simplify the logic to decide how to deal with
additional dictionaries when loading settings or language
switching.
Bug: 13273534
Change-Id: I9f3d328272f25addfa186fbeedaaf8417455ba99
Diffstat (limited to 'java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java | 39 |
1 files changed, 10 insertions, 29 deletions
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java index 36b30eabe..ffa5e8e89 100644 --- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java +++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java @@ -32,6 +32,7 @@ import com.android.inputmethod.event.InputTransaction; import com.android.inputmethod.keyboard.KeyboardSwitcher; import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.Dictionary; +import com.android.inputmethod.latin.DictionaryFacilitatorForSuggest; import com.android.inputmethod.latin.InputPointers; import com.android.inputmethod.latin.LastComposedWord; import com.android.inputmethod.latin.LatinIME; @@ -77,8 +78,7 @@ public final class InputLogic { private int mSpaceState; // Never null public SuggestedWords mSuggestedWords = SuggestedWords.EMPTY; - // TODO: mSuggest should be touched by a single thread. - public volatile Suggest mSuggest; + public final Suggest mSuggest = new Suggest(); public LastComposedWord mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD; public final WordComposer mWordComposer; @@ -106,15 +106,6 @@ public final class InputLogic { mInputLogicHandler = InputLogicHandler.NULL_HANDLER; } - // Replace the old Suggest with the passed Suggest and close it. - public void replaceSuggest(final Suggest newSuggest) { - final Suggest oldSuggest = mSuggest; - mSuggest = newSuggest; - if (oldSuggest != null) { - oldSuggest.close(); - } - } - /** * Initializes the input logic for input in an editor. * @@ -283,23 +274,18 @@ public final class InputLogic { // We should show the "Touch again to save" hint if the user pressed the first entry // AND it's in none of our current dictionaries (main, user or otherwise). - // Please note that if mSuggest is null, it means that everything is off: suggestion - // and correction, so we shouldn't try to show the hint - final Suggest suggest = mSuggest; + final DictionaryFacilitatorForSuggest dictionaryFacilitator = + mSuggest.mDictionaryFacilitator; final boolean showingAddToDictionaryHint = (SuggestedWordInfo.KIND_TYPED == suggestionInfo.mKind || SuggestedWordInfo.KIND_OOV_CORRECTION == suggestionInfo.mKind) - && suggest != null - // If the suggestion is not in the dictionary, the hint should be shown. - && !suggest.mDictionaryFacilitator.isValidWord(suggestion, - true /* ignoreCase */); + && !dictionaryFacilitator.isValidWord(suggestion, true /* ignoreCase */); if (settingsValues.mIsInternal) { LatinImeLoggerUtils.onSeparator((char)Constants.CODE_SPACE, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE); } - if (showingAddToDictionaryHint - && suggest.mDictionaryFacilitator.isUserDictionaryEnabled()) { + if (showingAddToDictionaryHint && dictionaryFacilitator.isUserDictionaryEnabled()) { mSuggestionStripViewAccessor.showAddToDictionaryHint(suggestion); } else { // If we're not showing the "Touch again to save", then update the suggestion strip. @@ -1231,20 +1217,17 @@ public final class InputLogic { if (!settingsValues.mCorrectionEnabled) return; if (TextUtils.isEmpty(suggestion)) return; - final Suggest suggest = mSuggest; - if (suggest == null) return; - final boolean wasAutoCapitalized = mWordComposer.wasAutoCapitalized() && !mWordComposer.isMostlyCaps(); final int timeStampInSeconds = (int)TimeUnit.MILLISECONDS.toSeconds( System.currentTimeMillis()); - suggest.mDictionaryFacilitator.addToUserHistory(suggestion, wasAutoCapitalized, prevWord, + mSuggest.mDictionaryFacilitator.addToUserHistory(suggestion, wasAutoCapitalized, prevWord, timeStampInSeconds); } public void performUpdateSuggestionStripSync(final SettingsValues settingsValues) { // Check if we have a suggestion engine attached. - if (mSuggest == null || !settingsValues.isSuggestionsRequested()) { + if (!settingsValues.isSuggestionsRequested()) { if (mWordComposer.isComposingWord()) { Log.w(TAG, "Called updateSuggestionsOrPredictions but suggestions were not " + "requested!"); @@ -1446,10 +1429,8 @@ public final class InputLogic { } mConnection.deleteSurroundingText(deleteLength, 0); if (!TextUtils.isEmpty(previousWord) && !TextUtils.isEmpty(committedWord)) { - if (mSuggest != null) { - mSuggest.mDictionaryFacilitator.cancelAddingUserHistory( - previousWord, committedWordString); - } + mSuggest.mDictionaryFacilitator.cancelAddingUserHistory( + previousWord, committedWordString); } final String stringToCommit = originallyTypedWord + mLastComposedWord.mSeparatorString; final SpannableString textToCommit = new SpannableString(stringToCommit); |