Clean up Settings and SettingsFragment a bit
Change-Id: I93bf3cb1ea7e8fc09f4ad34b0bdd74f5f5ff1a68main
parent
20b6775acc
commit
ce875664e0
|
@ -22,10 +22,10 @@
|
||||||
<!-- Device form factor. This value must be aligned with {@link KeyboardId.FORM_FACTOR_TABLET7} -->
|
<!-- Device form factor. This value must be aligned with {@link KeyboardId.FORM_FACTOR_TABLET7} -->
|
||||||
<integer name="config_device_form_factor">1</integer>
|
<integer name="config_device_form_factor">1</integer>
|
||||||
<bool name="config_enable_show_voice_key_option">false</bool>
|
<bool name="config_enable_show_voice_key_option">false</bool>
|
||||||
<bool name="config_enable_show_popup_on_keypress_option">false</bool>
|
<bool name="config_enable_show_option_of_key_preview_popup">false</bool>
|
||||||
<bool name="config_enable_bigram_suggestions_option">false</bool>
|
<bool name="config_enable_bigram_suggestions_option">false</bool>
|
||||||
<!-- Whether or not Popup on key press is enabled by default -->
|
<!-- Whether or not Popup on key press is enabled by default -->
|
||||||
<bool name="config_default_popup_preview">false</bool>
|
<bool name="config_default_key_preview_popup">false</bool>
|
||||||
<bool name="config_default_sound_enabled">true</bool>
|
<bool name="config_default_sound_enabled">true</bool>
|
||||||
<bool name="config_auto_correction_spacebar_led_enabled">false</bool>
|
<bool name="config_auto_correction_spacebar_led_enabled">false</bool>
|
||||||
<!-- The language is never displayed if == 0, always displayed if < 0 -->
|
<!-- The language is never displayed if == 0, always displayed if < 0 -->
|
||||||
|
|
|
@ -22,10 +22,10 @@
|
||||||
<!-- Device form factor. This value must be aligned with {@link KeyboardId.FORM_FACTOR_TABLET10} -->
|
<!-- Device form factor. This value must be aligned with {@link KeyboardId.FORM_FACTOR_TABLET10} -->
|
||||||
<integer name="config_device_form_factor">2</integer>
|
<integer name="config_device_form_factor">2</integer>
|
||||||
<bool name="config_enable_show_voice_key_option">false</bool>
|
<bool name="config_enable_show_voice_key_option">false</bool>
|
||||||
<bool name="config_enable_show_popup_on_keypress_option">false</bool>
|
<bool name="config_enable_show_option_of_key_preview_popup">false</bool>
|
||||||
<bool name="config_enable_bigram_suggestions_option">false</bool>
|
<bool name="config_enable_bigram_suggestions_option">false</bool>
|
||||||
<!-- Whether or not Popup on key press is enabled by default -->
|
<!-- Whether or not Popup on key press is enabled by default -->
|
||||||
<bool name="config_default_popup_preview">false</bool>
|
<bool name="config_default_key_preview_popup">false</bool>
|
||||||
<bool name="config_default_sound_enabled">true</bool>
|
<bool name="config_default_sound_enabled">true</bool>
|
||||||
<bool name="config_auto_correction_spacebar_led_enabled">false</bool>
|
<bool name="config_auto_correction_spacebar_led_enabled">false</bool>
|
||||||
<!-- This configuration is the index of the array {@link KeyboardSwitcher.KEYBOARD_THEMES}. -->
|
<!-- This configuration is the index of the array {@link KeyboardSwitcher.KEYBOARD_THEMES}. -->
|
||||||
|
|
|
@ -23,11 +23,11 @@
|
||||||
<integer name="config_device_form_factor">0</integer>
|
<integer name="config_device_form_factor">0</integer>
|
||||||
<bool name="config_use_fullscreen_mode">false</bool>
|
<bool name="config_use_fullscreen_mode">false</bool>
|
||||||
<bool name="config_enable_show_voice_key_option">true</bool>
|
<bool name="config_enable_show_voice_key_option">true</bool>
|
||||||
<bool name="config_enable_show_popup_on_keypress_option">true</bool>
|
<bool name="config_enable_show_option_of_key_preview_popup">true</bool>
|
||||||
<!-- TODO: Disable the following configuration for production. -->
|
<!-- TODO: Disable the following configuration for production. -->
|
||||||
<bool name="config_enable_usability_study_mode_option">true</bool>
|
<bool name="config_enable_usability_study_mode_option">true</bool>
|
||||||
<!-- Whether or not Popup on key press is enabled by default -->
|
<!-- Whether or not Popup on key press is enabled by default -->
|
||||||
<bool name="config_default_popup_preview">true</bool>
|
<bool name="config_default_key_preview_popup">true</bool>
|
||||||
<!-- Default value for next word prediction: after entering a word and a space only, should we look
|
<!-- Default value for next word prediction: after entering a word and a space only, should we look
|
||||||
at input history to suggest a hopefully helpful suggestions for the next word? -->
|
at input history to suggest a hopefully helpful suggestions for the next word? -->
|
||||||
<bool name="config_default_next_word_prediction">true</bool>
|
<bool name="config_default_next_word_prediction">true</bool>
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
android:key="popup_on"
|
android:key="popup_on"
|
||||||
android:title="@string/popup_on_keypress"
|
android:title="@string/popup_on_keypress"
|
||||||
android:persistent="true"
|
android:persistent="true"
|
||||||
android:defaultValue="@bool/config_default_popup_preview" />
|
android:defaultValue="@bool/config_default_key_preview_popup" />
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:key="voice_mode"
|
android:key="voice_mode"
|
||||||
android:title="@string/voice_input"
|
android:title="@string/voice_input"
|
||||||
|
|
|
@ -126,13 +126,49 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
|
||||||
}
|
}
|
||||||
|
|
||||||
// Accessed from the settings interface, hence public
|
// 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,
|
public static boolean readKeyPreviewPopupEnabled(final SharedPreferences prefs,
|
||||||
final Resources res) {
|
final Resources res) {
|
||||||
final boolean showPopupOption = res.getBoolean(
|
final boolean defaultKeyPreviewPopup = res.getBoolean(
|
||||||
R.bool.config_enable_show_popup_on_keypress_option);
|
R.bool.config_default_key_preview_popup);
|
||||||
if (!showPopupOption) return res.getBoolean(R.bool.config_default_popup_preview);
|
if (!readFromBuildConfigIfToShowKeyPreviewPopupSettingsOption(res)) {
|
||||||
return prefs.getBoolean(PREF_POPUP_ON,
|
return defaultKeyPreviewPopup;
|
||||||
res.getBoolean(R.bool.config_default_popup_preview));
|
}
|
||||||
|
return prefs.getBoolean(PREF_POPUP_ON, defaultKeyPreviewPopup);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int readKeyPreviewPopupDismissDelay(final SharedPreferences prefs,
|
public static int readKeyPreviewPopupDismissDelay(final SharedPreferences prefs,
|
||||||
|
|
|
@ -114,23 +114,22 @@ public final class SettingsFragment extends InputMethodSettingsFragment
|
||||||
removePreference(Settings.PREF_VIBRATION_DURATION_SETTINGS, advancedSettings);
|
removePreference(Settings.PREF_VIBRATION_DURATION_SETTINGS, advancedSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean showKeyPreviewPopupOption = res.getBoolean(
|
|
||||||
R.bool.config_enable_show_popup_on_keypress_option);
|
|
||||||
mKeyPreviewPopupDismissDelay =
|
mKeyPreviewPopupDismissDelay =
|
||||||
(ListPreference) findPreference(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
|
(ListPreference) findPreference(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
|
||||||
if (!showKeyPreviewPopupOption) {
|
if (!Settings.readFromBuildConfigIfToShowKeyPreviewPopupSettingsOption(res)) {
|
||||||
removePreference(Settings.PREF_POPUP_ON, generalSettings);
|
removePreference(Settings.PREF_POPUP_ON, generalSettings);
|
||||||
removePreference(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY, advancedSettings);
|
removePreference(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY, advancedSettings);
|
||||||
} else {
|
} 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(
|
final String popupDismissDelayDefaultValue = Integer.toString(res.getInteger(
|
||||||
R.integer.config_key_preview_linger_timeout));
|
R.integer.config_key_preview_linger_timeout));
|
||||||
mKeyPreviewPopupDismissDelay.setEntries(entries);
|
mKeyPreviewPopupDismissDelay.setEntries(new String[] {
|
||||||
mKeyPreviewPopupDismissDelay.setEntryValues(
|
res.getString(R.string.key_preview_popup_dismiss_no_delay),
|
||||||
new String[] { "0", popupDismissDelayDefaultValue });
|
res.getString(R.string.key_preview_popup_dismiss_default_delay),
|
||||||
|
});
|
||||||
|
mKeyPreviewPopupDismissDelay.setEntryValues(new String[] {
|
||||||
|
"0",
|
||||||
|
popupDismissDelayDefaultValue
|
||||||
|
});
|
||||||
if (null == mKeyPreviewPopupDismissDelay.getValue()) {
|
if (null == mKeyPreviewPopupDismissDelay.getValue()) {
|
||||||
mKeyPreviewPopupDismissDelay.setValue(popupDismissDelayDefaultValue);
|
mKeyPreviewPopupDismissDelay.setValue(popupDismissDelayDefaultValue);
|
||||||
}
|
}
|
||||||
|
@ -152,9 +151,7 @@ public final class SettingsFragment extends InputMethodSettingsFragment
|
||||||
textCorrectionGroup.removePreference(dictionaryLink);
|
textCorrectionGroup.removePreference(dictionaryLink);
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean gestureInputEnabledByBuildConfig = res.getBoolean(
|
if (!Settings.readFromBuildConfigIfGestureInputEnabled(res)) {
|
||||||
R.bool.config_gesture_input_enabled_by_build_config);
|
|
||||||
if (!gestureInputEnabledByBuildConfig) {
|
|
||||||
removePreference(Settings.PREF_GESTURE_SETTINGS, getPreferenceScreen());
|
removePreference(Settings.PREF_GESTURE_SETTINGS, getPreferenceScreen());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,23 +185,17 @@ public final class SettingsFragment extends InputMethodSettingsFragment
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
|
public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
|
||||||
(new BackupManager(getActivity())).dataChanged();
|
(new BackupManager(getActivity())).dataChanged();
|
||||||
|
final Resources res = getResources();
|
||||||
if (key.equals(Settings.PREF_POPUP_ON)) {
|
if (key.equals(Settings.PREF_POPUP_ON)) {
|
||||||
setPreferenceEnabled(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY,
|
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)) {
|
} else if (key.equals(Settings.PREF_SHOW_LANGUAGE_SWITCH_KEY)) {
|
||||||
setPreferenceEnabled(Settings.PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST,
|
setPreferenceEnabled(Settings.PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST,
|
||||||
Settings.readShowsLanguageSwitchKey(prefs));
|
Settings.readShowsLanguageSwitchKey(prefs));
|
||||||
} else if (key.equals(Settings.PREF_GESTURE_INPUT)) {
|
} else if (key.equals(Settings.PREF_GESTURE_INPUT)) {
|
||||||
final boolean gestureInputEnabledByConfig = getResources().getBoolean(
|
final boolean gestureInputEnabled = Settings.readGestureInputEnabled(prefs, res);
|
||||||
R.bool.config_gesture_input_enabled_by_build_config);
|
setPreferenceEnabled(Settings.PREF_GESTURE_PREVIEW_TRAIL, gestureInputEnabled);
|
||||||
if (gestureInputEnabledByConfig) {
|
setPreferenceEnabled(Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT, gestureInputEnabled);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ensureConsistencyOfAutoCorrectionSettings();
|
ensureConsistencyOfAutoCorrectionSettings();
|
||||||
updateVoiceModeSummary();
|
updateVoiceModeSummary();
|
||||||
|
@ -258,16 +249,10 @@ public final class SettingsFragment extends InputMethodSettingsFragment
|
||||||
|
|
||||||
private void refreshEnablingsOfKeypressSoundAndVibrationSettings(
|
private void refreshEnablingsOfKeypressSoundAndVibrationSettings(
|
||||||
final SharedPreferences sp, final Resources res) {
|
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,
|
setPreferenceEnabled(Settings.PREF_VIBRATION_DURATION_SETTINGS,
|
||||||
hasVibratorHardware && vibrateOnByUser);
|
Settings.readVibrationEnabled(sp, res));
|
||||||
|
setPreferenceEnabled(Settings.PREF_KEYPRESS_SOUND_VOLUME,
|
||||||
final boolean soundOn = sp.getBoolean(Settings.PREF_SOUND_ON,
|
Settings.readKeypressSoundEnabled(sp, res));
|
||||||
res.getBoolean(R.bool.config_default_sound_enabled));
|
|
||||||
setPreferenceEnabled(Settings.PREF_KEYPRESS_SOUND_VOLUME, soundOn);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupKeypressVibrationDurationSettings(final SharedPreferences sp,
|
private void setupKeypressVibrationDurationSettings(final SharedPreferences sp,
|
||||||
|
|
|
@ -104,9 +104,8 @@ public final class SettingsValues {
|
||||||
|
|
||||||
// Get the settings preferences
|
// Get the settings preferences
|
||||||
mAutoCap = prefs.getBoolean(Settings.PREF_AUTO_CAP, true);
|
mAutoCap = prefs.getBoolean(Settings.PREF_AUTO_CAP, true);
|
||||||
mVibrateOn = readVibrationEnabled(prefs, res);
|
mVibrateOn = Settings.readVibrationEnabled(prefs, res);
|
||||||
mSoundOn = prefs.getBoolean(Settings.PREF_SOUND_ON,
|
mSoundOn = Settings.readKeypressSoundEnabled(prefs, res);
|
||||||
res.getBoolean(R.bool.config_default_sound_enabled));
|
|
||||||
mKeyPreviewPopupOn = Settings.readKeyPreviewPopupEnabled(prefs, res);
|
mKeyPreviewPopupOn = Settings.readKeyPreviewPopupEnabled(prefs, res);
|
||||||
mSlidingKeyInputPreviewEnabled = prefs.getBoolean(
|
mSlidingKeyInputPreviewEnabled = prefs.getBoolean(
|
||||||
Settings.PREF_SLIDING_KEY_INPUT_PREVIEW, true);
|
Settings.PREF_SLIDING_KEY_INPUT_PREVIEW, true);
|
||||||
|
@ -121,7 +120,7 @@ public final class SettingsValues {
|
||||||
mShowsLanguageSwitchKey = Settings.readShowsLanguageSwitchKey(prefs);
|
mShowsLanguageSwitchKey = Settings.readShowsLanguageSwitchKey(prefs);
|
||||||
mUseContactsDict = prefs.getBoolean(Settings.PREF_KEY_USE_CONTACTS_DICT, true);
|
mUseContactsDict = prefs.getBoolean(Settings.PREF_KEY_USE_CONTACTS_DICT, true);
|
||||||
mUseDoubleSpacePeriod = prefs.getBoolean(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, 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);
|
mBigramPredictionEnabled = readBigramPredictionEnabled(prefs, res);
|
||||||
|
|
||||||
// Compute other readable settings
|
// Compute other readable settings
|
||||||
|
@ -133,10 +132,7 @@ public final class SettingsValues {
|
||||||
autoCorrectionThresholdRawValue);
|
autoCorrectionThresholdRawValue);
|
||||||
mVoiceKeyEnabled = mVoiceMode != null && !mVoiceMode.equals(voiceModeOff);
|
mVoiceKeyEnabled = mVoiceMode != null && !mVoiceMode.equals(voiceModeOff);
|
||||||
mVoiceKeyOnMain = mVoiceMode != null && mVoiceMode.equals(voiceModeMain);
|
mVoiceKeyOnMain = mVoiceMode != null && mVoiceMode.equals(voiceModeMain);
|
||||||
final boolean gestureInputEnabledByBuildConfig = res.getBoolean(
|
mGestureInputEnabled = Settings.readGestureInputEnabled(prefs, res);
|
||||||
R.bool.config_gesture_input_enabled_by_build_config);
|
|
||||||
mGestureInputEnabled = gestureInputEnabledByBuildConfig
|
|
||||||
&& prefs.getBoolean(Settings.PREF_GESTURE_INPUT, true);
|
|
||||||
mGesturePreviewTrailEnabled = prefs.getBoolean(Settings.PREF_GESTURE_PREVIEW_TRAIL, true);
|
mGesturePreviewTrailEnabled = prefs.getBoolean(Settings.PREF_GESTURE_PREVIEW_TRAIL, true);
|
||||||
mGestureFloatingPreviewTextEnabled = prefs.getBoolean(
|
mGestureFloatingPreviewTextEnabled = prefs.getBoolean(
|
||||||
Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT, true);
|
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");
|
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,
|
private static boolean readBigramPredictionEnabled(final SharedPreferences prefs,
|
||||||
final Resources res) {
|
final Resources res) {
|
||||||
return prefs.getBoolean(Settings.PREF_BIGRAM_PREDICTIONS, res.getBoolean(
|
return prefs.getBoolean(Settings.PREF_BIGRAM_PREDICTIONS, res.getBoolean(
|
||||||
|
|
Loading…
Reference in New Issue