From aa161eb371d8042ef4c1f9207648b3aeacb65e4e Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 20 Dec 2013 16:34:38 +0900 Subject: [PATCH] [IL24] Move mDisplayOrientation to SettingsValues. Bug: 8636060 Change-Id: Id57ced0cca9dc9e5e85c3a53683588feb28c1402 --- .../android/inputmethod/latin/LatinIME.java | 29 ++++++++++--------- .../latin/inputlogic/InputLogic.java | 10 +++---- .../latin/settings/SettingsValues.java | 16 ++++++---- 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index f8909e86a..f97510b46 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -137,10 +137,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private boolean mUseOnlyPersonalizationDictionaryForDebug = false; private boolean mBoostPersonalizationDictionaryForDebug = false; - // Member variable for remembering the current device orientation. - // TODO[IL]: Move this to SettingsValues. - public int mDisplayOrientation; - // Object for reacting to adding/removing a dictionary pack. private BroadcastReceiver mDictionaryPackInstallReceiver = new DictionaryPackInstallBroadcastReceiver(this); @@ -485,7 +481,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.getInstance().init(this, mKeyboardSwitcher, mInputLogic.mSuggest); } - mDisplayOrientation = getResources().getConfiguration().orientation; // Register to receive ringer mode change and network state change. // Also receive installation and removal of a dictionary pack. @@ -609,8 +604,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen @Override public void onConfigurationChanged(final Configuration conf) { // If orientation changed while predicting, commit the change - if (mDisplayOrientation != conf.orientation) { - mDisplayOrientation = conf.orientation; + final SettingsValues settingsValues = mSettings.getCurrent(); + if (settingsValues.mDisplayOrientation != conf.orientation) { mHandler.startOrientationChanging(); mInputLogic.mConnection.beginBatchEdit(); mInputLogic.commitTyped(mSettings.getCurrent(), LastComposedWord.NOT_A_SEPARATOR); @@ -789,9 +784,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen canReachInputConnection = true; } + if (isDifferentTextField || + !currentSettingsValues.hasSameOrientation(getResources().getConfiguration())) { + loadSettings(); + } if (isDifferentTextField) { mainKeyboardView.closing(); - loadSettings(); currentSettingsValues = mSettings.getCurrent(); if (suggest != null && currentSettingsValues.mCorrectionEnabled) { @@ -1040,7 +1038,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen */ @Override public void onExtractedTextClicked() { - if (mSettings.getCurrent().isSuggestionsRequested(mDisplayOrientation)) return; + if (mSettings.getCurrent().isSuggestionsRequested()) { + return; + } super.onExtractedTextClicked(); } @@ -1056,7 +1056,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen */ @Override public void onExtractedCursorMovement(final int dx, final int dy) { - if (mSettings.getCurrent().isSuggestionsRequested(mDisplayOrientation)) return; + if (mSettings.getCurrent().isSuggestionsRequested()) { + return; + } super.onExtractedCursorMovement(dx, dy); } @@ -1634,11 +1636,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen return true; if (null == currentSettings) return false; - if (!currentSettings.isSuggestionStripVisibleInOrientation(mDisplayOrientation)) + if (!currentSettings.isSuggestionStripVisible()) return false; if (currentSettings.isApplicationSpecifiedCompletionsOn()) return true; - return currentSettings.isSuggestionsRequested(mDisplayOrientation); + return currentSettings.isSuggestionsRequested(); } public void dismissAddToDictionaryHint() { @@ -2278,8 +2280,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen final int keyboardMode = keyboard != null ? keyboard.mId.mMode : -1; p.println(" Keyboard mode = " + keyboardMode); final SettingsValues settingsValues = mSettings.getCurrent(); - p.println(" mIsSuggestionsRequested = " - + settingsValues.isSuggestionsRequested(mDisplayOrientation)); + p.println(" mIsSuggestionsRequested = " + settingsValues.isSuggestionsRequested()); p.println(" mCorrectionEnabled=" + settingsValues.mCorrectionEnabled); p.println(" isComposingWord=" + mInputLogic.mWordComposer.isComposingWord()); p.println(" mSoundOn=" + settingsValues.mSoundOn); diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java index b9c96555b..27b7b98d8 100644 --- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java +++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java @@ -389,7 +389,7 @@ public final class InputLogic { // a letter or a word connector. && settingsValues.isWordCodePoint(codePoint) // We never go into composing state if suggestions are not requested. - && settingsValues.isSuggestionsRequested(mLatinIME.mDisplayOrientation) && + && settingsValues.isSuggestionsRequested() && // In languages with spaces, we only start composing a word when we are not already // touching a word. In languages without spaces, the above conditions are sufficient. (!mConnection.isCursorTouchingWord(settingsValues) @@ -493,7 +493,7 @@ public final class InputLogic { } if (Constants.CODE_SPACE == codePoint) { - if (settingsValues.isSuggestionsRequested(mLatinIME.mDisplayOrientation)) { + if (settingsValues.isSuggestionsRequested()) { if (maybeDoubleSpacePeriod(settingsValues, keyboardSwitcher, handler)) { mSpaceState = SpaceState.DOUBLE; } else if (!mLatinIME.isShowingPunctuationList()) { @@ -674,8 +674,7 @@ public final class InputLogic { } } } - // TODO: move mDisplayOrientation to CurrentSettings. - if (settingsValues.isSuggestionsRequested(mLatinIME.mDisplayOrientation) + if (settingsValues.isSuggestionsRequested() && settingsValues.mCurrentLanguageHasSpaces) { restartSuggestionsOnWordBeforeCursorIfAtEndOfWord(settingsValues, keyboardSwitcher, handler); @@ -893,8 +892,7 @@ public final class InputLogic { handler.cancelUpdateSuggestionStrip(); // Check if we have a suggestion engine attached. - if (mSuggest == null - || !settingsValues.isSuggestionsRequested(mLatinIME.mDisplayOrientation)) { + if (mSuggest == null || !settingsValues.isSuggestionsRequested()) { if (mWordComposer.isComposingWord()) { Log.w(TAG, "Called updateSuggestionsOrPredictions but suggestions were not " + "requested!"); diff --git a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java index c0e8a0301..3307de8ae 100644 --- a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java @@ -101,6 +101,7 @@ public final class SettingsValues { public final int mSuggestionVisibility; public final boolean mBoostPersonalizationDictionaryForDebug; public final boolean mUseOnlyPersonalizationDictionaryForDebug; + public final int mDisplayOrientation; private final AsyncResultHolder mAppWorkarounds; // Setting values for additional features @@ -184,6 +185,7 @@ public final class SettingsValues { Settings.readBoostPersonalizationDictionaryForDebug(prefs); mUseOnlyPersonalizationDictionaryForDebug = Settings.readUseOnlyPersonalizationDictionaryForDebug(prefs); + mDisplayOrientation = res.getConfiguration().orientation; mAppWorkarounds = new AsyncResultHolder(); final PackageInfo packageInfo = TargetPackageInfoGetterTask.getCachedPackageInfo( mInputAttributes.mTargetApplicationPackageName); @@ -241,6 +243,7 @@ public final class SettingsValues { mIsInternal = false; mBoostPersonalizationDictionaryForDebug = false; mUseOnlyPersonalizationDictionaryForDebug = false; + mDisplayOrientation = Configuration.ORIENTATION_PORTRAIT; mAppWorkarounds = new AsyncResultHolder(); mAppWorkarounds.set(null); } @@ -254,16 +257,15 @@ public final class SettingsValues { return mInputAttributes.mApplicationSpecifiedCompletionOn; } - public boolean isSuggestionsRequested(final int displayOrientation) { + public boolean isSuggestionsRequested() { return mInputAttributes.mIsSettingsSuggestionStripOn - && (mCorrectionEnabled - || isSuggestionStripVisibleInOrientation(displayOrientation)); + && (mCorrectionEnabled || isSuggestionStripVisible()); } - public boolean isSuggestionStripVisibleInOrientation(final int orientation) { + public boolean isSuggestionStripVisible() { return (mSuggestionVisibility == SUGGESTION_VISIBILITY_SHOW_VALUE) || (mSuggestionVisibility == SUGGESTION_VISIBILITY_SHOW_ONLY_PORTRAIT_VALUE - && orientation == Configuration.ORIENTATION_PORTRAIT); + && mDisplayOrientation == Configuration.ORIENTATION_PORTRAIT); } public boolean isWordSeparator(final int code) { @@ -306,6 +308,10 @@ public final class SettingsValues { return mInputAttributes.isSameInputType(editorInfo); } + public boolean hasSameOrientation(final Configuration configuration) { + return mDisplayOrientation == configuration.orientation; + } + public boolean isBeforeJellyBean() { final AppWorkaroundsUtils appWorkaroundUtils = mAppWorkarounds.get(null, TIMEOUT_TO_GET_TARGET_PACKAGE);