Merge "Accurately update the preference summary string when changing the vibrate setting." into ics-mr1

This commit is contained in:
Vikram Aggarwal 2011-11-18 12:52:18 -08:00 committed by Android (Google) Code Review
commit dd4f501b44

View File

@ -506,15 +506,35 @@ public class AccountSettingsFragment extends PreferenceFragment {
mAccountVibrateWhen = (ListPreference) findPreference(PREFERENCE_VIBRATE_WHEN); mAccountVibrateWhen = (ListPreference) findPreference(PREFERENCE_VIBRATE_WHEN);
Vibrator vibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE); Vibrator vibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
if (vibrator.hasVibrator()) { if (vibrator.hasVibrator()) {
boolean flagsVibrate = 0 != (mAccount.getFlags() & Account.FLAGS_VIBRATE_ALWAYS); // Calculate the value to set based on the choices, and set the value.
boolean flagsVibrateSilent = final boolean vibrateAlways = 0 != (mAccount.getFlags() & Account.FLAGS_VIBRATE_ALWAYS);
final boolean vibrateWhenSilent =
0 != (mAccount.getFlags() & Account.FLAGS_VIBRATE_WHEN_SILENT); 0 != (mAccount.getFlags() & Account.FLAGS_VIBRATE_WHEN_SILENT);
mAccountVibrateWhen.setValue( final String vibrateSetting =
flagsVibrate ? PREFERENCE_VALUE_VIBRATE_WHEN_ALWAYS : vibrateAlways ? PREFERENCE_VALUE_VIBRATE_WHEN_ALWAYS :
flagsVibrateSilent ? PREFERENCE_VALUE_VIBRATE_WHEN_SILENT : vibrateWhenSilent ? PREFERENCE_VALUE_VIBRATE_WHEN_SILENT :
PREFERENCE_VALUE_VIBRATE_WHEN_NEVER); PREFERENCE_VALUE_VIBRATE_WHEN_NEVER;
mAccountVibrateWhen.setOnPreferenceChangeListener(mPreferenceChangeListener); mAccountVibrateWhen.setValue(vibrateSetting);
// Update the summary string.
final int index = mAccountVibrateWhen.findIndexOfValue(vibrateSetting);
mAccountVibrateWhen.setSummary(mAccountVibrateWhen.getEntries()[index]);
// When the value is changed, update the summary in addition to the setting.
mAccountVibrateWhen.setOnPreferenceChangeListener(
new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final String vibrateSetting = newValue.toString();
final int index = mAccountVibrateWhen.findIndexOfValue(vibrateSetting);
mAccountVibrateWhen.setSummary(mAccountVibrateWhen.getEntries()[index]);
mAccountVibrateWhen.setValue(vibrateSetting);
onPreferenceChanged(PREFERENCE_VIBRATE_WHEN, newValue);
return false;
}
});
} else { } else {
// No vibrator present. Remove the preference altogether.
PreferenceCategory notificationsCategory = (PreferenceCategory) PreferenceCategory notificationsCategory = (PreferenceCategory)
findPreference(PREFERENCE_CATEGORY_NOTIFICATIONS); findPreference(PREFERENCE_CATEGORY_NOTIFICATIONS);
notificationsCategory.removePreference(mAccountVibrateWhen); notificationsCategory.removePreference(mAccountVibrateWhen);