diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin/LatinIME.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/LatinIME.java | 101 |
1 files changed, 36 insertions, 65 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index ca38cdeec..d96b858eb 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -72,6 +72,7 @@ import com.android.inputmethod.latin.suggestions.SuggestionsView; import java.io.FileDescriptor; import java.io.PrintWriter; +import java.util.List; import java.util.Locale; /** @@ -532,6 +533,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // Also receive installation and removal of a dictionary pack. final IntentFilter filter = new IntentFilter(); filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); + filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION); registerReceiver(mReceiver, filter); mVoiceProxy = VoiceProxy.init(this, prefs, mHandler); @@ -547,19 +549,11 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar registerReceiver(mDictionaryPackInstallReceiver, newDictFilter); } - private void renewFeedbackReceiver() { - if (null != mFeedbackManager) unregisterReceiver(mFeedbackManager); - mFeedbackManager = new AudioAndHapticFeedbackManager(this, mSettingsValues); - final IntentFilter ringerModeFilter = new IntentFilter(); - ringerModeFilter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION); - registerReceiver(mFeedbackManager, ringerModeFilter); - } - // Has to be package-visible for unit tests /* package */ void loadSettings() { if (null == mPrefs) mPrefs = PreferenceManager.getDefaultSharedPreferences(this); mSettingsValues = new SettingsValues(mPrefs, this, mSubtypeSwitcher.getInputLocaleStr()); - renewFeedbackReceiver(); + mFeedbackManager = new AudioAndHapticFeedbackManager(this, mSettingsValues); resetContactsDictionary(null == mSuggest ? null : mSuggest.getContactsDictionary()); } @@ -648,7 +642,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar mSuggest = null; } unregisterReceiver(mReceiver); - unregisterReceiver(mFeedbackManager); unregisterReceiver(mDictionaryPackInstallReceiver); mVoiceProxy.destroy(); LatinImeLogger.commit(); @@ -987,8 +980,11 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar return; } + final List<CharSequence> applicationSuggestedWords = + SuggestedWords.Builder.getFromApplicationSpecifiedCompletions( + applicationSpecifiedCompletions); SuggestedWords.Builder builder = new SuggestedWords.Builder() - .setApplicationSpecifiedCompletions(applicationSpecifiedCompletions) + .addWords(applicationSuggestedWords, null) .setTypedWordValid(false) .setHasMinimalSuggestion(false); // When in fullscreen mode, show completions generated by the application @@ -1292,7 +1288,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } private void handleLanguageSwitchKey() { - final boolean includesOtherImes = !mSettingsValues.mIncludesOtherImesInLanguageSwitchList; + final boolean includesOtherImes = mSettingsValues.mIncludesOtherImesInLanguageSwitchList; final IBinder token = getWindow().getWindow().getAttributes().token; if (mShouldSwitchToLastSubtype) { final InputMethodSubtypeCompatWrapper lastSubtype = mImm.getLastInputMethodSubtype(); @@ -1824,70 +1820,36 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } else { prevWord = EditingUtils.getPreviousWord(ic, mSettingsValues.mWordSeparators); } + + final CharSequence typedWord = mWordComposer.getTypedWord(); // getSuggestedWordBuilder handles gracefully a null value of prevWord final SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder(mWordComposer, prevWord, mKeyboardSwitcher.getKeyboard().getProximityInfo(), mCorrectionMode); - boolean autoCorrectionAvailable = !mInputAttributes.mInputTypeNoAutoCorrect - && mSuggest.hasAutoCorrection(); - final CharSequence typedWord = mWordComposer.getTypedWord(); - // Here, we want to promote a whitelisted word if exists. - // TODO: Change this scheme - a boolean is not enough. A whitelisted word may be "valid" - // but still autocorrected from - in the case the whitelist only capitalizes the word. - // The whitelist should be case-insensitive, so it's not possible to be consistent with - // a boolean flag. Right now this is handled with a slight hack in - // WhitelistDictionary#shouldForciblyAutoCorrectFrom. - final int quotesCount = mWordComposer.trailingSingleQuotesCount(); - final boolean allowsToBeAutoCorrected = AutoCorrection.allowsToBeAutoCorrected( - mSuggest.getUnigramDictionaries(), - // If the typed string ends with a single quote, for dictionary lookup purposes - // we behave as if the single quote was not here. Here, we are looking up the - // typed string in the dictionary (to avoid autocorrecting from an existing - // word, so for consistency this lookup should be made WITHOUT the trailing - // single quote. - quotesCount > 0 - ? typedWord.subSequence(0, typedWord.length() - quotesCount) : typedWord, - preferCapitalization()); - if (mCorrectionMode == Suggest.CORRECTION_FULL - || mCorrectionMode == Suggest.CORRECTION_FULL_BIGRAM) { - autoCorrectionAvailable |= (!allowsToBeAutoCorrected); - } - // Don't auto-correct words with multiple capital letter - autoCorrectionAvailable &= !mWordComposer.isMostlyCaps(); - // Basically, we update the suggestion strip only when suggestion count > 1. However, // there is an exception: We update the suggestion strip whenever typed word's length // is 1 or typed word is found in dictionary, regardless of suggestion count. Actually, // in most cases, suggestion count is 1 when typed word's length is 1, but we do always // need to clear the previous state when the user starts typing a word (i.e. typed word's // length == 1). - if (typedWord != null) { - if (builder.size() > 1 || typedWord.length() == 1 || (!allowsToBeAutoCorrected) - || mSuggestionsView.isShowingAddToDictionaryHint()) { - builder.setTypedWordValid(!allowsToBeAutoCorrected).setHasMinimalSuggestion( - autoCorrectionAvailable); - } else { - SuggestedWords previousSuggestions = mSuggestionsView.getSuggestions(); - if (previousSuggestions == mSettingsValues.mSuggestPuncList) { - if (builder.size() == 0) { - return; - } - previousSuggestions = SuggestedWords.EMPTY; - } - builder.addTypedWordAndPreviousSuggestions(typedWord, previousSuggestions); + if (builder.size() > 1 || typedWord.length() == 1 || !builder.allowsToBeAutoCorrected() + || mSuggestionsView.isShowingAddToDictionaryHint()) { + showSuggestions(builder.build(), typedWord); + } else { + SuggestedWords previousSuggestions = mSuggestionsView.getSuggestions(); + if (previousSuggestions == mSettingsValues.mSuggestPuncList) { + previousSuggestions = SuggestedWords.EMPTY; } + final SuggestedWords.Builder obsoleteSuggestionsBuilder = new SuggestedWords.Builder() + .addTypedWordAndPreviousSuggestions(typedWord, previousSuggestions); + showSuggestions(obsoleteSuggestionsBuilder.build(), typedWord); } - if (Suggest.shouldBlockAutoCorrectionBySafetyNet(builder, mSuggest)) { - builder.setShouldBlockAutoCorrectionBySafetyNet(); - } - showSuggestions(builder.build(), typedWord); } public void showSuggestions(final SuggestedWords suggestedWords, final CharSequence typedWord) { final CharSequence autoCorrection; if (suggestedWords.size() > 0) { - if (!suggestedWords.mShouldBlockAutoCorrectionBySafetyNet - && suggestedWords.hasAutoCorrectionWord()) { + if (suggestedWords.hasAutoCorrectionWord()) { autoCorrection = suggestedWords.getWord(1); } else { autoCorrection = typedWord; @@ -2051,7 +2013,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar separatorCode); } - private static final WordComposer sEmptyWordComposer = new WordComposer(); public void updateBigramPredictions() { if (mSuggest == null || !isSuggestionsRequested()) return; @@ -2061,12 +2022,20 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar return; } - final CharSequence prevWord = EditingUtils.getThisWord(getCurrentInputConnection(), - mSettingsValues.mWordSeparators); - SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder(sEmptyWordComposer, - prevWord, mKeyboardSwitcher.getKeyboard().getProximityInfo(), mCorrectionMode); + final SuggestedWords.Builder builder; + if (mCorrectionMode == Suggest.CORRECTION_FULL_BIGRAM) { + final CharSequence prevWord = EditingUtils.getThisWord(getCurrentInputConnection(), + mSettingsValues.mWordSeparators); + if (!TextUtils.isEmpty(prevWord)) { + builder = mSuggest.getBigramPredictionWordBuilder(prevWord); + } else { + builder = null; + } + } else { + builder = null; + } - if (builder.size() > 0) { + if (null != builder && builder.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(builder.build(), ""); @@ -2356,6 +2325,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar final String action = intent.getAction(); if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) { mSubtypeSwitcher.onNetworkStateChanged(intent); + } else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) { + mFeedbackManager.onRingerModeChanged(); } } }; |