diff options
author | Adnan <adnan@cyngn.com> | 2015-01-06 12:23:30 -0800 |
---|---|---|
committer | Adnan Begovic <adnan@cyngn.com> | 2016-01-12 13:58:03 -0800 |
commit | 8605334551ba87d5454fcbd7b4a17a556637e3cc (patch) | |
tree | 278aad01027a4cff08fa4ba4c95d5152ffb5777b /src | |
parent | 2c3e40d3af620990aaba1a4ac9f32629d2ff4b16 (diff) | |
download | packages_apps_Settings-8605334551ba87d5454fcbd7b4a17a556637e3cc.zip packages_apps_Settings-8605334551ba87d5454fcbd7b4a17a556637e3cc.tar.gz packages_apps_Settings-8605334551ba87d5454fcbd7b4a17a556637e3cc.tar.bz2 |
Settings: Show ringtone per sim for multi sim device
TICKET: CYNGNOS-1589
Change-Id: I56244242cece2c0ab732a2edb8d8c57e9d2c29b3
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/settings/DefaultRingtonePreference.java | 8 | ||||
-rw-r--r-- | src/com/android/settings/notification/SoundSettings.java | 68 |
2 files changed, 59 insertions, 17 deletions
diff --git a/src/com/android/settings/DefaultRingtonePreference.java b/src/com/android/settings/DefaultRingtonePreference.java index 4607bcd..d3cbe5a 100644 --- a/src/com/android/settings/DefaultRingtonePreference.java +++ b/src/com/android/settings/DefaultRingtonePreference.java @@ -44,7 +44,13 @@ public class DefaultRingtonePreference extends RingtonePreference { @Override protected void onSaveRingtone(Uri ringtoneUri) { - RingtoneManager.setActualDefaultRingtoneUri(getContext(), getRingtoneType(), ringtoneUri); + if (getRingtoneType() == RingtoneManager.TYPE_RINGTONE) { + RingtoneManager.setActualRingtoneUriBySubId(getContext(), + getSubId(), ringtoneUri); + } else { + RingtoneManager.setActualDefaultRingtoneUri(getContext(), + getRingtoneType(), ringtoneUri); + } } @Override diff --git a/src/com/android/settings/notification/SoundSettings.java b/src/com/android/settings/notification/SoundSettings.java index a8e3165..73973f2 100644 --- a/src/com/android/settings/notification/SoundSettings.java +++ b/src/com/android/settings/notification/SoundSettings.java @@ -37,7 +37,6 @@ import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.os.Message; -import android.os.UserHandle; import android.os.UserManager; import android.os.Vibrator; import android.preference.Preference; @@ -51,15 +50,17 @@ import android.provider.MediaStore; import android.provider.OpenableColumns; import android.provider.SearchIndexableResource; import android.provider.Settings; +import android.telephony.SubscriptionManager; +import android.telephony.TelephonyManager; import android.util.Log; import com.android.internal.logging.MetricsLogger; import com.android.internal.widget.LockPatternUtils; +import com.android.settings.DefaultRingtonePreference; import com.android.settings.DropDownPreference; import com.android.settings.R; import com.android.settings.SettingsPreferenceFragment; import com.android.settings.Utils; -import com.android.settings.hardware.VibratorIntensity; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.search.Indexable; import cyanogenmod.hardware.CMHardwareManager; @@ -129,7 +130,7 @@ public class SoundSettings extends SettingsPreferenceFragment implements Indexab private TwoStatePreference mIncreasingRing; private IncreasingRingVolumePreference mIncreasingRingVolume; - private Preference mPhoneRingtonePreference; + private ArrayList<DefaultRingtonePreference> mPhoneRingtonePreferences; private Preference mNotificationRingtonePreference; private TwoStatePreference mVibrateWhenRinging; private Preference mNotificationAccess; @@ -347,10 +348,32 @@ public class SoundSettings extends SettingsPreferenceFragment implements Indexab // === Phone & notification ringtone === private void initRingtones(PreferenceCategory root) { - mPhoneRingtonePreference = root.findPreference(KEY_PHONE_RINGTONE); - if (mPhoneRingtonePreference != null && (!mVoiceCapable || !Utils.isUserOwner())) { - root.removePreference(mPhoneRingtonePreference); - mPhoneRingtonePreference = null; + DefaultRingtonePreference phoneRingtonePreference = + (DefaultRingtonePreference) root.findPreference(KEY_PHONE_RINGTONE); + if (mPhoneRingtonePreferences != null && !mVoiceCapable || !Utils.isUserOwner()) { + root.removePreference(phoneRingtonePreference); + mPhoneRingtonePreferences = null; + } else { + mPhoneRingtonePreferences = new ArrayList<DefaultRingtonePreference>(); + TelephonyManager telephonyManager = (TelephonyManager) mContext.getSystemService( + Context.TELEPHONY_SERVICE); + if (telephonyManager.isMultiSimEnabled()){ + root.removePreference(phoneRingtonePreference); + PreferenceCategory soundCategory = (PreferenceCategory) findPreference(KEY_SOUND); + for (int i = 0; i < TelephonyManager.getDefault().getSimCount(); i++) { + DefaultRingtonePreference ringtonePreference = + new DefaultRingtonePreference(mContext, null); + String title = getString(R.string.sim_ringtone_title, i + 1); + ringtonePreference.setTitle(title); + ringtonePreference.setSubId(i); + ringtonePreference.setOrder(0); + ringtonePreference.setRingtoneType(RingtoneManager.TYPE_RINGTONE); + soundCategory.addPreference(ringtonePreference); + mPhoneRingtonePreferences.add(ringtonePreference); + } + } else { + mPhoneRingtonePreferences.add(phoneRingtonePreference); + } } mNotificationRingtonePreference = root.findPreference(KEY_NOTIFICATION_RINGTONE); } @@ -362,16 +385,20 @@ public class SoundSettings extends SettingsPreferenceFragment implements Indexab private final Runnable mLookupRingtoneNames = new Runnable() { @Override public void run() { - if (mPhoneRingtonePreference != null) { - final CharSequence summary = updateRingtoneName( - mContext, RingtoneManager.TYPE_RINGTONE); - if (summary != null) { - mHandler.obtainMessage(H.UPDATE_PHONE_RINGTONE, summary).sendToTarget(); + if (mPhoneRingtonePreferences != null) { + ArrayList<CharSequence> summaries = new ArrayList<CharSequence>(); + for (DefaultRingtonePreference preference : mPhoneRingtonePreferences) { + CharSequence summary = updateRingtoneName( + mContext, RingtoneManager.TYPE_RINGTONE, preference.getSubId()); + summaries.add(summary); + } + if (!summaries.isEmpty()) { + mHandler.obtainMessage(H.UPDATE_PHONE_RINGTONE, summaries).sendToTarget(); } } if (mNotificationRingtonePreference != null) { final CharSequence summary = updateRingtoneName( - mContext, RingtoneManager.TYPE_NOTIFICATION); + mContext, RingtoneManager.TYPE_NOTIFICATION, -1); if (summary != null) { mHandler.obtainMessage(H.UPDATE_NOTIFICATION_RINGTONE, summary).sendToTarget(); } @@ -379,12 +406,17 @@ public class SoundSettings extends SettingsPreferenceFragment implements Indexab } }; - private static CharSequence updateRingtoneName(Context context, int type) { + private static CharSequence updateRingtoneName(Context context, int type, int subId) { if (context == null) { Log.e(TAG, "Unable to update ringtone name, no context provided"); return null; } - Uri ringtoneUri = RingtoneManager.getActualDefaultRingtoneUri(context, type); + Uri ringtoneUri; + if (type != RingtoneManager.TYPE_RINGTONE || subId <= 0) { + ringtoneUri = RingtoneManager.getActualDefaultRingtoneUri(context, type); + } else { + ringtoneUri = RingtoneManager.getActualRingtoneUriBySubId(context, subId); + } CharSequence summary = context.getString(com.android.internal.R.string.ringtone_unknown); // Is it a silent ringtone? if (ringtoneUri == null) { @@ -568,7 +600,11 @@ public class SoundSettings extends SettingsPreferenceFragment implements Indexab public void handleMessage(Message msg) { switch (msg.what) { case UPDATE_PHONE_RINGTONE: - mPhoneRingtonePreference.setSummary((CharSequence) msg.obj); + ArrayList<CharSequence> summaries = (ArrayList<CharSequence>) msg.obj; + for (int i = 0; i < summaries.size(); i++) { + Preference preference = mPhoneRingtonePreferences.get(i); + preference.setSummary(summaries.get(i)); + } break; case UPDATE_NOTIFICATION_RINGTONE: mNotificationRingtonePreference.setSummary((CharSequence) msg.obj); |