Merge "Clean up SettingsFragment a bit"

This commit is contained in:
Tadashi G. Takaoka 2013-01-24 08:46:23 +00:00 committed by Android (Google) Code Review
commit 0f1ccbff17

View file

@ -41,7 +41,6 @@ public final class SettingsFragment extends InputMethodSettingsFragment
private ListPreference mKeyPreviewPopupDismissDelay; private ListPreference mKeyPreviewPopupDismissDelay;
// Use bigrams to predict the next word when there is no input for it yet // Use bigrams to predict the next word when there is no input for it yet
private CheckBoxPreference mBigramPrediction; private CheckBoxPreference mBigramPrediction;
private Preference mDebugSettingsPreference;
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);
@ -50,11 +49,14 @@ public final class SettingsFragment extends InputMethodSettingsFragment
} }
} }
private void ensureConsistencyOfAutoCorrectionSettings() { private static void removePreference(final String preferenceKey, final PreferenceGroup parent) {
final String autoCorrectionOff = getResources().getString( if (parent == null) {
R.string.auto_correction_threshold_mode_index_off); return;
final String currentSetting = mAutoCorrectionThresholdPreference.getValue(); }
mBigramPrediction.setEnabled(!currentSetting.equals(autoCorrectionOff)); final Preference preference = parent.findPreference(preferenceKey);
if (preference != null) {
parent.removePreference(preference);
}
} }
@Override @Override
@ -84,22 +86,18 @@ public final class SettingsFragment extends InputMethodSettingsFragment
final PreferenceGroup generalSettings = final PreferenceGroup generalSettings =
(PreferenceGroup) findPreference(Settings.PREF_GENERAL_SETTINGS); (PreferenceGroup) findPreference(Settings.PREF_GENERAL_SETTINGS);
final PreferenceGroup textCorrectionGroup =
(PreferenceGroup) findPreference(Settings.PREF_CORRECTION_SETTINGS);
final PreferenceGroup gestureTypingSettings =
(PreferenceGroup) findPreference(Settings.PREF_GESTURE_SETTINGS);
final PreferenceGroup miscSettings = final PreferenceGroup miscSettings =
(PreferenceGroup) findPreference(Settings.PREF_MISC_SETTINGS); (PreferenceGroup) findPreference(Settings.PREF_MISC_SETTINGS);
mDebugSettingsPreference = findPreference(Settings.PREF_DEBUG_SETTINGS); final Preference debugSettings = findPreference(Settings.PREF_DEBUG_SETTINGS);
if (mDebugSettingsPreference != null) { if (debugSettings != null) {
if (ProductionFlag.IS_INTERNAL) { if (ProductionFlag.IS_INTERNAL) {
final Intent debugSettingsIntent = new Intent(Intent.ACTION_MAIN); final Intent debugSettingsIntent = new Intent(Intent.ACTION_MAIN);
debugSettingsIntent.setClassName( debugSettingsIntent.setClassName(
context.getPackageName(), DebugSettingsActivity.class.getName()); context.getPackageName(), DebugSettingsActivity.class.getName());
mDebugSettingsPreference.setIntent(debugSettingsIntent); debugSettings.setIntent(debugSettingsIntent);
} else { } else {
miscSettings.removePreference(mDebugSettingsPreference); miscSettings.removePreference(debugSettings);
} }
} }
@ -112,11 +110,8 @@ public final class SettingsFragment extends InputMethodSettingsFragment
final PreferenceGroup advancedSettings = final PreferenceGroup advancedSettings =
(PreferenceGroup) findPreference(Settings.PREF_ADVANCED_SETTINGS); (PreferenceGroup) findPreference(Settings.PREF_ADVANCED_SETTINGS);
if (!AudioAndHapticFeedbackManager.getInstance().hasVibrator()) { if (!AudioAndHapticFeedbackManager.getInstance().hasVibrator()) {
generalSettings.removePreference(findPreference(Settings.PREF_VIBRATE_ON)); removePreference(Settings.PREF_VIBRATE_ON, generalSettings);
if (null != advancedSettings) { // Theoretically advancedSettings cannot be null removePreference(Settings.PREF_VIBRATION_DURATION_SETTINGS, advancedSettings);
advancedSettings.removePreference(
findPreference(Settings.PREF_VIBRATION_DURATION_SETTINGS));
}
} }
final boolean showKeyPreviewPopupOption = res.getBoolean( final boolean showKeyPreviewPopupOption = res.getBoolean(
@ -124,10 +119,8 @@ public final class SettingsFragment extends InputMethodSettingsFragment
mKeyPreviewPopupDismissDelay = mKeyPreviewPopupDismissDelay =
(ListPreference) findPreference(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY); (ListPreference) findPreference(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
if (!showKeyPreviewPopupOption) { if (!showKeyPreviewPopupOption) {
generalSettings.removePreference(findPreference(Settings.PREF_POPUP_ON)); removePreference(Settings.PREF_POPUP_ON, generalSettings);
if (null != advancedSettings) { // Theoretically advancedSettings cannot be null removePreference(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY, advancedSettings);
advancedSettings.removePreference(mKeyPreviewPopupDismissDelay);
}
} else { } else {
final String[] entries = new String[] { final String[] entries = new String[] {
res.getString(R.string.key_preview_popup_dismiss_no_delay), res.getString(R.string.key_preview_popup_dismiss_no_delay),
@ -148,10 +141,11 @@ public final class SettingsFragment extends InputMethodSettingsFragment
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));
final PreferenceGroup textCorrectionGroup =
(PreferenceGroup) findPreference(Settings.PREF_CORRECTION_SETTINGS);
final PreferenceScreen dictionaryLink = final PreferenceScreen dictionaryLink =
(PreferenceScreen) findPreference(Settings.PREF_CONFIGURE_DICTIONARIES_KEY); (PreferenceScreen) findPreference(Settings.PREF_CONFIGURE_DICTIONARIES_KEY);
final Intent intent = dictionaryLink.getIntent(); final Intent intent = dictionaryLink.getIntent();
final int number = context.getPackageManager().queryIntentActivities(intent, 0).size(); final int number = context.getPackageManager().queryIntentActivities(intent, 0).size();
// TODO: The experimental version is not supported by the Dictionary Pack Service yet // TODO: The experimental version is not supported by the Dictionary Pack Service yet
if (ProductionFlag.IS_EXPERIMENTAL || 0 >= number) { if (ProductionFlag.IS_EXPERIMENTAL || 0 >= number) {
@ -161,7 +155,7 @@ public final class SettingsFragment extends InputMethodSettingsFragment
final boolean gestureInputEnabledByBuildConfig = res.getBoolean( final boolean gestureInputEnabledByBuildConfig = res.getBoolean(
R.bool.config_gesture_input_enabled_by_build_config); R.bool.config_gesture_input_enabled_by_build_config);
if (!gestureInputEnabledByBuildConfig) { if (!gestureInputEnabledByBuildConfig) {
getPreferenceScreen().removePreference(gestureTypingSettings); removePreference(Settings.PREF_GESTURE_SETTINGS, getPreferenceScreen());
} }
setupKeyLongpressTimeoutSettings(prefs, res); setupKeyLongpressTimeoutSettings(prefs, res);
@ -219,6 +213,13 @@ public final class SettingsFragment extends InputMethodSettingsFragment
refreshEnablingsOfKeypressSoundAndVibrationSettings(prefs, getResources()); refreshEnablingsOfKeypressSoundAndVibrationSettings(prefs, getResources());
} }
private void ensureConsistencyOfAutoCorrectionSettings() {
final String autoCorrectionOff = getResources().getString(
R.string.auto_correction_threshold_mode_index_off);
final String currentSetting = mAutoCorrectionThresholdPreference.getValue();
mBigramPrediction.setEnabled(!currentSetting.equals(autoCorrectionOff));
}
private void updateShowCorrectionSuggestionsSummary() { private void updateShowCorrectionSuggestionsSummary() {
mShowCorrectionSuggestionsPreference.setSummary( mShowCorrectionSuggestionsPreference.setSummary(
getResources().getStringArray(R.array.prefs_suggestion_visibilities) getResources().getStringArray(R.array.prefs_suggestion_visibilities)