From ab661e3ef886a36b02fe094864ae4be6a3260f71 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 22 Jul 2014 10:18:38 -0700 Subject: [PATCH] Make "Show correction suggestions" as a binary option Formerly "Show correction suggestions" had three options, "always show", "show in portrait mode", and "always hide". The reason behind "show in portrait mode" was that there may not be enough screen estate in landscape mode to show suggestions. Because recent phone devices have relatively large screen, we decide to remove "show in portrait mode" option. Bug: 15780939 Change-Id: I896d737452c3893d43ce20bd88127f10c1eb3d83 --- java/res/values/donottranslate.xml | 20 ------ java/res/values/strings.xml | 3 - java/res/xml/prefs.xml | 8 +-- .../android/inputmethod/latin/LatinIME.java | 14 ++--- .../latin/inputlogic/InputLogic.java | 14 ++--- .../inputmethod/latin/settings/Settings.java | 4 +- .../latin/settings/SettingsFragment.java | 2 - .../latin/settings/SettingsValues.java | 61 +++++++------------ .../inputmethod/latin/InputLogicTests.java | 20 +++--- 9 files changed, 52 insertions(+), 94 deletions(-) diff --git a/java/res/values/donottranslate.xml b/java/res/values/donottranslate.xml index 83d082f82..e3f0aeade 100644 --- a/java/res/values/donottranslate.xml +++ b/java/res/values/donottranslate.xml @@ -18,26 +18,6 @@ */ --> - - 0 - - 1 - - 2 - - 0 - - - @string/prefs_suggestion_visibility_show_value - @string/prefs_suggestion_visibility_show_only_portrait_value - @string/prefs_suggestion_visibility_hide_value - - - @string/prefs_suggestion_visibility_show_name - @string/prefs_suggestion_visibility_show_only_portrait_name - @string/prefs_suggestion_visibility_hide_name - - 0 diff --git a/java/res/values/strings.xml b/java/res/values/strings.xml index 6df69ed47..b6601c8c2 100644 --- a/java/res/values/strings.xml +++ b/java/res/values/strings.xml @@ -108,9 +108,6 @@ Show correction suggestions Display suggested words while typing - Always show - Show in portrait mode - Always hide Block offensive words diff --git a/java/res/xml/prefs.xml b/java/res/xml/prefs.xml index 6febb3126..7e4c28496 100644 --- a/java/res/xml/prefs.xml +++ b/java/res/xml/prefs.xml @@ -144,13 +144,11 @@ android:entries="@array/auto_correction_threshold_modes" android:defaultValue="@string/auto_correction_threshold_mode_index_modest" android:persistent="true" /> - mAppWorkarounds; @@ -155,11 +154,9 @@ public final class SettingsValues { mGestureFloatingPreviewTextEnabled = prefs.getBoolean( Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT, true); mPhraseGestureEnabled = Settings.readPhraseGestureEnabled(prefs, res); - mAutoCorrectionEnabled = mAutoCorrectEnabled && !mInputAttributes.mInputTypeNoAutoCorrect; - final String showSuggestionsSetting = prefs.getString( - Settings.PREF_SHOW_SUGGESTIONS_SETTING, - res.getString(R.string.prefs_suggestion_visibility_default_value)); - mSuggestionVisibility = createSuggestionVisibility(res, showSuggestionsSetting); + mAutoCorrectionEnabledPerUserSettings = mAutoCorrectEnabled + && !mInputAttributes.mInputTypeNoAutoCorrect; + mSuggestionsEnabledPerUserSettings = readSuggestionsEnabled(prefs); AdditionalFeaturesSettingUtils.readAdditionalFeaturesPreferencesIntoArray( prefs, mAdditionalFeaturesSettingValues); mIsInternal = Settings.isInternal(prefs); @@ -193,17 +190,13 @@ public final class SettingsValues { return mInputAttributes.mApplicationSpecifiedCompletionOn; } - // TODO: Rename this to needsToLookupSuggestions(). - public boolean isSuggestionsRequested() { + public boolean needsToLookupSuggestions() { return mInputAttributes.mShouldShowSuggestions - && (mAutoCorrectionEnabled - || isCurrentOrientationAllowingSuggestionsPerUserSettings()); + && (mAutoCorrectionEnabledPerUserSettings || isSuggestionsEnabledPerUserSettings()); } - public boolean isCurrentOrientationAllowingSuggestionsPerUserSettings() { - return (mSuggestionVisibility == SUGGESTION_VISIBILITY_SHOW_VALUE) - || (mSuggestionVisibility == SUGGESTION_VISIBILITY_SHOW_ONLY_PORTRAIT_VALUE - && mDisplayOrientation == Configuration.ORIENTATION_PORTRAIT); + public boolean isSuggestionsEnabledPerUserSettings() { + return mSuggestionsEnabledPerUserSettings; } public boolean isWordSeparator(final int code) { @@ -263,26 +256,18 @@ public final class SettingsValues { return null == appWorkaroundUtils ? false : appWorkaroundUtils.isBrokenByRecorrection(); } - private static final int SUGGESTION_VISIBILITY_SHOW_VALUE = - R.string.prefs_suggestion_visibility_show_value; - private static final int SUGGESTION_VISIBILITY_SHOW_ONLY_PORTRAIT_VALUE = - R.string.prefs_suggestion_visibility_show_only_portrait_value; - private static final int SUGGESTION_VISIBILITY_HIDE_VALUE = - R.string.prefs_suggestion_visibility_hide_value; - private static final int[] SUGGESTION_VISIBILITY_VALUE_ARRAY = new int[] { - SUGGESTION_VISIBILITY_SHOW_VALUE, - SUGGESTION_VISIBILITY_SHOW_ONLY_PORTRAIT_VALUE, - SUGGESTION_VISIBILITY_HIDE_VALUE - }; + private static final String SUGGESTIONS_VISIBILITY_HIDE_VALUE_OBSOLETE = "2"; - private static int createSuggestionVisibility(final Resources res, - final String suggestionVisiblityStr) { - for (int visibility : SUGGESTION_VISIBILITY_VALUE_ARRAY) { - if (suggestionVisiblityStr.equals(res.getString(visibility))) { - return visibility; - } + private static boolean readSuggestionsEnabled(final SharedPreferences prefs) { + if (prefs.contains(Settings.PREF_SHOW_SUGGESTIONS_SETTING_OBSOLETE)) { + final boolean alwaysHide = SUGGESTIONS_VISIBILITY_HIDE_VALUE_OBSOLETE.equals( + prefs.getString(Settings.PREF_SHOW_SUGGESTIONS_SETTING_OBSOLETE, null)); + prefs.edit() + .remove(Settings.PREF_SHOW_SUGGESTIONS_SETTING_OBSOLETE) + .putBoolean(Settings.PREF_SHOW_SUGGESTIONS, !alwaysHide) + .apply(); } - throw new RuntimeException("Bug: visibility string is not configured correctly"); + return prefs.getBoolean(Settings.PREF_SHOW_SUGGESTIONS, true); } private static boolean readBigramPredictionEnabled(final SharedPreferences prefs, @@ -396,10 +381,10 @@ public final class SettingsValues { sb.append("" + mAutoCorrectEnabled); sb.append("\n mAutoCorrectionThreshold = "); sb.append("" + mAutoCorrectionThreshold); - sb.append("\n mAutoCorrectionEnabled = "); - sb.append("" + mAutoCorrectionEnabled); - sb.append("\n mSuggestionVisibility = "); - sb.append("" + mSuggestionVisibility); + sb.append("\n mAutoCorrectionEnabledPerUserSettings = "); + sb.append("" + mAutoCorrectionEnabledPerUserSettings); + sb.append("\n mSuggestionsEnabledPerUserSettings = "); + sb.append("" + mSuggestionsEnabledPerUserSettings); sb.append("\n mDisplayOrientation = "); sb.append("" + mDisplayOrientation); sb.append("\n mAppWorkarounds = "); diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTests.java b/tests/src/com/android/inputmethod/latin/InputLogicTests.java index de9475af4..59b858dbd 100644 --- a/tests/src/com/android/inputmethod/latin/InputLogicTests.java +++ b/tests/src/com/android/inputmethod/latin/InputLogicTests.java @@ -16,12 +16,12 @@ package com.android.inputmethod.latin; -import com.android.inputmethod.latin.settings.Settings; - import android.test.suitebuilder.annotation.LargeTest; import android.text.TextUtils; import android.view.inputmethod.BaseInputConnection; +import com.android.inputmethod.latin.settings.Settings; + @LargeTest public class InputLogicTests extends InputTestsBase { @@ -242,16 +242,14 @@ public class InputLogicTests extends InputTestsBase { public void testDoubleSpacePeriod() { // Reset settings to default, else these tests will go flaky. - setStringPreference(Settings.PREF_SHOW_SUGGESTIONS_SETTING, "0", "0"); + setBooleanPreference(Settings.PREF_SHOW_SUGGESTIONS, true, true); setStringPreference(Settings.PREF_AUTO_CORRECTION_THRESHOLD, "1", "1"); setBooleanPreference(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true, true); testDoubleSpacePeriodWithSettings(true /* expectsPeriod */); - // "Suggestion visibility" to "always hide" - testDoubleSpacePeriodWithSettings(true, Settings.PREF_SHOW_SUGGESTIONS_SETTING, "2"); - // "Suggestion visibility" to "portrait only" - testDoubleSpacePeriodWithSettings(true, Settings.PREF_SHOW_SUGGESTIONS_SETTING, "1"); - // "Suggestion visibility" to "always show" - testDoubleSpacePeriodWithSettings(true, Settings.PREF_SHOW_SUGGESTIONS_SETTING, "0"); + // "Suggestion visibility" to off + testDoubleSpacePeriodWithSettings(true, Settings.PREF_SHOW_SUGGESTIONS, false); + // "Suggestion visibility" to on + testDoubleSpacePeriodWithSettings(true, Settings.PREF_SHOW_SUGGESTIONS, true); // "Double-space period" to "off" testDoubleSpacePeriodWithSettings(false, Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, false); @@ -264,10 +262,10 @@ public class InputLogicTests extends InputTestsBase { testDoubleSpacePeriodWithSettings(true, Settings.PREF_AUTO_CORRECTION_THRESHOLD, "3"); // "Suggestion visibility" to "always hide" and "Auto-correction" to "off" - testDoubleSpacePeriodWithSettings(true, Settings.PREF_SHOW_SUGGESTIONS_SETTING, "0", + testDoubleSpacePeriodWithSettings(true, Settings.PREF_SHOW_SUGGESTIONS, false, Settings.PREF_AUTO_CORRECTION_THRESHOLD, "0"); // "Suggestion visibility" to "always hide" and "Auto-correction" to "off" - testDoubleSpacePeriodWithSettings(false, Settings.PREF_SHOW_SUGGESTIONS_SETTING, "0", + testDoubleSpacePeriodWithSettings(false, Settings.PREF_SHOW_SUGGESTIONS, false, Settings.PREF_AUTO_CORRECTION_THRESHOLD, "0", Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, false); }