diff options
author | 2015-03-12 19:39:06 -0700 | |
---|---|---|
committer | 2015-03-13 12:21:26 -0700 | |
commit | 116e58c437526ea2503564317e2731b8126acaa4 (patch) | |
tree | 8e396e56a3d648e4828218d27e55ec1c06c3dc1e | |
parent | 80f90349555ac22f83175e6f19d1ed5e0d673d85 (diff) | |
download | latinime-116e58c437526ea2503564317e2731b8126acaa4.tar.gz latinime-116e58c437526ea2503564317e2731b8126acaa4.tar.xz latinime-116e58c437526ea2503564317e2731b8126acaa4.zip |
Remove autocorrection aggressiveness settings.
Replace multiple settings with binary switch for autocorrection.
Bug: 19589766
Change-Id: Ic8a0362dd36d18930493a55699851161e9cb23e8
5 files changed, 43 insertions, 28 deletions
diff --git a/java/res/xml/prefs_screen_correction.xml b/java/res/xml/prefs_screen_correction.xml index 020d3afa6..284231bf1 100644 --- a/java/res/xml/prefs_screen_correction.xml +++ b/java/res/xml/prefs_screen_correction.xml @@ -41,13 +41,11 @@ android:summary="@string/prefs_block_potentially_offensive_summary" android:defaultValue="@bool/config_block_potentially_offensive" android:persistent="true" /> - <ListPreference - android:key="auto_correction_threshold" + <CheckBoxPreference + android:key="pref_key_auto_correction" android:title="@string/auto_correction" android:summary="@string/auto_correction_summary" - android:entryValues="@array/auto_correction_threshold_mode_indexes" - android:entries="@array/auto_correction_threshold_modes" - android:defaultValue="@string/auto_correction_threshold_mode_index_modest" + android:defaultValue="true" android:persistent="true" /> <CheckBoxPreference android:key="show_suggestions" diff --git a/java/src/com/android/inputmethod/latin/settings/Settings.java b/java/src/com/android/inputmethod/latin/settings/Settings.java index 5596c7fe9..6567e7159 100644 --- a/java/src/com/android/inputmethod/latin/settings/Settings.java +++ b/java/src/com/android/inputmethod/latin/settings/Settings.java @@ -57,7 +57,10 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang public static final String PREF_VOICE_INPUT_KEY = "pref_voice_input_key"; public static final String PREF_EDIT_PERSONAL_DICTIONARY = "edit_personal_dictionary"; public static final String PREF_CONFIGURE_DICTIONARIES_KEY = "configure_dictionaries_key"; - public static final String PREF_AUTO_CORRECTION_THRESHOLD = "auto_correction_threshold"; + // PREF_AUTO_CORRECTION_THRESHOLD_OBSOLETE is obsolete. Use PREF_AUTO_CORRECTION instead. + public static final String PREF_AUTO_CORRECTION_THRESHOLD_OBSOLETE = + "auto_correction_threshold"; + public static final String PREF_AUTO_CORRECTION = "pref_key_auto_correction"; // PREF_SHOW_SUGGESTIONS_SETTING_OBSOLETE is obsolete. Use PREF_SHOW_SUGGESTIONS instead. public static final String PREF_SHOW_SUGGESTIONS_SETTING_OBSOLETE = "show_suggestions_setting"; public static final String PREF_SHOW_SUGGESTIONS = "show_suggestions"; @@ -139,6 +142,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang mRes = context.getResources(); mPrefs = PreferenceManager.getDefaultSharedPreferences(context); mPrefs.registerOnSharedPreferenceChangeListener(this); + upgradeAutocorrectionSettings(mPrefs, mRes); } public void onDestroy() { @@ -207,11 +211,9 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang res.getBoolean(R.bool.config_default_vibration_enabled)); } - public static boolean readAutoCorrectEnabled(final String currentAutoCorrectionSetting, + public static boolean readAutoCorrectEnabled(final SharedPreferences prefs, final Resources res) { - final String autoCorrectionOff = res.getString( - R.string.auto_correction_threshold_mode_index_off); - return !currentAutoCorrectionSetting.equals(autoCorrectionOff); + return prefs.getBoolean(PREF_AUTO_CORRECTION, true); } public static float readPlausibilityThreshold(final Resources res) { @@ -421,4 +423,21 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang final SharedPreferences prefs, final int defValue) { return prefs.getInt(PREF_LAST_SHOWN_EMOJI_CATEGORY_ID, defValue); } + + private void upgradeAutocorrectionSettings(final SharedPreferences prefs, final Resources res) { + final String thresholdSetting = + prefs.getString(PREF_AUTO_CORRECTION_THRESHOLD_OBSOLETE, null); + if (thresholdSetting != null) { + SharedPreferences.Editor editor = prefs.edit(); + editor.remove(PREF_AUTO_CORRECTION_THRESHOLD_OBSOLETE); + final String autoCorrectionOff = + res.getString(R.string.auto_correction_threshold_mode_index_off); + if (thresholdSetting.equals(autoCorrectionOff)) { + editor.putBoolean(PREF_AUTO_CORRECTION, false); + } else { + editor.putBoolean(PREF_AUTO_CORRECTION, true); + } + editor.commit(); + } + } } diff --git a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java index ed11de96e..3dbbfad9d 100644 --- a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java @@ -135,9 +135,6 @@ public class SettingsValues { mShowsVoiceInputKey = needsToShowVoiceInputKey(prefs, res) && mInputAttributes.mShouldShowVoiceInputKey && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN; - final String autoCorrectionThresholdRawValue = prefs.getString( - Settings.PREF_AUTO_CORRECTION_THRESHOLD, - res.getString(R.string.auto_correction_threshold_mode_index_modest)); mIncludesOtherImesInLanguageSwitchList = Settings.ENABLE_SHOW_LANGUAGE_SWITCH_KEY_SETTINGS ? prefs.getBoolean(Settings.PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST, false) : true /* forcibly */; @@ -148,7 +145,10 @@ public class SettingsValues { mUseDoubleSpacePeriod = prefs.getBoolean(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true) && inputAttributes.mIsGeneralTextInput; mBlockPotentiallyOffensive = Settings.readBlockPotentiallyOffensive(prefs, res); - mAutoCorrectEnabled = Settings.readAutoCorrectEnabled(autoCorrectionThresholdRawValue, res); + mAutoCorrectEnabled = Settings.readAutoCorrectEnabled(prefs, res); + final String autoCorrectionThresholdRawValue = mAutoCorrectEnabled + ? res.getString(R.string.auto_correction_threshold_mode_index_modest) + : res.getString(R.string.auto_correction_threshold_mode_index_off); mDoubleSpacePeriodTimeout = res.getInteger(R.integer.config_double_space_period_timeout); mHasHardwareKeyboard = Settings.readHasHardwareKeyboard(res.getConfiguration()); mEnableMetricsLogging = prefs.getBoolean(Settings.PREF_ENABLE_METRICS_LOGGING, true); diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTests.java b/tests/src/com/android/inputmethod/latin/InputLogicTests.java index a6c9bbee0..e09b1e936 100644 --- a/tests/src/com/android/inputmethod/latin/InputLogicTests.java +++ b/tests/src/com/android/inputmethod/latin/InputLogicTests.java @@ -265,7 +265,7 @@ public class InputLogicTests extends InputTestsBase { public void testDoubleSpacePeriod() { // Reset settings to default, else these tests will go flaky. setBooleanPreference(Settings.PREF_SHOW_SUGGESTIONS, true, true); - setStringPreference(Settings.PREF_AUTO_CORRECTION_THRESHOLD, "1", "1"); + setBooleanPreference(Settings.PREF_AUTO_CORRECTION, true, true); setBooleanPreference(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true, true); testDoubleSpacePeriodWithSettings(true /* expectsPeriod */); // "Suggestion visibility" to off @@ -277,18 +277,16 @@ public class InputLogicTests extends InputTestsBase { testDoubleSpacePeriodWithSettings(false, Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, false); // "Auto-correction" to "off" - testDoubleSpacePeriodWithSettings(true, Settings.PREF_AUTO_CORRECTION_THRESHOLD, "0"); - // "Auto-correction" to "modest" - testDoubleSpacePeriodWithSettings(true, Settings.PREF_AUTO_CORRECTION_THRESHOLD, "1"); - // "Auto-correction" to "very aggressive" - testDoubleSpacePeriodWithSettings(true, Settings.PREF_AUTO_CORRECTION_THRESHOLD, "3"); + testDoubleSpacePeriodWithSettings(true, Settings.PREF_AUTO_CORRECTION, false); + // "Auto-correction" to "on" + testDoubleSpacePeriodWithSettings(true, Settings.PREF_AUTO_CORRECTION, true); // "Suggestion visibility" to "always hide" and "Auto-correction" to "off" testDoubleSpacePeriodWithSettings(true, Settings.PREF_SHOW_SUGGESTIONS, false, - Settings.PREF_AUTO_CORRECTION_THRESHOLD, "0"); + Settings.PREF_AUTO_CORRECTION, false); // "Suggestion visibility" to "always hide" and "Auto-correction" to "off" testDoubleSpacePeriodWithSettings(false, Settings.PREF_SHOW_SUGGESTIONS, false, - Settings.PREF_AUTO_CORRECTION_THRESHOLD, "0", + Settings.PREF_AUTO_CORRECTION, false, Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, false); } diff --git a/tests/src/com/android/inputmethod/latin/InputTestsBase.java b/tests/src/com/android/inputmethod/latin/InputTestsBase.java index ea7823c64..d5e93744a 100644 --- a/tests/src/com/android/inputmethod/latin/InputTestsBase.java +++ b/tests/src/com/android/inputmethod/latin/InputTestsBase.java @@ -58,7 +58,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> { // Default value for auto-correction threshold. This is the string representation of the // index in the resources array of auto-correction threshold settings. - private static final String DEFAULT_AUTO_CORRECTION_THRESHOLD = "1"; + private static final boolean DEFAULT_AUTO_CORRECTION = true; // The message that sets the underline is posted with a 500 ms delay protected static final int DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS = 500; @@ -77,7 +77,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> { protected MyEditText mEditText; protected View mInputView; protected InputConnection mInputConnection; - private String mPreviousAutoCorrectSetting; + private boolean mPreviousAutoCorrectSetting; // A helper class to ease span tests public static class SpanGetter { @@ -200,8 +200,8 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> { setupService(); mLatinIME = getService(); setDebugMode(true); - mPreviousAutoCorrectSetting = setStringPreference(Settings.PREF_AUTO_CORRECTION_THRESHOLD, - DEFAULT_AUTO_CORRECTION_THRESHOLD, DEFAULT_AUTO_CORRECTION_THRESHOLD); + mPreviousAutoCorrectSetting = setBooleanPreference(Settings.PREF_AUTO_CORRECTION, + DEFAULT_AUTO_CORRECTION, DEFAULT_AUTO_CORRECTION); mLatinIME.onCreate(); EditorInfo ei = new EditorInfo(); final InputConnection ic = mEditText.onCreateInputConnection(ei); @@ -230,8 +230,8 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> { mLatinIME.onFinishInput(); runMessages(); mLatinIME.mHandler.removeAllMessages(); - setStringPreference(Settings.PREF_AUTO_CORRECTION_THRESHOLD, mPreviousAutoCorrectSetting, - DEFAULT_AUTO_CORRECTION_THRESHOLD); + setBooleanPreference(Settings.PREF_AUTO_CORRECTION, mPreviousAutoCorrectSetting, + DEFAULT_AUTO_CORRECTION); setDebugMode(false); mLatinIME.recycle(); super.tearDown(); |