From 0fe3611bee5095e7bd0fff2d0fdf8d5a13379132 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 9 Dec 2011 20:16:57 +0900 Subject: [PATCH] Resolve TODOs: add some members to store prefs Change-Id: Idf09cb5d801e8008eb63cbb5138058faeb7db136 --- .../android/inputmethod/latin/LatinIME.java | 5 ++-- .../inputmethod/latin/SettingsValues.java | 27 +++++++++++++------ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index de273b56f..b39e1543b 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -144,6 +144,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar */ private static final String SCHEME_PACKAGE = "package"; + // TODO: migrate this to SettingsValues private int mSuggestionVisibility; private static final int SUGGESTION_VISIBILILTY_SHOW_VALUE = R.string.prefs_suggestion_visibility_show_value; @@ -2389,9 +2390,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } private void updateSuggestionVisibility(final SharedPreferences prefs, final Resources res) { - final String suggestionVisiblityStr = prefs.getString( - Settings.PREF_SHOW_SUGGESTIONS_SETTING, - res.getString(R.string.prefs_suggestion_visibility_default_value)); + final String suggestionVisiblityStr = mSettingsValues.mShowSuggestionsSetting; for (int visibility : SUGGESTION_VISIBILITY_VALUE_ARRAY) { if (suggestionVisiblityStr.equals(res.getString(visibility))) { mSuggestionVisibility = visibility; diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 90d611ceb..343427a38 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -50,9 +50,9 @@ public class SettingsValues { private final boolean mShowSettingsKey; private final String mVoiceMode; private final String mAutoCorrectionThresholdRawValue; - // TODO: add a member for the raw "show_suggestions_setting" setting - // TODO: add a member for the raw "usability_study_mode" setting - // TODO: add a member for the raw "pref_key_preview_popup_dismiss_delay" setting + public final String mShowSuggestionsSetting; + private final boolean mUsabilityStudyMode; + private final String mKeyPreviewPopupDismissDelayRawValue; public final boolean mUseContactsDict; // Suggestion: use bigrams to adjust scores of suggestions obtained from unigram dictionary public final boolean mBigramSuggestionEnabled; @@ -107,8 +107,14 @@ public class SettingsValues { mVoiceMode = prefs.getString(Settings.PREF_VOICE_MODE, voiceModeMain); mAutoCorrectionThresholdRawValue = prefs.getString(Settings.PREF_AUTO_CORRECTION_THRESHOLD, res.getString(R.string.auto_correction_threshold_mode_index_modest)); + mShowSuggestionsSetting = prefs.getString(Settings.PREF_SHOW_SUGGESTIONS_SETTING, + res.getString(R.string.prefs_suggestion_visibility_default_value)); + mUsabilityStudyMode = getUsabilityStudyMode(prefs, res); + mKeyPreviewPopupDismissDelayRawValue = prefs.getString( + Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY, + Integer.toString(res.getInteger(R.integer.config_delay_after_preview))); mUseContactsDict = prefs.getBoolean(Settings.PREF_KEY_USE_CONTACTS_DICT, true); - mAutoCorrectEnabled = isAutoCorrectEnabled(prefs, res); + mAutoCorrectEnabled = isAutoCorrectEnabled(prefs, res, mAutoCorrectionThresholdRawValue); mBigramSuggestionEnabled = mAutoCorrectEnabled && isBigramSuggestionEnabled(prefs, res, mAutoCorrectEnabled); mBigramPredictionEnabled = mBigramSuggestionEnabled @@ -191,10 +197,8 @@ public class SettingsValues { return mMagicSpaceSwappers.contains(String.valueOf((char)code)); } - private static boolean isAutoCorrectEnabled(SharedPreferences sp, Resources resources) { - final String currentAutoCorrectionSetting = sp.getString( - Settings.PREF_AUTO_CORRECTION_THRESHOLD, - resources.getString(R.string.auto_correction_threshold_mode_index_modest)); + private static boolean isAutoCorrectEnabled(final SharedPreferences sp, + final Resources resources, final String currentAutoCorrectionSetting) { final String autoCorrectionOff = resources.getString( R.string.auto_correction_threshold_mode_index_off); return !currentAutoCorrectionSetting.equals(autoCorrectionOff); @@ -213,6 +217,7 @@ public class SettingsValues { // Likewise public static int getKeyPreviewPopupDismissDelay(SharedPreferences sp, Resources resources) { + // TODO: use mKeyPreviewPopupDismissDelayRawValue instead of reading it again here. return Integer.parseInt(sp.getString(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY, Integer.toString(resources.getInteger(R.integer.config_delay_after_preview)))); } @@ -307,4 +312,10 @@ public class SettingsValues { } return -1; } + + // Likewise + public static boolean getUsabilityStudyMode(final SharedPreferences prefs, + final Resources res) { + return prefs.getBoolean(Settings.PREF_USABILITY_STUDY_MODE, true); + } }