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); }