mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Clean up Settings and SettingsFragment a bit
Change-Id: I93bf3cb1ea7e8fc09f4ad34b0bdd74f5f5ff1a68
This commit is contained in:
parent
20b6775acc
commit
ce875664e0
@ -22,10 +22,10 @@
|
||||
<!-- Device form factor. This value must be aligned with {@link KeyboardId.FORM_FACTOR_TABLET7} -->
|
||||
<integer name="config_device_form_factor">1</integer>
|
||||
<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>
|
||||
<!-- 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_auto_correction_spacebar_led_enabled">false</bool>
|
||||
<!-- 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} -->
|
||||
<integer name="config_device_form_factor">2</integer>
|
||||
<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>
|
||||
<!-- 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_auto_correction_spacebar_led_enabled">false</bool>
|
||||
<!-- This configuration is the index of the array {@link KeyboardSwitcher.KEYBOARD_THEMES}. -->
|
||||
|
@ -23,11 +23,11 @@
|
||||
<integer name="config_device_form_factor">0</integer>
|
||||
<bool name="config_use_fullscreen_mode">false</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. -->
|
||||
<bool name="config_enable_usability_study_mode_option">true</bool>
|
||||
<!-- 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
|
||||
at input history to suggest a hopefully helpful suggestions for the next word? -->
|
||||
<bool name="config_default_next_word_prediction">true</bool>
|
||||
|
@ -42,7 +42,7 @@
|
||||
android:key="popup_on"
|
||||
android:title="@string/popup_on_keypress"
|
||||
android:persistent="true"
|
||||
android:defaultValue="@bool/config_default_popup_preview" />
|
||||
android:defaultValue="@bool/config_default_key_preview_popup" />
|
||||
<ListPreference
|
||||
android:key="voice_mode"
|
||||
android:title="@string/voice_input"
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user