Cleanup SettingsFragment
Change-Id: Ic7dac203c17b34e1555ba2c91e3f8c057e85a4b5
This commit is contained in:
parent
0e8dbe0284
commit
98dd81ab80
1 changed files with 35 additions and 71 deletions
|
@ -60,13 +60,6 @@ public final class SettingsFragment extends InputMethodSettingsFragment
|
||||||
DBG_USE_INTERNAL_PERSONAL_DICTIONARY_SETTINGS
|
DBG_USE_INTERNAL_PERSONAL_DICTIONARY_SETTINGS
|
||||||
|| Build.VERSION.SDK_INT <= 18 /* Build.VERSION.JELLY_BEAN_MR2 */;
|
|| Build.VERSION.SDK_INT <= 18 /* Build.VERSION.JELLY_BEAN_MR2 */;
|
||||||
|
|
||||||
private CheckBoxPreference mVoiceInputKeyPreference;
|
|
||||||
private ListPreference mShowCorrectionSuggestionsPreference;
|
|
||||||
private ListPreference mAutoCorrectionThresholdPreference;
|
|
||||||
private ListPreference mKeyPreviewPopupDismissDelay;
|
|
||||||
// Use bigrams to predict the next word when there is no input for it yet
|
|
||||||
private CheckBoxPreference mBigramPrediction;
|
|
||||||
|
|
||||||
private void setPreferenceEnabled(final String preferenceKey, final boolean enabled) {
|
private void setPreferenceEnabled(final String preferenceKey, final boolean enabled) {
|
||||||
final Preference preference = findPreference(preferenceKey);
|
final Preference preference = findPreference(preferenceKey);
|
||||||
if (preference != null) {
|
if (preference != null) {
|
||||||
|
@ -74,6 +67,15 @@ public final class SettingsFragment extends InputMethodSettingsFragment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateListPreferenceSummaryToCurrentValue(final String prefKey) {
|
||||||
|
// Because the "%s" summary trick of {@link ListPreference} doesn't work properly before
|
||||||
|
// KitKat, we need to update the summary programmatically.
|
||||||
|
final ListPreference listPreference = (ListPreference)findPreference(prefKey);
|
||||||
|
final CharSequence entries[] = listPreference.getEntries();
|
||||||
|
final int entryIndex = listPreference.findIndexOfValue(listPreference.getValue());
|
||||||
|
listPreference.setSummary(entries[entryIndex]);
|
||||||
|
}
|
||||||
|
|
||||||
private static void removePreference(final String preferenceKey, final PreferenceGroup parent) {
|
private static void removePreference(final String preferenceKey, final PreferenceGroup parent) {
|
||||||
if (parent == null) {
|
if (parent == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -106,16 +108,9 @@ public final class SettingsFragment extends InputMethodSettingsFragment
|
||||||
SubtypeLocaleUtils.init(context);
|
SubtypeLocaleUtils.init(context);
|
||||||
AudioAndHapticFeedbackManager.init(context);
|
AudioAndHapticFeedbackManager.init(context);
|
||||||
|
|
||||||
mVoiceInputKeyPreference =
|
|
||||||
(CheckBoxPreference) findPreference(Settings.PREF_VOICE_INPUT_KEY);
|
|
||||||
mShowCorrectionSuggestionsPreference =
|
|
||||||
(ListPreference) findPreference(Settings.PREF_SHOW_SUGGESTIONS_SETTING);
|
|
||||||
final SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
|
final SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
|
||||||
prefs.registerOnSharedPreferenceChangeListener(this);
|
prefs.registerOnSharedPreferenceChangeListener(this);
|
||||||
|
|
||||||
mAutoCorrectionThresholdPreference =
|
|
||||||
(ListPreference) findPreference(Settings.PREF_AUTO_CORRECTION_THRESHOLD);
|
|
||||||
mBigramPrediction = (CheckBoxPreference) findPreference(Settings.PREF_BIGRAM_PREDICTIONS);
|
|
||||||
ensureConsistencyOfAutoCorrectionSettings();
|
ensureConsistencyOfAutoCorrectionSettings();
|
||||||
|
|
||||||
final PreferenceGroup generalSettings =
|
final PreferenceGroup generalSettings =
|
||||||
|
@ -161,7 +156,7 @@ public final class SettingsFragment extends InputMethodSettingsFragment
|
||||||
final boolean showVoiceKeyOption = res.getBoolean(
|
final boolean showVoiceKeyOption = res.getBoolean(
|
||||||
R.bool.config_enable_show_voice_key_option);
|
R.bool.config_enable_show_voice_key_option);
|
||||||
if (!showVoiceKeyOption) {
|
if (!showVoiceKeyOption) {
|
||||||
generalSettings.removePreference(mVoiceInputKeyPreference);
|
removePreference(Settings.PREF_VOICE_INPUT_KEY, generalSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
final PreferenceGroup advancedSettings =
|
final PreferenceGroup advancedSettings =
|
||||||
|
@ -171,26 +166,27 @@ public final class SettingsFragment extends InputMethodSettingsFragment
|
||||||
removePreference(Settings.PREF_VIBRATION_DURATION_SETTINGS, advancedSettings);
|
removePreference(Settings.PREF_VIBRATION_DURATION_SETTINGS, advancedSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
mKeyPreviewPopupDismissDelay =
|
|
||||||
(ListPreference) findPreference(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
|
|
||||||
if (!Settings.readFromBuildConfigIfToShowKeyPreviewPopupSettingsOption(res)) {
|
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 {
|
||||||
|
// TODO: Cleanup this setup.
|
||||||
|
final ListPreference keyPreviewPopupDismissDelay =
|
||||||
|
(ListPreference) findPreference(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_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(new String[] {
|
keyPreviewPopupDismissDelay.setEntries(new String[] {
|
||||||
res.getString(R.string.key_preview_popup_dismiss_no_delay),
|
res.getString(R.string.key_preview_popup_dismiss_no_delay),
|
||||||
res.getString(R.string.key_preview_popup_dismiss_default_delay),
|
res.getString(R.string.key_preview_popup_dismiss_default_delay),
|
||||||
});
|
});
|
||||||
mKeyPreviewPopupDismissDelay.setEntryValues(new String[] {
|
keyPreviewPopupDismissDelay.setEntryValues(new String[] {
|
||||||
"0",
|
"0",
|
||||||
popupDismissDelayDefaultValue
|
popupDismissDelayDefaultValue
|
||||||
});
|
});
|
||||||
if (null == mKeyPreviewPopupDismissDelay.getValue()) {
|
if (null == keyPreviewPopupDismissDelay.getValue()) {
|
||||||
mKeyPreviewPopupDismissDelay.setValue(popupDismissDelayDefaultValue);
|
keyPreviewPopupDismissDelay.setValue(popupDismissDelayDefaultValue);
|
||||||
}
|
}
|
||||||
mKeyPreviewPopupDismissDelay.setEnabled(
|
keyPreviewPopupDismissDelay.setEnabled(
|
||||||
Settings.readKeyPreviewPopupEnabled(prefs, res));
|
Settings.readKeyPreviewPopupEnabled(prefs, res));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,20 +233,19 @@ public final class SettingsFragment extends InputMethodSettingsFragment
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
final boolean isShortcutImeEnabled = SubtypeSwitcher.getInstance().isShortcutImeEnabled();
|
|
||||||
if (!isShortcutImeEnabled) {
|
|
||||||
getPreferenceScreen().removePreference(mVoiceInputKeyPreference);
|
|
||||||
}
|
|
||||||
final SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
|
final SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
|
||||||
|
final Resources res = getResources();
|
||||||
|
final boolean isShortcutImeEnabled = SubtypeSwitcher.getInstance().isShortcutImeEnabled();
|
||||||
|
setPreferenceEnabled(Settings.PREF_VOICE_INPUT_KEY, isShortcutImeEnabled);
|
||||||
final CheckBoxPreference showSetupWizardIcon =
|
final CheckBoxPreference showSetupWizardIcon =
|
||||||
(CheckBoxPreference)findPreference(Settings.PREF_SHOW_SETUP_WIZARD_ICON);
|
(CheckBoxPreference)findPreference(Settings.PREF_SHOW_SETUP_WIZARD_ICON);
|
||||||
if (showSetupWizardIcon != null) {
|
if (showSetupWizardIcon != null) {
|
||||||
showSetupWizardIcon.setChecked(Settings.readShowSetupWizardIcon(prefs, getActivity()));
|
showSetupWizardIcon.setChecked(Settings.readShowSetupWizardIcon(prefs, getActivity()));
|
||||||
}
|
}
|
||||||
updateShowCorrectionSuggestionsSummary();
|
updateListPreferenceSummaryToCurrentValue(Settings.PREF_SHOW_SUGGESTIONS_SETTING);
|
||||||
updateKeyPreviewPopupDelaySummary();
|
updateListPreferenceSummaryToCurrentValue(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
|
||||||
updateColorSchemeSummary(prefs, getResources());
|
updateListPreferenceSummaryToCurrentValue(Settings.PREF_KEYBOARD_LAYOUT);
|
||||||
updateCustomInputStylesSummary();
|
updateCustomInputStylesSummary(prefs, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -281,50 +276,26 @@ public final class SettingsFragment extends InputMethodSettingsFragment
|
||||||
LauncherIconVisibilityManager.updateSetupWizardIconVisibility(getActivity());
|
LauncherIconVisibilityManager.updateSetupWizardIconVisibility(getActivity());
|
||||||
}
|
}
|
||||||
ensureConsistencyOfAutoCorrectionSettings();
|
ensureConsistencyOfAutoCorrectionSettings();
|
||||||
updateShowCorrectionSuggestionsSummary();
|
updateListPreferenceSummaryToCurrentValue(Settings.PREF_SHOW_SUGGESTIONS_SETTING);
|
||||||
updateKeyPreviewPopupDelaySummary();
|
updateListPreferenceSummaryToCurrentValue(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
|
||||||
updateColorSchemeSummary(prefs, res);
|
updateListPreferenceSummaryToCurrentValue(Settings.PREF_KEYBOARD_LAYOUT);
|
||||||
refreshEnablingsOfKeypressSoundAndVibrationSettings(prefs, getResources());
|
refreshEnablingsOfKeypressSoundAndVibrationSettings(prefs, getResources());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ensureConsistencyOfAutoCorrectionSettings() {
|
private void ensureConsistencyOfAutoCorrectionSettings() {
|
||||||
final String autoCorrectionOff = getResources().getString(
|
final String autoCorrectionOff = getResources().getString(
|
||||||
R.string.auto_correction_threshold_mode_index_off);
|
R.string.auto_correction_threshold_mode_index_off);
|
||||||
final String currentSetting = mAutoCorrectionThresholdPreference.getValue();
|
final ListPreference autoCorrectionThresholdPref = (ListPreference)findPreference(
|
||||||
mBigramPrediction.setEnabled(!currentSetting.equals(autoCorrectionOff));
|
Settings.PREF_AUTO_CORRECTION_THRESHOLD);
|
||||||
|
final String currentSetting = autoCorrectionThresholdPref.getValue();
|
||||||
|
setPreferenceEnabled(
|
||||||
|
Settings.PREF_BIGRAM_PREDICTIONS, !currentSetting.equals(autoCorrectionOff));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateShowCorrectionSuggestionsSummary() {
|
private void updateCustomInputStylesSummary(final SharedPreferences prefs,
|
||||||
mShowCorrectionSuggestionsPreference.setSummary(
|
final Resources res) {
|
||||||
getResources().getStringArray(R.array.prefs_suggestion_visibilities)
|
|
||||||
[mShowCorrectionSuggestionsPreference.findIndexOfValue(
|
|
||||||
mShowCorrectionSuggestionsPreference.getValue())]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateColorSchemeSummary(final SharedPreferences prefs, final Resources res) {
|
|
||||||
// Because the "%s" summary trick of {@link ListPreference} doesn't work properly before
|
|
||||||
// KitKat, we need to update the summary by code.
|
|
||||||
final Preference preference = findPreference(Settings.PREF_KEYBOARD_LAYOUT);
|
|
||||||
if (!(preference instanceof ListPreference)) {
|
|
||||||
Log.w(TAG, "Can't find Keyboard Color Scheme preference");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final ListPreference colorSchemePreference = (ListPreference)preference;
|
|
||||||
final int themeIndex = Settings.readKeyboardThemeIndex(prefs, res);
|
|
||||||
int entryIndex = colorSchemePreference.findIndexOfValue(Integer.toString(themeIndex));
|
|
||||||
if (entryIndex < 0) {
|
|
||||||
final int defaultThemeIndex = Settings.resetAndGetDefaultKeyboardThemeIndex(prefs, res);
|
|
||||||
entryIndex = colorSchemePreference.findIndexOfValue(
|
|
||||||
Integer.toString(defaultThemeIndex));
|
|
||||||
}
|
|
||||||
colorSchemePreference.setSummary(colorSchemePreference.getEntries()[entryIndex]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateCustomInputStylesSummary() {
|
|
||||||
final PreferenceScreen customInputStyles =
|
final PreferenceScreen customInputStyles =
|
||||||
(PreferenceScreen)findPreference(Settings.PREF_CUSTOM_INPUT_STYLES);
|
(PreferenceScreen)findPreference(Settings.PREF_CUSTOM_INPUT_STYLES);
|
||||||
final SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
|
|
||||||
final Resources res = getResources();
|
|
||||||
final String prefSubtype = Settings.readPrefAdditionalSubtypes(prefs, res);
|
final String prefSubtype = Settings.readPrefAdditionalSubtypes(prefs, res);
|
||||||
final InputMethodSubtype[] subtypes =
|
final InputMethodSubtype[] subtypes =
|
||||||
AdditionalSubtypeUtils.createAdditionalSubtypesArray(prefSubtype);
|
AdditionalSubtypeUtils.createAdditionalSubtypesArray(prefSubtype);
|
||||||
|
@ -336,13 +307,6 @@ public final class SettingsFragment extends InputMethodSettingsFragment
|
||||||
customInputStyles.setSummary(styles);
|
customInputStyles.setSummary(styles);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateKeyPreviewPopupDelaySummary() {
|
|
||||||
final ListPreference lp = mKeyPreviewPopupDismissDelay;
|
|
||||||
final CharSequence[] entries = lp.getEntries();
|
|
||||||
if (entries == null || entries.length <= 0) return;
|
|
||||||
lp.setSummary(entries[lp.findIndexOfValue(lp.getValue())]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void refreshEnablingsOfKeypressSoundAndVibrationSettings(
|
private void refreshEnablingsOfKeypressSoundAndVibrationSettings(
|
||||||
final SharedPreferences sp, final Resources res) {
|
final SharedPreferences sp, final Resources res) {
|
||||||
setPreferenceEnabled(Settings.PREF_VIBRATION_DURATION_SETTINGS,
|
setPreferenceEnabled(Settings.PREF_VIBRATION_DURATION_SETTINGS,
|
||||||
|
|
Loading…
Reference in a new issue