Merge "Add VoicemailRingtonePreference to contain lookup logic." into lmp-mr1-dev
automerge: 4b94a31
* commit '4b94a311d1fa7b9393b33bb8e29fec2e9b896d3c':
Add VoicemailRingtonePreference to contain lookup logic.
diff --git a/res/xml/call_feature_setting.xml b/res/xml/call_feature_setting.xml
index 2148594..f958c1a 100644
--- a/res/xml/call_feature_setting.xml
+++ b/res/xml/call_feature_setting.xml
@@ -64,7 +64,7 @@
</PreferenceScreen>
- <RingtonePreference
+ <com.android.phone.settings.VoicemailRingtonePreference
android:key="button_voicemail_notification_ringtone_key"
android:title="@string/voicemail_notification_ringtone_title"
android:persistent="true"
diff --git a/src/com/android/phone/CallFeaturesSetting.java b/src/com/android/phone/CallFeaturesSetting.java
index 5204500..e468027 100644
--- a/src/com/android/phone/CallFeaturesSetting.java
+++ b/src/com/android/phone/CallFeaturesSetting.java
@@ -33,7 +33,6 @@
import android.content.pm.ResolveInfo;
import android.database.Cursor;
import android.media.AudioManager;
-import android.media.RingtoneManager;
import android.os.AsyncResult;
import android.os.Bundle;
import android.os.Handler;
@@ -241,18 +240,6 @@
private EditPhoneNumberPreference mSubMenuVoicemailSettings;
- private Runnable mVoicemailRingtoneLookupRunnable;
- private final Handler mVoicemailRingtoneLookupComplete = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- switch (msg.what) {
- case MSG_UPDATE_VOICEMAIL_RINGTONE_SUMMARY:
- mVoicemailNotificationRingtone.setSummary((CharSequence) msg.obj);
- break;
- }
- }
- };
-
/** Whether dialpad plays DTMF tone or not. */
private CheckBoxPreference mButtonAutoRetry;
private CheckBoxPreference mButtonHAC;
@@ -262,7 +249,6 @@
private ListPreference mVoicemailProviders;
private PreferenceScreen mVoicemailSettingsScreen;
private PreferenceScreen mVoicemailSettings;
- private Preference mVoicemailNotificationRingtone;
private CheckBoxPreference mVoicemailNotificationVibrate;
private AccountSelectionPreference mDefaultOutgoingAccount;
private CheckBoxPreference mEnableVideoCalling;
@@ -1443,20 +1429,6 @@
mContactListIntent = new Intent(Intent.ACTION_GET_CONTENT);
mContactListIntent.setType(android.provider.Contacts.Phones.CONTENT_ITEM_TYPE);
- mVoicemailRingtoneLookupRunnable = new Runnable() {
- @Override
- public void run() {
- if (mVoicemailNotificationRingtone != null) {
- SettingsUtil.updateRingtoneName(
- mPhone.getContext(),
- mVoicemailRingtoneLookupComplete,
- RingtoneManager.TYPE_NOTIFICATION,
- mVoicemailNotificationRingtone,
- MSG_UPDATE_VOICEMAIL_RINGTONE_SUMMARY);
- }
- }
- };
-
// Show the voicemail preference in onResume if the calling intent specifies the
// ACTION_ADD_VOICEMAIL action.
mShowVoicemailPreference = (icicle == null) &&
@@ -1513,8 +1485,6 @@
mVoicemailSettingsScreen =
(PreferenceScreen) findPreference(VOICEMAIL_SETTING_SCREEN_PREF_KEY);
mVoicemailSettings = (PreferenceScreen)findPreference(BUTTON_VOICEMAIL_SETTING_KEY);
- mVoicemailNotificationRingtone =
- findPreference(BUTTON_VOICEMAIL_NOTIFICATION_RINGTONE_KEY);
mVoicemailNotificationVibrate =
(CheckBoxPreference) findPreference(BUTTON_VOICEMAIL_NOTIFICATION_VIBRATE_KEY);
initVoiceMailProviders();
@@ -1629,9 +1599,6 @@
} else {
prefSet.removePreference(mEnableVideoCalling);
}
-
- // Look up the voicemail ringtone name asynchronously and update its preference.
- new Thread(mVoicemailRingtoneLookupRunnable).start();
}
// Migrate settings from BUTTON_VOICEMAIL_NOTIFICATION_VIBRATE_WHEN_KEY to
diff --git a/src/com/android/phone/settings/VoicemailRingtonePreference.java b/src/com/android/phone/settings/VoicemailRingtonePreference.java
new file mode 100644
index 0000000..3cc48af
--- /dev/null
+++ b/src/com/android/phone/settings/VoicemailRingtonePreference.java
@@ -0,0 +1,65 @@
+package com.android.phone.settings;
+
+import android.content.Context;
+import android.media.RingtoneManager;
+import android.net.Uri;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.preference.Preference;
+import android.preference.RingtonePreference;
+import android.util.AttributeSet;
+
+import com.android.phone.PhoneGlobals;
+import com.android.phone.common.util.SettingsUtil;
+
+/**
+ * Looks up the voicemail ringtone's name asynchronously and updates the preference's summary when
+ * it is created or updated.
+ */
+public class VoicemailRingtonePreference extends RingtonePreference {
+ private static final int MSG_UPDATE_VOICEMAIL_RINGTONE_SUMMARY = 1;
+
+ private Runnable mVoicemailRingtoneLookupRunnable;
+ private Handler mVoicemailRingtoneLookupComplete;
+
+ public VoicemailRingtonePreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+
+ mVoicemailRingtoneLookupComplete = new Handler() {
+ @Override
+ public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case MSG_UPDATE_VOICEMAIL_RINGTONE_SUMMARY:
+ setSummary((CharSequence) msg.obj);
+ break;
+ }
+ }
+ };
+
+ final Preference preference = this;
+ mVoicemailRingtoneLookupRunnable = new Runnable() {
+ @Override
+ public void run() {
+ SettingsUtil.updateRingtoneName(
+ preference.getContext(),
+ mVoicemailRingtoneLookupComplete,
+ RingtoneManager.TYPE_NOTIFICATION,
+ preference,
+ MSG_UPDATE_VOICEMAIL_RINGTONE_SUMMARY);
+ }
+ };
+
+ updateRingtoneName();
+ }
+
+ @Override
+ protected void onSaveRingtone(Uri ringtoneUri) {
+ super.onSaveRingtone(ringtoneUri);
+ updateRingtoneName();
+ }
+
+ private void updateRingtoneName() {
+ new Thread(mVoicemailRingtoneLookupRunnable).start();
+ }
+}