aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/Settings.java46
-rw-r--r--java/src/com/android/inputmethod/latin/SettingsFragment.java51
-rw-r--r--java/src/com/android/inputmethod/latin/SettingsValues.java26
3 files changed, 63 insertions, 60 deletions
diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java
index 49e19c272..02b44c7f6 100644
--- a/java/src/com/android/inputmethod/latin/Settings.java
+++ b/java/src/com/android/inputmethod/latin/Settings.java
@@ -126,13 +126,49 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
}
// Accessed from the settings interface, hence public
+ public static boolean readKeypressSoundEnabled(final SharedPreferences prefs,
+ final Resources res) {
+ return prefs.getBoolean(Settings.PREF_SOUND_ON,
+ res.getBoolean(R.bool.config_default_sound_enabled));
+ }
+
+ public static boolean readVibrationEnabled(final SharedPreferences prefs,
+ final Resources res) {
+ final boolean hasVibrator = AudioAndHapticFeedbackManager.getInstance().hasVibrator();
+ return hasVibrator && prefs.getBoolean(PREF_VIBRATE_ON,
+ res.getBoolean(R.bool.config_default_vibration_enabled));
+ }
+
+ public static boolean readAutoCorrectEnabled(final String currentAutoCorrectionSetting,
+ final Resources res) {
+ final String autoCorrectionOff = res.getString(
+ R.string.auto_correction_threshold_mode_index_off);
+ return !currentAutoCorrectionSetting.equals(autoCorrectionOff);
+ }
+
+ public static boolean readFromBuildConfigIfGestureInputEnabled(final Resources res) {
+ return res.getBoolean(R.bool.config_gesture_input_enabled_by_build_config);
+ }
+
+ public static boolean readGestureInputEnabled(final SharedPreferences prefs,
+ final Resources res) {
+ return readFromBuildConfigIfGestureInputEnabled(res)
+ && prefs.getBoolean(Settings.PREF_GESTURE_INPUT, true);
+ }
+
+ public static boolean readFromBuildConfigIfToShowKeyPreviewPopupSettingsOption(
+ final Resources res) {
+ return res.getBoolean(R.bool.config_enable_show_option_of_key_preview_popup);
+ }
+
public static boolean readKeyPreviewPopupEnabled(final SharedPreferences prefs,
final Resources res) {
- final boolean showPopupOption = res.getBoolean(
- R.bool.config_enable_show_popup_on_keypress_option);
- if (!showPopupOption) return res.getBoolean(R.bool.config_default_popup_preview);
- return prefs.getBoolean(PREF_POPUP_ON,
- res.getBoolean(R.bool.config_default_popup_preview));
+ final boolean defaultKeyPreviewPopup = res.getBoolean(
+ R.bool.config_default_key_preview_popup);
+ if (!readFromBuildConfigIfToShowKeyPreviewPopupSettingsOption(res)) {
+ return defaultKeyPreviewPopup;
+ }
+ return prefs.getBoolean(PREF_POPUP_ON, defaultKeyPreviewPopup);
}
public static int readKeyPreviewPopupDismissDelay(final SharedPreferences prefs,
diff --git a/java/src/com/android/inputmethod/latin/SettingsFragment.java b/java/src/com/android/inputmethod/latin/SettingsFragment.java
index f0c51e194..edd064c0b 100644
--- a/java/src/com/android/inputmethod/latin/SettingsFragment.java
+++ b/java/src/com/android/inputmethod/latin/SettingsFragment.java
@@ -114,23 +114,22 @@ public final class SettingsFragment extends InputMethodSettingsFragment
removePreference(Settings.PREF_VIBRATION_DURATION_SETTINGS, advancedSettings);
}
- final boolean showKeyPreviewPopupOption = res.getBoolean(
- R.bool.config_enable_show_popup_on_keypress_option);
mKeyPreviewPopupDismissDelay =
(ListPreference) findPreference(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
- if (!showKeyPreviewPopupOption) {
+ if (!Settings.readFromBuildConfigIfToShowKeyPreviewPopupSettingsOption(res)) {
removePreference(Settings.PREF_POPUP_ON, generalSettings);
removePreference(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY, advancedSettings);
} else {
- final String[] entries = new String[] {
- res.getString(R.string.key_preview_popup_dismiss_no_delay),
- res.getString(R.string.key_preview_popup_dismiss_default_delay),
- };
final String popupDismissDelayDefaultValue = Integer.toString(res.getInteger(
R.integer.config_key_preview_linger_timeout));
- mKeyPreviewPopupDismissDelay.setEntries(entries);
- mKeyPreviewPopupDismissDelay.setEntryValues(
- new String[] { "0", popupDismissDelayDefaultValue });
+ mKeyPreviewPopupDismissDelay.setEntries(new String[] {
+ res.getString(R.string.key_preview_popup_dismiss_no_delay),
+ res.getString(R.string.key_preview_popup_dismiss_default_delay),
+ });
+ mKeyPreviewPopupDismissDelay.setEntryValues(new String[] {
+ "0",
+ popupDismissDelayDefaultValue
+ });
if (null == mKeyPreviewPopupDismissDelay.getValue()) {
mKeyPreviewPopupDismissDelay.setValue(popupDismissDelayDefaultValue);
}
@@ -152,9 +151,7 @@ public final class SettingsFragment extends InputMethodSettingsFragment
textCorrectionGroup.removePreference(dictionaryLink);
}
- final boolean gestureInputEnabledByBuildConfig = res.getBoolean(
- R.bool.config_gesture_input_enabled_by_build_config);
- if (!gestureInputEnabledByBuildConfig) {
+ if (!Settings.readFromBuildConfigIfGestureInputEnabled(res)) {
removePreference(Settings.PREF_GESTURE_SETTINGS, getPreferenceScreen());
}
@@ -188,23 +185,17 @@ public final class SettingsFragment extends InputMethodSettingsFragment
@Override
public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
(new BackupManager(getActivity())).dataChanged();
+ final Resources res = getResources();
if (key.equals(Settings.PREF_POPUP_ON)) {
setPreferenceEnabled(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY,
- prefs.getBoolean(Settings.PREF_POPUP_ON, true));
+ Settings.readKeyPreviewPopupEnabled(prefs, res));
} else if (key.equals(Settings.PREF_SHOW_LANGUAGE_SWITCH_KEY)) {
setPreferenceEnabled(Settings.PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST,
Settings.readShowsLanguageSwitchKey(prefs));
} else if (key.equals(Settings.PREF_GESTURE_INPUT)) {
- final boolean gestureInputEnabledByConfig = getResources().getBoolean(
- R.bool.config_gesture_input_enabled_by_build_config);
- if (gestureInputEnabledByConfig) {
- final boolean gestureInputEnabledByUser = prefs.getBoolean(
- Settings.PREF_GESTURE_INPUT, true);
- setPreferenceEnabled(Settings.PREF_GESTURE_PREVIEW_TRAIL,
- gestureInputEnabledByUser);
- setPreferenceEnabled(Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT,
- gestureInputEnabledByUser);
- }
+ final boolean gestureInputEnabled = Settings.readGestureInputEnabled(prefs, res);
+ setPreferenceEnabled(Settings.PREF_GESTURE_PREVIEW_TRAIL, gestureInputEnabled);
+ setPreferenceEnabled(Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT, gestureInputEnabled);
}
ensureConsistencyOfAutoCorrectionSettings();
updateVoiceModeSummary();
@@ -258,16 +249,10 @@ public final class SettingsFragment extends InputMethodSettingsFragment
private void refreshEnablingsOfKeypressSoundAndVibrationSettings(
final SharedPreferences sp, final Resources res) {
- final boolean hasVibratorHardware =
- AudioAndHapticFeedbackManager.getInstance().hasVibrator();
- final boolean vibrateOnByUser = sp.getBoolean(Settings.PREF_VIBRATE_ON,
- res.getBoolean(R.bool.config_default_vibration_enabled));
setPreferenceEnabled(Settings.PREF_VIBRATION_DURATION_SETTINGS,
- hasVibratorHardware && vibrateOnByUser);
-
- final boolean soundOn = sp.getBoolean(Settings.PREF_SOUND_ON,
- res.getBoolean(R.bool.config_default_sound_enabled));
- setPreferenceEnabled(Settings.PREF_KEYPRESS_SOUND_VOLUME, soundOn);
+ Settings.readVibrationEnabled(sp, res));
+ setPreferenceEnabled(Settings.PREF_KEYPRESS_SOUND_VOLUME,
+ Settings.readKeypressSoundEnabled(sp, res));
}
private void setupKeypressVibrationDurationSettings(final SharedPreferences sp,
diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java
index f43382cb5..728f6b281 100644
--- a/java/src/com/android/inputmethod/latin/SettingsValues.java
+++ b/java/src/com/android/inputmethod/latin/SettingsValues.java
@@ -104,9 +104,8 @@ public final class SettingsValues {
// Get the settings preferences
mAutoCap = prefs.getBoolean(Settings.PREF_AUTO_CAP, true);
- mVibrateOn = readVibrationEnabled(prefs, res);
- mSoundOn = prefs.getBoolean(Settings.PREF_SOUND_ON,
- res.getBoolean(R.bool.config_default_sound_enabled));
+ mVibrateOn = Settings.readVibrationEnabled(prefs, res);
+ mSoundOn = Settings.readKeypressSoundEnabled(prefs, res);
mKeyPreviewPopupOn = Settings.readKeyPreviewPopupEnabled(prefs, res);
mSlidingKeyInputPreviewEnabled = prefs.getBoolean(
Settings.PREF_SLIDING_KEY_INPUT_PREVIEW, true);
@@ -121,7 +120,7 @@ public final class SettingsValues {
mShowsLanguageSwitchKey = Settings.readShowsLanguageSwitchKey(prefs);
mUseContactsDict = prefs.getBoolean(Settings.PREF_KEY_USE_CONTACTS_DICT, true);
mUseDoubleSpacePeriod = prefs.getBoolean(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true);
- mAutoCorrectEnabled = readAutoCorrectEnabled(res, autoCorrectionThresholdRawValue);
+ mAutoCorrectEnabled = Settings.readAutoCorrectEnabled(autoCorrectionThresholdRawValue, res);
mBigramPredictionEnabled = readBigramPredictionEnabled(prefs, res);
// Compute other readable settings
@@ -133,10 +132,7 @@ public final class SettingsValues {
autoCorrectionThresholdRawValue);
mVoiceKeyEnabled = mVoiceMode != null && !mVoiceMode.equals(voiceModeOff);
mVoiceKeyOnMain = mVoiceMode != null && mVoiceMode.equals(voiceModeMain);
- final boolean gestureInputEnabledByBuildConfig = res.getBoolean(
- R.bool.config_gesture_input_enabled_by_build_config);
- mGestureInputEnabled = gestureInputEnabledByBuildConfig
- && prefs.getBoolean(Settings.PREF_GESTURE_INPUT, true);
+ mGestureInputEnabled = Settings.readGestureInputEnabled(prefs, res);
mGesturePreviewTrailEnabled = prefs.getBoolean(Settings.PREF_GESTURE_PREVIEW_TRAIL, true);
mGestureFloatingPreviewTextEnabled = prefs.getBoolean(
Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT, true);
@@ -250,20 +246,6 @@ public final class SettingsValues {
throw new RuntimeException("Bug: visibility string is not configured correctly");
}
- private static boolean readVibrationEnabled(final SharedPreferences prefs,
- final Resources res) {
- final boolean hasVibrator = AudioAndHapticFeedbackManager.getInstance().hasVibrator();
- return hasVibrator && prefs.getBoolean(Settings.PREF_VIBRATE_ON,
- res.getBoolean(R.bool.config_default_vibration_enabled));
- }
-
- private static boolean readAutoCorrectEnabled(final Resources res,
- final String currentAutoCorrectionSetting) {
- final String autoCorrectionOff = res.getString(
- R.string.auto_correction_threshold_mode_index_off);
- return !currentAutoCorrectionSetting.equals(autoCorrectionOff);
- }
-
private static boolean readBigramPredictionEnabled(final SharedPreferences prefs,
final Resources res) {
return prefs.getBoolean(Settings.PREF_BIGRAM_PREDICTIONS, res.getBoolean(