Straighten out prefs reading code
Change-Id: Ibf9113a8ef07ac720100ee32d2e5ef321e8ddd98main
parent
bab1f045f4
commit
c40b807ca4
|
@ -178,7 +178,7 @@ public class Settings extends InputMethodSettingsActivity
|
||||||
final PreferenceGroup miscSettings =
|
final PreferenceGroup miscSettings =
|
||||||
(PreferenceGroup) findPreference(PREF_MISC_SETTINGS);
|
(PreferenceGroup) findPreference(PREF_MISC_SETTINGS);
|
||||||
|
|
||||||
if (!SettingsValues.isShowSettingsKeyOption(res)) {
|
if (!SettingsValues.isShowSettingsKeyOptionEnabled(res)) {
|
||||||
generalSettings.removePreference(mShowSettingsKeyPreference);
|
generalSettings.removePreference(mShowSettingsKeyPreference);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,28 +96,24 @@ public class SettingsValues {
|
||||||
mHintToSaveText = context.getText(R.string.hint_add_to_dictionary);
|
mHintToSaveText = context.getText(R.string.hint_add_to_dictionary);
|
||||||
|
|
||||||
// Get the settings preferences
|
// Get the settings preferences
|
||||||
final boolean hasVibrator = VibratorCompatWrapper.getInstance(context).hasVibrator();
|
mAutoCap = prefs.getBoolean(Settings.PREF_AUTO_CAP, true);
|
||||||
mVibrateOn = hasVibrator && prefs.getBoolean(Settings.PREF_VIBRATE_ON,
|
mVibrateOn = isVibrateOn(context, prefs, res);
|
||||||
res.getBoolean(R.bool.config_default_vibration_enabled));
|
|
||||||
mSoundOn = prefs.getBoolean(Settings.PREF_SOUND_ON,
|
mSoundOn = prefs.getBoolean(Settings.PREF_SOUND_ON,
|
||||||
res.getBoolean(R.bool.config_default_sound_enabled));
|
res.getBoolean(R.bool.config_default_sound_enabled));
|
||||||
mKeyPreviewPopupOn = isKeyPreviewPopupEnabled(prefs, res);
|
mKeyPreviewPopupOn = isKeyPreviewPopupEnabled(prefs, res);
|
||||||
mKeyPreviewPopupDismissDelay = getKeyPreviewPopupDismissDelay(prefs, res);
|
mShowSettingsKey = isSettingsKeyShown(prefs, res);
|
||||||
mAutoCap = prefs.getBoolean(Settings.PREF_AUTO_CAP, true);
|
mUseContactsDict = prefs.getBoolean(Settings.PREF_KEY_USE_CONTACTS_DICT, true);
|
||||||
mAutoCorrectEnabled = isAutoCorrectEnabled(prefs, res);
|
mAutoCorrectEnabled = isAutoCorrectEnabled(prefs, res);
|
||||||
mBigramSuggestionEnabled = mAutoCorrectEnabled
|
mBigramSuggestionEnabled = mAutoCorrectEnabled
|
||||||
&& isBigramSuggestionEnabled(prefs, res, mAutoCorrectEnabled);
|
&& isBigramSuggestionEnabled(prefs, res, mAutoCorrectEnabled);
|
||||||
mBigramPredictionEnabled = mBigramSuggestionEnabled
|
mBigramPredictionEnabled = mBigramSuggestionEnabled
|
||||||
&& isBigramPredictionEnabled(prefs, res);
|
&& isBigramPredictionEnabled(prefs, res);
|
||||||
mAutoCorrectionThreshold = getAutoCorrectionThreshold(prefs, res);
|
|
||||||
mUseContactsDict = prefs.getBoolean(Settings.PREF_KEY_USE_CONTACTS_DICT, true);
|
|
||||||
mEnableSuggestionSpanInsertion =
|
mEnableSuggestionSpanInsertion =
|
||||||
prefs.getBoolean(Settings.PREF_KEY_ENABLE_SPAN_INSERT, true);
|
prefs.getBoolean(Settings.PREF_KEY_ENABLE_SPAN_INSERT, true);
|
||||||
final boolean defaultShowSettingsKey = res.getBoolean(
|
|
||||||
R.bool.config_default_show_settings_key);
|
// Compute other readable settings
|
||||||
mShowSettingsKey = isShowSettingsKeyOption(res)
|
mKeyPreviewPopupDismissDelay = getKeyPreviewPopupDismissDelay(prefs, res);
|
||||||
? prefs.getBoolean(Settings.PREF_SHOW_SETTINGS_KEY, defaultShowSettingsKey)
|
mAutoCorrectionThreshold = getAutoCorrectionThreshold(prefs, res);
|
||||||
: defaultShowSettingsKey;
|
|
||||||
final String voiceModeMain = res.getString(R.string.voice_mode_main);
|
final String voiceModeMain = res.getString(R.string.voice_mode_main);
|
||||||
final String voiceModeOff = res.getString(R.string.voice_mode_off);
|
final String voiceModeOff = res.getString(R.string.voice_mode_off);
|
||||||
final String voiceMode = prefs.getString(Settings.PREF_VOICE_MODE, voiceModeMain);
|
final String voiceMode = prefs.getString(Settings.PREF_VOICE_MODE, voiceModeMain);
|
||||||
|
@ -153,6 +149,26 @@ public class SettingsValues {
|
||||||
return wordSeparators;
|
return wordSeparators;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isSettingsKeyShown(final SharedPreferences prefs, final Resources res) {
|
||||||
|
final boolean defaultShowSettingsKey = res.getBoolean(
|
||||||
|
R.bool.config_default_show_settings_key);
|
||||||
|
return isShowSettingsKeyOptionEnabled(res)
|
||||||
|
? prefs.getBoolean(Settings.PREF_SHOW_SETTINGS_KEY, defaultShowSettingsKey)
|
||||||
|
: defaultShowSettingsKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isShowSettingsKeyOptionEnabled(final Resources resources) {
|
||||||
|
// TODO: Read this once and for all into a public final member
|
||||||
|
return resources.getBoolean(R.bool.config_enable_show_settings_key_option);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isVibrateOn(final Context context, final SharedPreferences prefs,
|
||||||
|
final Resources res) {
|
||||||
|
final boolean hasVibrator = VibratorCompatWrapper.getInstance(context).hasVibrator();
|
||||||
|
return hasVibrator && prefs.getBoolean(Settings.PREF_VIBRATE_ON,
|
||||||
|
res.getBoolean(R.bool.config_default_vibration_enabled));
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isSuggestedPunctuation(int code) {
|
public boolean isSuggestedPunctuation(int code) {
|
||||||
return mSuggestPuncs.contains(String.valueOf((char)code));
|
return mSuggestPuncs.contains(String.valueOf((char)code));
|
||||||
}
|
}
|
||||||
|
@ -242,16 +258,11 @@ public class SettingsValues {
|
||||||
return autoCorrectionThreshold;
|
return autoCorrectionThreshold;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isShowSettingsKeyOption(final Resources resources) {
|
|
||||||
return resources.getBoolean(R.bool.config_enable_show_settings_key_option);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSettingsKeyEnabled() {
|
public boolean isSettingsKeyEnabled() {
|
||||||
return mShowSettingsKey;
|
return mShowSettingsKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isVoiceKeyEnabled(EditorInfo editorInfo) {
|
public boolean isVoiceKeyEnabled(final EditorInfo editorInfo) {
|
||||||
final boolean shortcutImeEnabled = SubtypeSwitcher.getInstance().isShortcutImeEnabled();
|
final boolean shortcutImeEnabled = SubtypeSwitcher.getInstance().isShortcutImeEnabled();
|
||||||
final int inputType = (editorInfo != null) ? editorInfo.inputType : 0;
|
final int inputType = (editorInfo != null) ? editorInfo.inputType : 0;
|
||||||
return shortcutImeEnabled && mVoiceKeyEnabled
|
return shortcutImeEnabled && mVoiceKeyEnabled
|
||||||
|
|
Loading…
Reference in New Issue