From e234aed4288efd7b4336f3755a958c25a1540b98 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Wed, 15 Aug 2012 17:57:38 +0900 Subject: [PATCH] Refresh editor info when the text field attributes changes. For some reason we get a "restarting" flag from the browser some times when the input field is different. The attributes however are not the same, so we can detect that and reload appropriately. Bug: 6946793 Change-Id: I6762dae6f41db690497b026a707d9cc89c840b34 --- .../android/inputmethod/latin/InputAttributes.java | 6 ++++++ java/src/com/android/inputmethod/latin/LatinIME.java | 12 +++++++----- .../android/inputmethod/latin/SettingsValues.java | 4 ++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/InputAttributes.java b/java/src/com/android/inputmethod/latin/InputAttributes.java index e561f5956..7bcda9bc4 100644 --- a/java/src/com/android/inputmethod/latin/InputAttributes.java +++ b/java/src/com/android/inputmethod/latin/InputAttributes.java @@ -29,10 +29,12 @@ public class InputAttributes { final public boolean mInputTypeNoAutoCorrect; final public boolean mIsSettingsSuggestionStripOn; final public boolean mApplicationSpecifiedCompletionOn; + final private int mInputType; public InputAttributes(final EditorInfo editorInfo, final boolean isFullscreenMode) { final int inputType = null != editorInfo ? editorInfo.inputType : 0; final int inputClass = inputType & InputType.TYPE_MASK_CLASS; + mInputType = inputType; if (inputClass != InputType.TYPE_CLASS_TEXT) { // If we are not looking at a TYPE_CLASS_TEXT field, the following strange // cases may arise, so we do a couple sanity checks for them. If it's a @@ -93,6 +95,10 @@ public class InputAttributes { } } + public boolean isSameInputType(final EditorInfo editorInfo) { + return editorInfo.inputType == mInputType; + } + @SuppressWarnings("unused") private void dumpFlags(final int inputType) { Log.i(TAG, "Input class:"); diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 446d44e7a..884e6db29 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -670,7 +670,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen accessUtils.onStartInputViewInternal(mainKeyboardView, editorInfo, restarting); } - if (!restarting) { + final boolean selectionChanged = mLastSelectionStart != editorInfo.initialSelStart + || mLastSelectionEnd != editorInfo.initialSelEnd; + final boolean inputTypeChanged = !mCurrentSettings.isSameInputType(editorInfo); + final boolean isDifferentTextField = !restarting || inputTypeChanged; + if (isDifferentTextField) { mSubtypeSwitcher.updateParametersOnStartInputView(); } @@ -679,9 +683,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen updateFullscreenMode(); mApplicationSpecifiedCompletions = null; - final boolean selectionChanged = mLastSelectionStart != editorInfo.initialSelStart - || mLastSelectionEnd != editorInfo.initialSelEnd; - if (!restarting || selectionChanged) { + if (isDifferentTextField || selectionChanged) { // If the selection changed, we reset the input state. Essentially, we come here with // restarting == true when the app called setText() or similar. We should reset the // state if the app set the text to something else, but keep it if it set a suggestion @@ -696,7 +698,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } } - if (!restarting) { + if (isDifferentTextField) { mainKeyboardView.closing(); loadSettings(); diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 0843bdbbc..c8755be9d 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -417,6 +417,10 @@ public class SettingsValues { prefs.edit().putString(Settings.PREF_LAST_USER_DICTIONARY_WRITE_TIME, newStr).apply(); } + public boolean isSameInputType(final EditorInfo editorInfo) { + return mInputAttributes.isSameInputType(editorInfo); + } + // For debug. public String getInputAttributesDebugString() { return mInputAttributes.toString();