diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin/LatinIME.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/LatinIME.java | 263 |
1 files changed, 123 insertions, 140 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index dcc131fc5..28994dc8e 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -35,6 +35,7 @@ import android.graphics.Rect; import android.inputmethodservice.InputMethodService; import android.media.AudioManager; import android.net.ConnectivityManager; +import android.os.Build.VERSION_CODES; import android.os.Debug; import android.os.Handler; import android.os.HandlerThread; @@ -72,7 +73,6 @@ import com.android.inputmethod.keyboard.KeyboardId; import com.android.inputmethod.keyboard.KeyboardSwitcher; import com.android.inputmethod.keyboard.KeyboardView; import com.android.inputmethod.keyboard.MainKeyboardView; -import com.android.inputmethod.latin.LocaleUtils.RunInLocale; import com.android.inputmethod.latin.Utils.Stats; import com.android.inputmethod.latin.define.ProductionFlag; import com.android.inputmethod.latin.suggestions.SuggestionStripView; @@ -127,7 +127,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction // Current space state of the input method. This can be any of the above constants. private int mSpaceState; - private SettingsValues mCurrentSettings; + private final Settings mSettings; private View mExtractArea; private View mKeyPreviewBackingView; @@ -138,14 +138,12 @@ public final class LatinIME extends InputMethodService implements KeyboardAction private ApplicationInfo mTargetApplicationInfo; private RichInputMethodManager mRichImm; - private Resources mResources; - private SharedPreferences mPrefs; @UsedForTesting final KeyboardSwitcher mKeyboardSwitcher; private final SubtypeSwitcher mSubtypeSwitcher; private final SubtypeState mSubtypeState = new SubtypeState(); // At start, create a default event interpreter that does nothing by passing it no decoder spec. // The event interpreter should never be null. - private EventInterpreter mEventInterpreter = new EventInterpreter(); + private EventInterpreter mEventInterpreter = new EventInterpreter(this); private boolean mIsMainDictionaryAvailable; private UserBinaryDictionary mUserDictionary; @@ -400,6 +398,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction public LatinIME() { super(); + mSettings = Settings.getInstance(); mSubtypeSwitcher = SubtypeSwitcher.getInstance(); mKeyboardSwitcher = KeyboardSwitcher.getInstance(); mIsHardwareAcceleratedDrawingEnabled = @@ -409,17 +408,16 @@ public final class LatinIME extends InputMethodService implements KeyboardAction @Override public void onCreate() { - mPrefs = PreferenceManager.getDefaultSharedPreferences(this); - mResources = getResources(); - - LatinImeLogger.init(this, mPrefs); + Settings.init(this); + LatinImeLogger.init(this); if (ProductionFlag.IS_EXPERIMENTAL) { - ResearchLogger.getInstance().init(this, mPrefs); + ResearchLogger.getInstance().init(this); } - RichInputMethodManager.init(this, mPrefs); + RichInputMethodManager.init(this); mRichImm = RichInputMethodManager.getInstance(); SubtypeSwitcher.init(this); - KeyboardSwitcher.init(this, mPrefs); + KeyboardSwitcher.init(this); + AudioAndHapticFeedbackManager.init(this); AccessibilityUtils.init(this); super.onCreate(); @@ -430,7 +428,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction loadSettings(); initSuggest(); - mDisplayOrientation = mResources.getConfiguration().orientation; + mDisplayOrientation = getResources().getConfiguration().orientation; // Register to receive ringer mode change and network state change. // Also receive installation and removal of a dictionary pack. @@ -457,18 +455,10 @@ public final class LatinIME extends InputMethodService implements KeyboardAction // Has to be package-visible for unit tests @UsedForTesting void loadSettings() { - // Note that the calling sequence of onCreate() and onCurrentInputMethodSubtypeChanged() - // is not guaranteed. It may even be called at the same time on a different thread. - if (null == mPrefs) mPrefs = PreferenceManager.getDefaultSharedPreferences(this); + final Locale locale = mSubtypeSwitcher.getCurrentSubtypeLocale(); final InputAttributes inputAttributes = new InputAttributes(getCurrentInputEditorInfo(), isFullscreenMode()); - final RunInLocale<SettingsValues> job = new RunInLocale<SettingsValues>() { - @Override - protected SettingsValues job(Resources res) { - return new SettingsValues(mPrefs, inputAttributes, LatinIME.this); - } - }; - mCurrentSettings = job.runInLocale(mResources, mSubtypeSwitcher.getCurrentSubtypeLocale()); + mSettings.loadSettings(locale, inputAttributes); resetContactsDictionary(null == mSuggest ? null : mSuggest.getContactsDictionary()); } @@ -495,8 +485,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction } mSuggest = new Suggest(this /* Context */, subtypeLocale, this /* SuggestInitializationListener */); - if (mCurrentSettings.mCorrectionEnabled) { - mSuggest.setAutoCorrectionThreshold(mCurrentSettings.mAutoCorrectionThreshold); + if (mSettings.getCurrent().mCorrectionEnabled) { + mSuggest.setAutoCorrectionThreshold(mSettings.getCurrent().mAutoCorrectionThreshold); } mIsMainDictionaryAvailable = DictionaryFactory.isDictionaryAvailable(this, subtypeLocale); @@ -510,10 +500,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction resetContactsDictionary(oldContactsDictionary); - // Note that the calling sequence of onCreate() and onCurrentInputMethodSubtypeChanged() - // is not guaranteed. It may even be called at the same time on a different thread. - if (null == mPrefs) mPrefs = PreferenceManager.getDefaultSharedPreferences(this); - mUserHistoryDictionary = UserHistoryDictionary.getInstance(this, localeStr, mPrefs); + final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + mUserHistoryDictionary = UserHistoryDictionary.getInstance(this, localeStr, prefs); mSuggest.setUserHistoryDictionary(mUserHistoryDictionary); } @@ -526,7 +514,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction * @param oldContactsDictionary an optional dictionary to use, or null */ private void resetContactsDictionary(final ContactsBinaryDictionary oldContactsDictionary) { - final boolean shouldSetDictionary = (null != mSuggest && mCurrentSettings.mUseContactsDict); + final boolean shouldSetDictionary = + (null != mSuggest && mSettings.getCurrent().mUseContactsDict); final ContactsBinaryDictionary dictionaryToUse; if (!shouldSetDictionary) { @@ -570,6 +559,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction mSuggest.close(); mSuggest = null; } + mSettings.onDestroy(); unregisterReceiver(mReceiver); // TODO: The experimental version is not supported by the Dictionary Pack Service yet. if (!ProductionFlag.IS_EXPERIMENTAL) { @@ -582,10 +572,6 @@ public final class LatinIME extends InputMethodService implements KeyboardAction @Override public void onConfigurationChanged(final Configuration conf) { - // System locale has been changed. Needs to reload keyboard. - if (mSubtypeSwitcher.onConfigurationChanged(conf)) { - loadKeyboard(); - } // If orientation changed while predicting, commit the change if (mDisplayOrientation != conf.orientation) { mDisplayOrientation = conf.orientation; @@ -651,7 +637,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction public void onCurrentInputMethodSubtypeChanged(final InputMethodSubtype subtype) { // Note that the calling sequence of onCreate() and onCurrentInputMethodSubtypeChanged() // is not guaranteed. It may even be called at the same time on a different thread. - mSubtypeSwitcher.updateSubtype(subtype); + mSubtypeSwitcher.onSubtypeChanged(subtype); loadKeyboard(); } @@ -684,7 +670,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction + ((editorInfo.inputType & InputType.TYPE_TEXT_FLAG_CAP_WORDS) != 0)); } if (ProductionFlag.IS_EXPERIMENTAL) { - ResearchLogger.latinIME_onStartInputViewInternal(editorInfo, mPrefs); + final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + ResearchLogger.latinIME_onStartInputViewInternal(editorInfo, prefs); } if (InputAttributes.inPrivateImeOptions(null, NO_MICROPHONE_COMPAT, editorInfo)) { Log.w(TAG, "Deprecated private IME option specified: " @@ -716,18 +703,10 @@ public final class LatinIME extends InputMethodService implements KeyboardAction accessUtils.onStartInputViewInternal(mainKeyboardView, editorInfo, restarting); } - final boolean inputTypeChanged = !mCurrentSettings.isSameInputType(editorInfo); + final boolean inputTypeChanged = !mSettings.getCurrent().isSameInputType(editorInfo); final boolean isDifferentTextField = !restarting || inputTypeChanged; if (isDifferentTextField) { - final boolean currentSubtypeEnabled = mSubtypeSwitcher - .updateParametersOnStartInputViewAndReturnIfCurrentSubtypeEnabled(); - if (!currentSubtypeEnabled) { - // Current subtype is disabled. Needs to update subtype and keyboard. - final InputMethodSubtype newSubtype = mRichImm.getCurrentInputMethodSubtype( - mSubtypeSwitcher.getNoLanguageSubtype()); - mSubtypeSwitcher.updateSubtype(newSubtype); - loadKeyboard(); - } + mSubtypeSwitcher.updateParametersOnStartInputView(); } // The EditorInfo might have a flag that affects fullscreen mode. @@ -754,11 +733,12 @@ public final class LatinIME extends InputMethodService implements KeyboardAction mainKeyboardView.closing(); loadSettings(); - if (mSuggest != null && mCurrentSettings.mCorrectionEnabled) { - mSuggest.setAutoCorrectionThreshold(mCurrentSettings.mAutoCorrectionThreshold); + if (mSuggest != null && mSettings.getCurrent().mCorrectionEnabled) { + mSuggest.setAutoCorrectionThreshold( + mSettings.getCurrent().mAutoCorrectionThreshold); } - switcher.loadKeyboard(editorInfo, mCurrentSettings); + switcher.loadKeyboard(editorInfo, mSettings.getCurrent()); } else if (restarting) { // TODO: Come up with a more comprehensive way to reset the keyboard layout when // a keyboard layout set doesn't get reloaded in this method. @@ -779,11 +759,12 @@ public final class LatinIME extends InputMethodService implements KeyboardAction mHandler.cancelDoubleSpacePeriodTimer(); mainKeyboardView.setMainDictionaryAvailability(mIsMainDictionaryAvailable); - mainKeyboardView.setKeyPreviewPopupEnabled(mCurrentSettings.mKeyPreviewPopupOn, - mCurrentSettings.mKeyPreviewPopupDismissDelay); - mainKeyboardView.setGestureHandlingEnabledByUser(mCurrentSettings.mGestureInputEnabled); - mainKeyboardView.setGesturePreviewMode(mCurrentSettings.mGesturePreviewTrailEnabled, - mCurrentSettings.mGestureFloatingPreviewTextEnabled); + mainKeyboardView.setKeyPreviewPopupEnabled(mSettings.getCurrent().mKeyPreviewPopupOn, + mSettings.getCurrent().mKeyPreviewPopupDismissDelay); + mainKeyboardView.setGestureHandlingEnabledByUser( + mSettings.getCurrent().mGestureInputEnabled); + mainKeyboardView.setGesturePreviewMode(mSettings.getCurrent().mGesturePreviewTrailEnabled, + mSettings.getCurrent().mGestureFloatingPreviewTextEnabled); // If we have a user dictionary addition in progress, we should check now if we should // replace the previously committed string with the word that has actually been added @@ -941,7 +922,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction */ @Override public void onExtractedTextClicked() { - if (mCurrentSettings.isSuggestionsRequested(mDisplayOrientation)) return; + if (mSettings.getCurrent().isSuggestionsRequested(mDisplayOrientation)) return; super.onExtractedTextClicked(); } @@ -957,7 +938,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction */ @Override public void onExtractedCursorMovement(final int dx, final int dy) { - if (mCurrentSettings.isSuggestionsRequested(mDisplayOrientation)) return; + if (mSettings.getCurrent().isSuggestionsRequested(mDisplayOrientation)) return; super.onExtractedCursorMovement(dx, dy); } @@ -985,7 +966,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction } } } - if (!mCurrentSettings.isApplicationSpecifiedCompletionsOn()) return; + if (!mSettings.getCurrent().isApplicationSpecifiedCompletionsOn()) return; mApplicationSpecifiedCompletions = applicationSpecifiedCompletions; if (applicationSpecifiedCompletions == null) { clearSuggestionStrip(); @@ -1009,9 +990,6 @@ public final class LatinIME extends InputMethodService implements KeyboardAction final boolean isAutoCorrection = false; setSuggestionStrip(suggestedWords, 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()); setSuggestionStripShown(true); if (ProductionFlag.IS_EXPERIMENTAL) { ResearchLogger.latinIME_onDisplayCompletions(applicationSpecifiedCompletions); @@ -1053,7 +1031,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction } final int keyboardHeight = mainKeyboardView.getHeight(); final int suggestionsHeight = mSuggestionsContainer.getHeight(); - final int displayHeight = mResources.getDisplayMetrics().heightPixels; + final int displayHeight = getResources().getDisplayMetrics().heightPixels; final Rect rect = new Rect(); mKeyPreviewBackingView.getWindowVisibleDisplayFrame(rect); final int notificationBarHeight = rect.top; @@ -1132,10 +1110,10 @@ public final class LatinIME extends InputMethodService implements KeyboardAction // the composing word, reset the last composed word, tell the inputconnection about it. private void resetEntireInputState(final int newCursorPosition) { resetComposingState(true /* alsoResetLastComposedWord */); - if (mCurrentSettings.mBigramPredictionEnabled) { + if (mSettings.getCurrent().mBigramPredictionEnabled) { clearSuggestionStrip(); } else { - setSuggestionStrip(mCurrentSettings.mSuggestPuncList, false); + setSuggestionStrip(mSettings.getCurrent().mSuggestPuncList, false); } mConnection.resetCachesUponCursorMove(newCursorPosition); } @@ -1152,13 +1130,16 @@ public final class LatinIME extends InputMethodService implements KeyboardAction if (typedWord.length() > 0) { commitChosenWord(typedWord, LastComposedWord.COMMIT_TYPE_USER_TYPED_WORD, separatorString); + if (ProductionFlag.IS_EXPERIMENTAL) { + ResearchLogger.getInstance().onWordComplete(typedWord, Long.MAX_VALUE); + } } } // Called from the KeyboardSwitcher which needs to know auto caps state to display // the right layout. public int getCurrentAutoCapsState() { - if (!mCurrentSettings.mAutoCap) return Constants.TextUtils.CAP_MODE_OFF; + if (!mSettings.getCurrent().mAutoCap) return Constants.TextUtils.CAP_MODE_OFF; final EditorInfo ei = getCurrentInputEditorInfo(); if (ei == null) return Constants.TextUtils.CAP_MODE_OFF; @@ -1187,8 +1168,10 @@ public final class LatinIME extends InputMethodService implements KeyboardAction if (lastTwo != null && lastTwo.length() == 2 && lastTwo.charAt(0) == Constants.CODE_SPACE) { mConnection.deleteSurroundingText(2, 0); - mConnection.commitText(lastTwo.charAt(1) + " ", 1); + final String text = lastTwo.charAt(1) + " "; + mConnection.commitText(text, 1); if (ProductionFlag.IS_EXPERIMENTAL) { + ResearchLogger.getInstance().onWordComplete(text, Long.MAX_VALUE); ResearchLogger.latinIME_swapSwapperAndSpace(); } mKeyboardSwitcher.updateShiftState(); @@ -1196,8 +1179,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction } private boolean maybeDoubleSpacePeriod() { - if (!mCurrentSettings.mCorrectionEnabled) return false; - if (!mCurrentSettings.mUseDoubleSpacePeriod) return false; + if (!mSettings.getCurrent().mCorrectionEnabled) return false; + if (!mSettings.getCurrent().mUseDoubleSpacePeriod) return false; if (!mHandler.isAcceptingDoubleSpacePeriod()) return false; final CharSequence lastThree = mConnection.getTextBeforeCursor(3, 0); if (lastThree != null && lastThree.length() == 3 @@ -1206,7 +1189,11 @@ public final class LatinIME extends InputMethodService implements KeyboardAction && lastThree.charAt(2) == Constants.CODE_SPACE) { mHandler.cancelDoubleSpacePeriodTimer(); mConnection.deleteSurroundingText(2, 0); - mConnection.commitText(". ", 1); + final String textToInsert = ". "; + mConnection.commitText(textToInsert, 1); + if (ProductionFlag.IS_EXPERIMENTAL) { + ResearchLogger.getInstance().onWordComplete(textToInsert, Long.MAX_VALUE); + } mKeyboardSwitcher.updateShiftState(); return true; } @@ -1296,7 +1283,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction // TODO: Revise the language switch key behavior to make it much smarter and more reasonable. private void handleLanguageSwitchKey() { final IBinder token = getWindow().getWindow().getAttributes().token; - if (mCurrentSettings.mIncludesOtherImesInLanguageSwitchList) { + if (mSettings.getCurrent().mIncludesOtherImesInLanguageSwitchList) { mRichImm.switchToNextInputMethod(token, false /* onlyCurrentIme */); return; } @@ -1324,10 +1311,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction return; } - // 16 is android.os.Build.VERSION_CODES.JELLY_BEAN but we can't write it because - // we want to be able to compile against the Ice Cream Sandwich SDK. if (Constants.CODE_ENTER == code && mTargetApplicationInfo != null - && mTargetApplicationInfo.targetSdkVersion < 16) { + && mTargetApplicationInfo.targetSdkVersion < VERSION_CODES.JELLY_BEAN) { // Backward compatibility mode. Before Jelly bean, the keyboard would simulate // a hardware keyboard event on pressing enter or delete. This is bad for many // reasons (there are race conditions with commits) but some applications are @@ -1400,7 +1385,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction break; default: mSpaceState = SPACE_STATE_NONE; - if (mCurrentSettings.isWordSeparator(primaryCode)) { + if (mSettings.getCurrent().isWordSeparator(primaryCode)) { didAutoCorrect = handleSeparator(primaryCode, x, y, spaceState); } else { if (SPACE_STATE_PHANTOM == spaceState) { @@ -1445,7 +1430,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction public void onTextInput(final String rawText) { mConnection.beginBatchEdit(); if (mWordComposer.isComposingWord()) { - commitCurrentAutoCorrection(rawText.toString()); + commitCurrentAutoCorrection(rawText); } else { resetComposingState(true /* alsoResetLastComposedWord */); } @@ -1455,6 +1440,9 @@ public final class LatinIME extends InputMethodService implements KeyboardAction promotePhantomSpace(); } mConnection.commitText(text, 1); + if (ProductionFlag.IS_EXPERIMENTAL) { + ResearchLogger.getInstance().onWordComplete(text, Long.MAX_VALUE); + } mConnection.endBatchEdit(); // Space state must be updated before calling updateShiftState mSpaceState = SPACE_STATE_NONE; @@ -1495,8 +1483,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction // should usually be followed by a space, and it should be more readable. if (Constants.NOT_A_CODE != codePointBeforeCursor && !Character.isWhitespace(codePointBeforeCursor) - && !mCurrentSettings.isPhantomSpacePromotingSymbol(codePointBeforeCursor) - && !mCurrentSettings.isWeakSpaceStripper(codePointBeforeCursor)) { + && !mSettings.getCurrent().isPhantomSpacePromotingSymbol(codePointBeforeCursor) + && !mSettings.getCurrent().isWeakSpaceStripper(codePointBeforeCursor)) { mSpaceState = SPACE_STATE_PHANTOM; } } @@ -1603,9 +1591,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction if (dismissGestureFloatingPreviewText) { mainKeyboardView.dismissGestureFloatingPreviewText(); } else { - final String batchInputText = suggestedWords.isEmpty() - ? null : suggestedWords.getWord(0); - mainKeyboardView.showGestureFloatingPreviewText(batchInputText); + mainKeyboardView.showGestureFloatingPreviewText(suggestedWords); } } @@ -1739,10 +1725,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction // This should never happen. Log.e(TAG, "Backspace when we don't know the selection position"); } - // 16 is android.os.Build.VERSION_CODES.JELLY_BEAN but we can't write it because - // we want to be able to compile against the Ice Cream Sandwich SDK. if (mTargetApplicationInfo != null - && mTargetApplicationInfo.targetSdkVersion < 16) { + && mTargetApplicationInfo.targetSdkVersion < VERSION_CODES.JELLY_BEAN) { // Backward compatibility mode. Before Jelly bean, the keyboard would simulate // a hardware keyboard event on pressing enter or delete. This is bad for many // reasons (there are race conditions with commits) but some applications are @@ -1755,7 +1739,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction mConnection.deleteSurroundingText(1, 0); } } - if (mCurrentSettings.isSuggestionsRequested(mDisplayOrientation)) { + if (mSettings.getCurrent().isSuggestionsRequested(mDisplayOrientation)) { restartSuggestionsOnWordBeforeCursorIfAtEndOfWord(); } } @@ -1769,10 +1753,10 @@ public final class LatinIME extends InputMethodService implements KeyboardAction } else if ((SPACE_STATE_WEAK == spaceState || SPACE_STATE_SWAP_PUNCTUATION == spaceState) && isFromSuggestionStrip) { - if (mCurrentSettings.isWeakSpaceSwapper(code)) { + if (mSettings.getCurrent().isWeakSpaceSwapper(code)) { return true; } else { - if (mCurrentSettings.isWeakSpaceStripper(code)) { + if (mSettings.getCurrent().isWeakSpaceStripper(code)) { mConnection.removeTrailingSpace(); } return false; @@ -1787,7 +1771,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction boolean isComposingWord = mWordComposer.isComposingWord(); if (SPACE_STATE_PHANTOM == spaceState && - !mCurrentSettings.isSymbolExcludedFromWordSeparators(primaryCode)) { + !mSettings.getCurrent().isSymbolExcludedFromWordSeparators(primaryCode)) { if (isComposingWord) { // Sanity check throw new RuntimeException("Should not be composing here"); @@ -1799,9 +1783,9 @@ public final class LatinIME extends InputMethodService implements KeyboardAction // dozen milliseconds. Avoid calling it as much as possible, since we are on the UI // thread here. if (!isComposingWord && (isAlphabet(primaryCode) - || mCurrentSettings.isSymbolExcludedFromWordSeparators(primaryCode)) - && mCurrentSettings.isSuggestionsRequested(mDisplayOrientation) && - !mConnection.isCursorTouchingWord(mCurrentSettings)) { + || mSettings.getCurrent().isSymbolExcludedFromWordSeparators(primaryCode)) + && mSettings.getCurrent().isSuggestionsRequested(mDisplayOrientation) && + !mConnection.isCursorTouchingWord(mSettings.getCurrent())) { // Reset entirely the composing state anyway, then start composing a new word unless // the character is a single quote. The idea here is, single quote is not a // separator and it should be treated as a normal character, except in the first @@ -1855,7 +1839,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction boolean didAutoCorrect = false; // Handle separator if (mWordComposer.isComposingWord()) { - if (mCurrentSettings.mCorrectionEnabled) { + if (mSettings.getCurrent().mCorrectionEnabled) { // TODO: maybe cache Strings in an <String> sparse array or something commitCurrentAutoCorrection(new String(new int[]{primaryCode}, 0, 1)); didAutoCorrect = true; @@ -1868,13 +1852,13 @@ public final class LatinIME extends InputMethodService implements KeyboardAction Constants.SUGGESTION_STRIP_COORDINATE == x); if (SPACE_STATE_PHANTOM == spaceState && - mCurrentSettings.isPhantomSpacePromotingSymbol(primaryCode)) { + mSettings.getCurrent().isPhantomSpacePromotingSymbol(primaryCode)) { promotePhantomSpace(); } sendKeyCodePoint(primaryCode); if (Constants.CODE_SPACE == primaryCode) { - if (mCurrentSettings.isSuggestionsRequested(mDisplayOrientation)) { + if (mSettings.getCurrent().isSuggestionsRequested(mDisplayOrientation)) { if (maybeDoubleSpacePeriod()) { mSpaceState = SPACE_STATE_DOUBLE; } else if (!isShowingPunctuationList()) { @@ -1883,7 +1867,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction } mHandler.startDoubleSpacePeriodTimer(); - if (!mConnection.isCursorTouchingWord(mCurrentSettings)) { + if (!mConnection.isCursorTouchingWord(mSettings.getCurrent())) { mHandler.postUpdateSuggestionStrip(); } } else { @@ -1891,8 +1875,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction swapSwapperAndSpace(); mSpaceState = SPACE_STATE_SWAP_PUNCTUATION; } else if (SPACE_STATE_PHANTOM == spaceState - && !mCurrentSettings.isWeakSpaceStripper(primaryCode) - && !mCurrentSettings.isPhantomSpacePromotingSymbol(primaryCode)) { + && !mSettings.getCurrent().isWeakSpaceStripper(primaryCode) + && !mSettings.getCurrent().isPhantomSpacePromotingSymbol(primaryCode)) { // If we are in phantom space state, and the user presses a separator, we want to // stay in phantom space state so that the next keypress has a chance to add the // space. For example, if I type "Good dat", pick "day" from the suggestion strip @@ -1925,6 +1909,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction } private void handleClose() { + // TODO: Verify that words are logged properly when IME is closed. commitTyped(LastComposedWord.NOT_A_SEPARATOR); requestHideSelf(0); final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView(); @@ -1938,7 +1923,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction @UsedForTesting boolean isShowingPunctuationList() { if (mSuggestionStripView == null) return false; - return mCurrentSettings.mSuggestPuncList == mSuggestionStripView.getSuggestions(); + return mSettings.getCurrent().mSuggestPuncList == mSuggestionStripView.getSuggestions(); } private boolean isSuggestionsStripVisible() { @@ -1946,11 +1931,11 @@ public final class LatinIME extends InputMethodService implements KeyboardAction return false; if (mSuggestionStripView.isShowingAddToDictionaryHint()) return true; - if (!mCurrentSettings.isSuggestionStripVisibleInOrientation(mDisplayOrientation)) + if (!mSettings.getCurrent().isSuggestionStripVisibleInOrientation(mDisplayOrientation)) return false; - if (mCurrentSettings.isApplicationSpecifiedCompletionsOn()) + if (mSettings.getCurrent().isApplicationSpecifiedCompletionsOn()) return true; - return mCurrentSettings.isSuggestionsRequested(mDisplayOrientation); + return mSettings.getCurrent().isSuggestionsRequested(mDisplayOrientation); } private void clearSuggestionStrip() { @@ -1984,16 +1969,16 @@ public final class LatinIME extends InputMethodService implements KeyboardAction mHandler.cancelUpdateSuggestionStrip(); // Check if we have a suggestion engine attached. - if (mSuggest == null || !mCurrentSettings.isSuggestionsRequested(mDisplayOrientation)) { + if (mSuggest == null + || !mSettings.getCurrent().isSuggestionsRequested(mDisplayOrientation)) { if (mWordComposer.isComposingWord()) { Log.w(TAG, "Called updateSuggestionsOrPredictions but suggestions were not " + "requested!"); - mWordComposer.setAutoCorrection(mWordComposer.getTypedWord()); } return; } - if (!mWordComposer.isComposingWord() && !mCurrentSettings.mBigramPredictionEnabled) { + if (!mWordComposer.isComposingWord() && !mSettings.getCurrent().mBigramPredictionEnabled) { setPunctuationSuggestions(); return; } @@ -2014,10 +1999,10 @@ public final class LatinIME extends InputMethodService implements KeyboardAction // should just skip whitespace if any, so 1. // TODO: this is slow (2-way IPC) - we should probably cache this instead. final String prevWord = - mConnection.getNthPreviousWord(mCurrentSettings.mWordSeparators, + mConnection.getNthPreviousWord(mSettings.getCurrent().mWordSeparators, mWordComposer.isComposingWord() ? 2 : 1); final SuggestedWords suggestedWords = mSuggest.getSuggestedWords(mWordComposer, - prevWord, keyboard.getProximityInfo(), mCurrentSettings.mCorrectionEnabled, + prevWord, keyboard.getProximityInfo(), mSettings.getCurrent().mCorrectionEnabled, sessionId); return maybeRetrieveOlderSuggestions(typedWord, suggestedWords); } @@ -2042,7 +2027,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction private SuggestedWords getOlderSuggestions(final String typedWord) { SuggestedWords previousSuggestions = mSuggestionStripView.getSuggestions(); - if (previousSuggestions == mCurrentSettings.mSuggestPuncList) { + if (previousSuggestions == mSettings.getCurrent().mSuggestPuncList) { previousSuggestions = SuggestedWords.EMPTY; } if (typedWord == null) { @@ -2091,8 +2076,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction + "is empty? Impossible! I must commit suicide."); } if (ProductionFlag.IS_INTERNAL) { - Stats.onAutoCorrection( - typedWord, autoCorrection.toString(), separatorString, mWordComposer); + Stats.onAutoCorrection(typedWord, autoCorrection, separatorString, mWordComposer); } if (ProductionFlag.IS_EXPERIMENTAL) { ResearchLogger.latinIme_commitCurrentAutoCorrection(typedWord, autoCorrection, @@ -2124,7 +2108,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction 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, suggestedWords); + LatinImeLogger.logOnManualSuggestion("", suggestion, index, suggestedWords); // Rely on onCodeInput to do the complicated swapping/stripping logic consistently. final int primaryCode = suggestion.charAt(0); onCodeInput(primaryCode, @@ -2141,13 +2125,13 @@ public final class LatinIME extends InputMethodService implements KeyboardAction // the current batch input text and there is no need for a phantom space. && !mWordComposer.isBatchMode()) { int firstChar = Character.codePointAt(suggestion, 0); - if ((!mCurrentSettings.isWeakSpaceStripper(firstChar)) - && (!mCurrentSettings.isWeakSpaceSwapper(firstChar))) { + if ((!mSettings.getCurrent().isWeakSpaceStripper(firstChar)) + && (!mSettings.getCurrent().isWeakSpaceSwapper(firstChar))) { promotePhantomSpace(); } } - if (mCurrentSettings.isApplicationSpecifiedCompletionsOn() + if (mSettings.getCurrent().isApplicationSpecifiedCompletionsOn() && mApplicationSpecifiedCompletions != null && index >= 0 && index < mApplicationSpecifiedCompletions.length) { if (mSuggestionStripView != null) { @@ -2163,9 +2147,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction // We need to log before we commit, because the word composer will store away the user // typed word. - final String replacedWord = mWordComposer.getTypedWord().toString(); - LatinImeLogger.logOnManualSuggestion(replacedWord, - suggestion.toString(), index, suggestedWords); + final String replacedWord = mWordComposer.getTypedWord(); + LatinImeLogger.logOnManualSuggestion(replacedWord, suggestion, index, suggestedWords); mExpectingUpdateSelection = true; commitChosenWord(suggestion, LastComposedWord.COMMIT_TYPE_MANUAL_PICK, LastComposedWord.NOT_A_SEPARATOR); @@ -2193,7 +2176,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction } if (showingAddToDictionaryHint && mIsUserDictionaryAvailable) { mSuggestionStripView.showAddToDictionaryHint( - suggestion, mCurrentSettings.mHintToSaveText); + suggestion, mSettings.getCurrent().mHintToSaveText); } else { // If we're not showing the "Touch again to save", then update the suggestion strip. mHandler.postUpdateSuggestionStrip(); @@ -2214,15 +2197,15 @@ public final class LatinIME extends InputMethodService implements KeyboardAction // what user typed. Note: currently this is done much later in // LastComposedWord#didCommitTypedWord by string equality of the remembered // strings. - mLastComposedWord = mWordComposer.commitWord(commitType, chosenWord.toString(), - separatorString, prevWord); + mLastComposedWord = mWordComposer.commitWord(commitType, chosenWord, separatorString, + prevWord); } private void setPunctuationSuggestions() { - if (mCurrentSettings.mBigramPredictionEnabled) { + if (mSettings.getCurrent().mBigramPredictionEnabled) { clearSuggestionStrip(); } else { - setSuggestionStrip(mCurrentSettings.mSuggestPuncList, false); + setSuggestionStrip(mSettings.getCurrent().mSuggestPuncList, false); } setAutoCorrectionIndicator(false); setSuggestionStripShown(isSuggestionsStripVisible()); @@ -2235,12 +2218,12 @@ public final class LatinIME extends InputMethodService implements KeyboardAction // If correction is not enabled, we don't add words to the user history dictionary. // That's to avoid unintended additions in some sensitive fields, or fields that // expect to receive non-words. - if (!mCurrentSettings.mCorrectionEnabled) return null; + if (!mSettings.getCurrent().mCorrectionEnabled) return null; final UserHistoryDictionary userHistoryDictionary = mUserHistoryDictionary; if (userHistoryDictionary != null) { - final CharSequence prevWord - = mConnection.getNthPreviousWord(mCurrentSettings.mWordSeparators, 2); + final String prevWord + = mConnection.getNthPreviousWord(mSettings.getCurrent().mWordSeparators, 2); final String secondWord; if (mWordComposer.wasAutoCapitalized() && !mWordComposer.isMostlyCaps()) { secondWord = suggestion.toLowerCase(mSubtypeSwitcher.getCurrentSubtypeLocale()); @@ -2252,9 +2235,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction final int maxFreq = AutoCorrection.getMaxFrequency( mSuggest.getUnigramDictionaries(), suggestion); if (maxFreq == 0) return null; - final String prevWordString = (null == prevWord) ? null : prevWord.toString(); - userHistoryDictionary.addToUserHistory(prevWordString, secondWord, maxFreq > 0); - return prevWordString; + userHistoryDictionary.addToUserHistory(prevWord, secondWord, maxFreq > 0); + return prevWord; } return null; } @@ -2264,7 +2246,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction * word, else do nothing. */ private void restartSuggestionsOnWordBeforeCursorIfAtEndOfWord() { - final CharSequence word = mConnection.getWordBeforeCursorIfAtEndOfWord(mCurrentSettings); + final CharSequence word = + mConnection.getWordBeforeCursorIfAtEndOfWord(mSettings.getCurrent()); if (null != word) { restartSuggestionsOnWordBeforeCursor(word); } @@ -2302,8 +2285,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction } mConnection.deleteSurroundingText(deleteLength, 0); if (!TextUtils.isEmpty(previousWord) && !TextUtils.isEmpty(committedWord)) { - mUserHistoryDictionary.cancelAddingUserHistory( - previousWord.toString(), committedWord.toString()); + mUserHistoryDictionary.cancelAddingUserHistory(previousWord, committedWord); } mConnection.commitText(originallyTypedWord + mLastComposedWord.mSeparatorString, 1); if (ProductionFlag.IS_INTERNAL) { @@ -2311,7 +2293,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE); } if (ProductionFlag.IS_EXPERIMENTAL) { - ResearchLogger.latinIME_revertCommit(originallyTypedWord); + ResearchLogger.latinIME_revertCommit(committedWord, originallyTypedWord); + ResearchLogger.getInstance().onWordComplete(originallyTypedWord, Long.MAX_VALUE); } // Don't restart suggestion yet. We'll restart if the user deletes the // separator. @@ -2322,14 +2305,14 @@ public final class LatinIME extends InputMethodService implements KeyboardAction // This essentially inserts a space, and that's it. public void promotePhantomSpace() { - if (mCurrentSettings.shouldInsertSpacesAutomatically()) { + if (mSettings.getCurrent().shouldInsertSpacesAutomatically()) { sendKeyCodePoint(Constants.CODE_SPACE); } } // Used by the RingCharBuffer public boolean isWordSeparator(final int code) { - return mCurrentSettings.isWordSeparator(code); + return mSettings.getCurrent().isWordSeparator(code); } // TODO: Make this private @@ -2342,7 +2325,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction loadSettings(); if (mKeyboardSwitcher.getMainKeyboardView() != null) { // Reload keyboard because the current language has been changed. - mKeyboardSwitcher.loadKeyboard(getCurrentInputEditorInfo(), mCurrentSettings); + mKeyboardSwitcher.loadKeyboard(getCurrentInputEditorInfo(), mSettings.getCurrent()); } // Since we just changed languages, we should re-evaluate suggestions with whatever word // we are currently composing. If we are not composing anything, we may want to display @@ -2399,7 +2382,6 @@ public final class LatinIME extends InputMethodService implements KeyboardAction @Override public boolean onKeyUp(final int keyCode, final KeyEvent event) { - if (mEventInterpreter.onHardwareKeyEvent(event)) return true; return super.onKeyUp(keyCode, event); } @@ -2504,7 +2486,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction .append("\nPackage : ").append(mTargetApplicationInfo.packageName) .append("\nTarget app sdk version : ") .append(mTargetApplicationInfo.targetSdkVersion) - .append("\nAttributes : ").append(mCurrentSettings.getInputAttributesDebugString()) + .append("\nAttributes : ").append(mSettings.getCurrent().mInputAttributes) .append("\nContext : ").append(context); throw new RuntimeException(s.toString()); } @@ -2518,13 +2500,14 @@ public final class LatinIME extends InputMethodService implements KeyboardAction final Keyboard keyboard = mKeyboardSwitcher.getKeyboard(); final int keyboardMode = keyboard != null ? keyboard.mId.mMode : -1; p.println(" Keyboard mode = " + keyboardMode); + final SettingsValues settingsValues = mSettings.getCurrent(); p.println(" mIsSuggestionsSuggestionsRequested = " - + mCurrentSettings.isSuggestionsRequested(mDisplayOrientation)); - p.println(" mCorrectionEnabled=" + mCurrentSettings.mCorrectionEnabled); + + settingsValues.isSuggestionsRequested(mDisplayOrientation)); + p.println(" mCorrectionEnabled=" + settingsValues.mCorrectionEnabled); p.println(" isComposingWord=" + mWordComposer.isComposingWord()); - p.println(" mSoundOn=" + mCurrentSettings.mSoundOn); - p.println(" mVibrateOn=" + mCurrentSettings.mVibrateOn); - p.println(" mKeyPreviewPopupOn=" + mCurrentSettings.mKeyPreviewPopupOn); - p.println(" inputAttributes=" + mCurrentSettings.getInputAttributesDebugString()); + p.println(" mSoundOn=" + settingsValues.mSoundOn); + p.println(" mVibrateOn=" + settingsValues.mVibrateOn); + p.println(" mKeyPreviewPopupOn=" + settingsValues.mKeyPreviewPopupOn); + p.println(" inputAttributes=" + settingsValues.mInputAttributes); } } |