Show current vibrate setting
Bug 6014134
Show the current vibrate setting in the pref's summary rather than
making the user tap on the setting in order to bring up a dialog
of the current setting.
Change-Id: Idc2408f79174704da6fbf4eec7f4d67f74812695
diff --git a/src/com/android/mms/ui/MessagingPreferenceActivity.java b/src/com/android/mms/ui/MessagingPreferenceActivity.java
index 0c69da2..28c8ae9 100755
--- a/src/com/android/mms/ui/MessagingPreferenceActivity.java
+++ b/src/com/android/mms/ui/MessagingPreferenceActivity.java
@@ -22,7 +22,6 @@
import com.android.mms.R;
import android.app.ActionBar;
-import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
@@ -37,6 +36,7 @@
import android.preference.PreferenceCategory;
import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;
+import android.preference.Preference.OnPreferenceChangeListener;
import android.provider.SearchRecentSuggestions;
import android.view.Menu;
import android.view.MenuItem;
@@ -47,7 +47,8 @@
* With this activity, users can set preferences for MMS and SMS and
* can access and manipulate SMS messages stored on the SIM.
*/
-public class MessagingPreferenceActivity extends PreferenceActivity {
+public class MessagingPreferenceActivity extends PreferenceActivity
+ implements OnPreferenceChangeListener {
// Symbolic names for the keys used for preference lookup
public static final String MMS_DELIVERY_REPORT_MODE = "pref_key_mms_delivery_reports";
public static final String EXPIRY_TIME = "pref_key_mms_expiry";
@@ -77,6 +78,8 @@
private Recycler mSmsRecycler;
private Recycler mMmsRecycler;
private static final int CONFIRM_CLEAR_SEARCH_HISTORY_DIALOG = 3;
+ private CharSequence[] mVibrateEntries;
+ private CharSequence[] mVibrateValues;
@Override
protected void onCreate(Bundle icicle) {
@@ -93,6 +96,9 @@
mEnableNotificationsPref = (CheckBoxPreference) findPreference(NOTIFICATION_ENABLED);
mVibrateWhenPref = (ListPreference) findPreference(NOTIFICATION_VIBRATE_WHEN);
+ mVibrateEntries = getResources().getTextArray(R.array.prefEntries_vibrateWhen);
+ mVibrateValues = getResources().getTextArray(R.array.prefValues_vibrateWhen);
+
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
setMessagePreferences();
@@ -105,6 +111,7 @@
// Since the enabled notifications pref can be changed outside of this activity,
// we have to reload it whenever we resume.
setEnabledNotificationsPref();
+ registerListeners();
}
private void setMessagePreferences() {
@@ -164,6 +171,8 @@
// Fix up the recycler's summary with the correct values
setSmsDisplayLimit();
setMmsDisplayLimit();
+
+ adjustVibrateSummary(mVibrateWhenPref.getValue());
}
private void setEnabledNotificationsPref() {
@@ -302,4 +311,28 @@
editor.apply();
}
+
+ private void registerListeners() {
+ mVibrateWhenPref.setOnPreferenceChangeListener(this);
+ }
+
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ boolean result = false;
+ if (preference == mVibrateWhenPref) {
+ adjustVibrateSummary((String)newValue);
+ result = true;
+ }
+ return result;
+ }
+
+ private void adjustVibrateSummary(String value) {
+ int len = mVibrateValues.length;
+ for (int i = 0; i < len; i++) {
+ if (mVibrateValues[i].equals(value)) {
+ mVibrateWhenPref.setSummary(mVibrateEntries[i]);
+ return;
+ }
+ }
+ mVibrateWhenPref.setSummary(null);
+ }
}