The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.settings; |
| 18 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 19 | import android.content.BroadcastReceiver; |
| 20 | import android.content.ContentResolver; |
| 21 | import android.content.Context; |
| 22 | import android.content.Intent; |
| 23 | import android.content.IntentFilter; |
Marco Nelissen | 6eca4b3 | 2011-07-15 15:02:03 -0700 | [diff] [blame] | 24 | import android.content.pm.PackageManager; |
| 25 | import android.content.pm.ResolveInfo; |
Amith Yamasani | 823bf0c | 2011-08-01 15:55:06 -0700 | [diff] [blame] | 26 | import android.database.Cursor; |
| 27 | import android.database.sqlite.SQLiteException; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 28 | import android.media.AudioManager; |
Amith Yamasani | 823bf0c | 2011-08-01 15:55:06 -0700 | [diff] [blame] | 29 | import android.media.Ringtone; |
| 30 | import android.media.RingtoneManager; |
Marco Nelissen | 6eca4b3 | 2011-07-15 15:02:03 -0700 | [diff] [blame] | 31 | import android.media.audiofx.AudioEffect; |
Amith Yamasani | 823bf0c | 2011-08-01 15:55:06 -0700 | [diff] [blame] | 32 | import android.net.Uri; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 33 | import android.os.Bundle; |
Amith Yamasani | 823bf0c | 2011-08-01 15:55:06 -0700 | [diff] [blame] | 34 | import android.os.Handler; |
| 35 | import android.os.Message; |
Dianne Hackborn | 0a115aa | 2010-11-04 11:40:31 -0700 | [diff] [blame] | 36 | import android.os.Vibrator; |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 37 | import android.preference.CheckBoxPreference; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 38 | import android.preference.ListPreference; |
| 39 | import android.preference.Preference; |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 40 | import android.preference.PreferenceGroup; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 41 | import android.preference.PreferenceScreen; |
Amith Yamasani | 823bf0c | 2011-08-01 15:55:06 -0700 | [diff] [blame] | 42 | import android.provider.MediaStore; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 43 | import android.provider.Settings; |
Amith Yamasani | 823bf0c | 2011-08-01 15:55:06 -0700 | [diff] [blame] | 44 | import android.provider.MediaStore.Images.Media; |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 45 | import android.provider.Settings.SettingNotFoundException; |
| 46 | import android.telephony.TelephonyManager; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 47 | import android.util.Log; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 48 | |
Marco Nelissen | 6eca4b3 | 2011-07-15 15:02:03 -0700 | [diff] [blame] | 49 | import java.util.List; |
| 50 | |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 51 | public class SoundSettings extends SettingsPreferenceFragment implements |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 52 | Preference.OnPreferenceChangeListener { |
Amith Yamasani | 823bf0c | 2011-08-01 15:55:06 -0700 | [diff] [blame] | 53 | private static final String TAG = "SoundSettings"; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 54 | |
| 55 | /** If there is no setting in the provider, use this. */ |
Chouting Zhang | 386278a | 2009-06-24 14:25:43 -0500 | [diff] [blame] | 56 | private static final int FALLBACK_EMERGENCY_TONE_VALUE = 0; |
Michael Chan | df9504e | 2009-12-06 01:04:04 -0800 | [diff] [blame] | 57 | |
Amith Yamasani | dfb6543 | 2011-11-29 16:38:14 -0800 | [diff] [blame] | 58 | private static final String KEY_SILENT_MODE = "silent_mode"; |
| 59 | private static final String KEY_VIBRATE = "vibrate_on_ring"; |
Joe Onorato | 057f181 | 2011-01-12 15:35:47 -0800 | [diff] [blame] | 60 | private static final String KEY_RING_VOLUME = "ring_volume"; |
Marco Nelissen | 6eca4b3 | 2011-07-15 15:02:03 -0700 | [diff] [blame] | 61 | private static final String KEY_MUSICFX = "musicfx"; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 62 | private static final String KEY_DTMF_TONE = "dtmf_tone"; |
| 63 | private static final String KEY_SOUND_EFFECTS = "sound_effects"; |
Dan Murphy | 22e1868 | 2009-09-22 11:47:08 -0500 | [diff] [blame] | 64 | private static final String KEY_HAPTIC_FEEDBACK = "haptic_feedback"; |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 65 | private static final String KEY_EMERGENCY_TONE = "emergency_tone"; |
| 66 | private static final String KEY_SOUND_SETTINGS = "sound_settings"; |
Daniel Sandler | 231d880 | 2010-02-17 15:35:21 -0500 | [diff] [blame] | 67 | private static final String KEY_LOCK_SOUNDS = "lock_sounds"; |
Amith Yamasani | 60133dd | 2010-09-11 14:17:31 -0700 | [diff] [blame] | 68 | private static final String KEY_RINGTONE = "ringtone"; |
| 69 | private static final String KEY_NOTIFICATION_SOUND = "notification_sound"; |
| 70 | private static final String KEY_CATEGORY_CALLS = "category_calls"; |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 71 | |
Amith Yamasani | dfb6543 | 2011-11-29 16:38:14 -0800 | [diff] [blame] | 72 | private static final String SILENT_MODE_OFF = "off"; |
| 73 | private static final String SILENT_MODE_VIBRATE = "vibrate"; |
| 74 | private static final String SILENT_MODE_MUTE = "mute"; |
Daniel Sandler | 2c91784 | 2010-04-21 15:24:24 -0400 | [diff] [blame] | 75 | |
Amith Yamasani | 60133dd | 2010-09-11 14:17:31 -0700 | [diff] [blame] | 76 | private static final String[] NEED_VOICE_CAPABILITY = { |
| 77 | KEY_RINGTONE, KEY_DTMF_TONE, KEY_CATEGORY_CALLS, |
| 78 | KEY_EMERGENCY_TONE |
| 79 | }; |
| 80 | |
Amith Yamasani | 823bf0c | 2011-08-01 15:55:06 -0700 | [diff] [blame] | 81 | private static final int MSG_UPDATE_RINGTONE_SUMMARY = 1; |
| 82 | private static final int MSG_UPDATE_NOTIFICATION_SUMMARY = 2; |
| 83 | |
Amith Yamasani | dfb6543 | 2011-11-29 16:38:14 -0800 | [diff] [blame] | 84 | private ListPreference mSilentMode; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 85 | private CheckBoxPreference mDtmfTone; |
| 86 | private CheckBoxPreference mSoundEffects; |
Dan Murphy | 22e1868 | 2009-09-22 11:47:08 -0500 | [diff] [blame] | 87 | private CheckBoxPreference mHapticFeedback; |
Marco Nelissen | 6eca4b3 | 2011-07-15 15:02:03 -0700 | [diff] [blame] | 88 | private Preference mMusicFx; |
Daniel Sandler | 231d880 | 2010-02-17 15:35:21 -0500 | [diff] [blame] | 89 | private CheckBoxPreference mLockSounds; |
Amith Yamasani | 823bf0c | 2011-08-01 15:55:06 -0700 | [diff] [blame] | 90 | private Preference mRingtonePreference; |
| 91 | private Preference mNotificationPreference; |
| 92 | |
| 93 | private Runnable mRingtoneLookupRunnable; |
Michael Chan | df9504e | 2009-12-06 01:04:04 -0800 | [diff] [blame] | 94 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 95 | private AudioManager mAudioManager; |
Michael Chan | df9504e | 2009-12-06 01:04:04 -0800 | [diff] [blame] | 96 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 97 | private BroadcastReceiver mReceiver = new BroadcastReceiver() { |
| 98 | @Override |
| 99 | public void onReceive(Context context, Intent intent) { |
Amith Yamasani | d2b3ab0 | 2009-12-02 13:56:05 -0800 | [diff] [blame] | 100 | if (intent.getAction().equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) { |
| 101 | updateState(false); |
Amith Yamasani | d2b3ab0 | 2009-12-02 13:56:05 -0800 | [diff] [blame] | 102 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 103 | } |
| 104 | }; |
| 105 | |
Amith Yamasani | 823bf0c | 2011-08-01 15:55:06 -0700 | [diff] [blame] | 106 | private Handler mHandler = new Handler() { |
| 107 | public void handleMessage(Message msg) { |
| 108 | switch (msg.what) { |
| 109 | case MSG_UPDATE_RINGTONE_SUMMARY: |
| 110 | mRingtonePreference.setSummary((CharSequence) msg.obj); |
| 111 | break; |
| 112 | case MSG_UPDATE_NOTIFICATION_SUMMARY: |
| 113 | mNotificationPreference.setSummary((CharSequence) msg.obj); |
| 114 | break; |
| 115 | } |
| 116 | } |
| 117 | }; |
| 118 | |
Amith Yamasani | d2b3ab0 | 2009-12-02 13:56:05 -0800 | [diff] [blame] | 119 | private PreferenceGroup mSoundSettings; |
| 120 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 121 | @Override |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 122 | public void onCreate(Bundle savedInstanceState) { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 123 | super.onCreate(savedInstanceState); |
| 124 | ContentResolver resolver = getContentResolver(); |
Wink Saville | 327147e | 2011-02-02 11:30:25 -0800 | [diff] [blame] | 125 | int activePhoneType = TelephonyManager.getDefault().getCurrentPhoneType(); |
Michael Chan | df9504e | 2009-12-06 01:04:04 -0800 | [diff] [blame] | 126 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 127 | mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 128 | |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 129 | addPreferencesFromResource(R.xml.sound_settings); |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 130 | |
Chouting Zhang | 386278a | 2009-06-24 14:25:43 -0500 | [diff] [blame] | 131 | if (TelephonyManager.PHONE_TYPE_CDMA != activePhoneType) { |
| 132 | // device is not CDMA, do not display CDMA emergency_tone |
| 133 | getPreferenceScreen().removePreference(findPreference(KEY_EMERGENCY_TONE)); |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 134 | } |
Chouting Zhang | 386278a | 2009-06-24 14:25:43 -0500 | [diff] [blame] | 135 | |
Amith Yamasani | dfb6543 | 2011-11-29 16:38:14 -0800 | [diff] [blame] | 136 | mSilentMode = (ListPreference) findPreference(KEY_SILENT_MODE); |
Joe Onorato | 057f181 | 2011-01-12 15:35:47 -0800 | [diff] [blame] | 137 | if (!getResources().getBoolean(R.bool.has_silent_mode)) { |
Amith Yamasani | dfb6543 | 2011-11-29 16:38:14 -0800 | [diff] [blame] | 138 | getPreferenceScreen().removePreference(mSilentMode); |
Joe Onorato | 057f181 | 2011-01-12 15:35:47 -0800 | [diff] [blame] | 139 | findPreference(KEY_RING_VOLUME).setDependency(null); |
Amith Yamasani | dfb6543 | 2011-11-29 16:38:14 -0800 | [diff] [blame] | 140 | } else { |
| 141 | mSilentMode.setOnPreferenceChangeListener(this); |
Joe Onorato | 057f181 | 2011-01-12 15:35:47 -0800 | [diff] [blame] | 142 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 143 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 144 | mDtmfTone = (CheckBoxPreference) findPreference(KEY_DTMF_TONE); |
| 145 | mDtmfTone.setPersistent(false); |
| 146 | mDtmfTone.setChecked(Settings.System.getInt(resolver, |
| 147 | Settings.System.DTMF_TONE_WHEN_DIALING, 1) != 0); |
| 148 | mSoundEffects = (CheckBoxPreference) findPreference(KEY_SOUND_EFFECTS); |
| 149 | mSoundEffects.setPersistent(false); |
| 150 | mSoundEffects.setChecked(Settings.System.getInt(resolver, |
Amith Yamasani | 823bf0c | 2011-08-01 15:55:06 -0700 | [diff] [blame] | 151 | Settings.System.SOUND_EFFECTS_ENABLED, 1) != 0); |
Dan Murphy | 22e1868 | 2009-09-22 11:47:08 -0500 | [diff] [blame] | 152 | mHapticFeedback = (CheckBoxPreference) findPreference(KEY_HAPTIC_FEEDBACK); |
| 153 | mHapticFeedback.setPersistent(false); |
| 154 | mHapticFeedback.setChecked(Settings.System.getInt(resolver, |
Amith Yamasani | 823bf0c | 2011-08-01 15:55:06 -0700 | [diff] [blame] | 155 | Settings.System.HAPTIC_FEEDBACK_ENABLED, 1) != 0); |
Daniel Sandler | 231d880 | 2010-02-17 15:35:21 -0500 | [diff] [blame] | 156 | mLockSounds = (CheckBoxPreference) findPreference(KEY_LOCK_SOUNDS); |
| 157 | mLockSounds.setPersistent(false); |
| 158 | mLockSounds.setChecked(Settings.System.getInt(resolver, |
| 159 | Settings.System.LOCKSCREEN_SOUNDS_ENABLED, 1) != 0); |
Chouting Zhang | 386278a | 2009-06-24 14:25:43 -0500 | [diff] [blame] | 160 | |
Amith Yamasani | 823bf0c | 2011-08-01 15:55:06 -0700 | [diff] [blame] | 161 | mRingtonePreference = findPreference(KEY_RINGTONE); |
| 162 | mNotificationPreference = findPreference(KEY_NOTIFICATION_SOUND); |
| 163 | |
Amith Yamasani | edac9af | 2010-11-17 09:08:21 -0800 | [diff] [blame] | 164 | if (!((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).hasVibrator()) { |
Amith Yamasani | edac9af | 2010-11-17 09:08:21 -0800 | [diff] [blame] | 165 | getPreferenceScreen().removePreference(mHapticFeedback); |
| 166 | } |
| 167 | |
Chouting Zhang | 386278a | 2009-06-24 14:25:43 -0500 | [diff] [blame] | 168 | if (TelephonyManager.PHONE_TYPE_CDMA == activePhoneType) { |
| 169 | ListPreference emergencyTonePreference = |
| 170 | (ListPreference) findPreference(KEY_EMERGENCY_TONE); |
| 171 | emergencyTonePreference.setValue(String.valueOf(Settings.System.getInt( |
| 172 | resolver, Settings.System.EMERGENCY_TONE, FALLBACK_EMERGENCY_TONE_VALUE))); |
| 173 | emergencyTonePreference.setOnPreferenceChangeListener(this); |
| 174 | } |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 175 | |
Amith Yamasani | d2b3ab0 | 2009-12-02 13:56:05 -0800 | [diff] [blame] | 176 | mSoundSettings = (PreferenceGroup) findPreference(KEY_SOUND_SETTINGS); |
Amith Yamasani | d2b3ab0 | 2009-12-02 13:56:05 -0800 | [diff] [blame] | 177 | |
Marco Nelissen | 6eca4b3 | 2011-07-15 15:02:03 -0700 | [diff] [blame] | 178 | mMusicFx = mSoundSettings.findPreference(KEY_MUSICFX); |
| 179 | Intent i = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL); |
| 180 | PackageManager p = getPackageManager(); |
| 181 | List<ResolveInfo> ris = p.queryIntentActivities(i, PackageManager.GET_DISABLED_COMPONENTS); |
| 182 | if (ris.size() <= 2) { |
| 183 | // no need to show the item if there is no choice for the user to make |
| 184 | // note: the built in musicfx panel has two activities (one being a |
| 185 | // compatibility shim that launches either the other activity, or a |
| 186 | // third party one), hence the check for <=2. If the implementation |
| 187 | // of the compatbility layer changes, this check may need to be updated. |
| 188 | mSoundSettings.removePreference(mMusicFx); |
| 189 | } |
| 190 | |
Amith Yamasani | 60133dd | 2010-09-11 14:17:31 -0700 | [diff] [blame] | 191 | if (!Utils.isVoiceCapable(getActivity())) { |
| 192 | for (String prefKey : NEED_VOICE_CAPABILITY) { |
| 193 | Preference pref = findPreference(prefKey); |
| 194 | if (pref != null) { |
| 195 | getPreferenceScreen().removePreference(pref); |
| 196 | } |
| 197 | } |
| 198 | } |
Amith Yamasani | 823bf0c | 2011-08-01 15:55:06 -0700 | [diff] [blame] | 199 | |
| 200 | mRingtoneLookupRunnable = new Runnable() { |
| 201 | public void run() { |
| 202 | if (mRingtonePreference != null) { |
| 203 | updateRingtoneName(RingtoneManager.TYPE_RINGTONE, mRingtonePreference, |
| 204 | MSG_UPDATE_RINGTONE_SUMMARY); |
| 205 | } |
| 206 | if (mNotificationPreference != null) { |
| 207 | updateRingtoneName(RingtoneManager.TYPE_NOTIFICATION, mNotificationPreference, |
| 208 | MSG_UPDATE_NOTIFICATION_SUMMARY); |
| 209 | } |
| 210 | } |
| 211 | }; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 212 | } |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 213 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 214 | @Override |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 215 | public void onResume() { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 216 | super.onResume(); |
Michael Chan | df9504e | 2009-12-06 01:04:04 -0800 | [diff] [blame] | 217 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 218 | updateState(true); |
Amith Yamasani | 823bf0c | 2011-08-01 15:55:06 -0700 | [diff] [blame] | 219 | lookupRingtoneNames(); |
Michael Chan | df9504e | 2009-12-06 01:04:04 -0800 | [diff] [blame] | 220 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 221 | IntentFilter filter = new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION); |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 222 | getActivity().registerReceiver(mReceiver, filter); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | @Override |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 226 | public void onPause() { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 227 | super.onPause(); |
| 228 | |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 229 | getActivity().unregisterReceiver(mReceiver); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 230 | } |
| 231 | |
Amith Yamasani | dfb6543 | 2011-11-29 16:38:14 -0800 | [diff] [blame] | 232 | private void setPhoneSilentSettingValue(String value) { |
| 233 | int ringerMode = AudioManager.RINGER_MODE_NORMAL; |
| 234 | if (value.equals(SILENT_MODE_MUTE)) { |
| 235 | ringerMode = AudioManager.RINGER_MODE_SILENT; |
| 236 | } else if (value.equals(SILENT_MODE_VIBRATE)) { |
| 237 | ringerMode = AudioManager.RINGER_MODE_VIBRATE; |
Daniel Sandler | 2c91784 | 2010-04-21 15:24:24 -0400 | [diff] [blame] | 238 | } |
Amith Yamasani | dfb6543 | 2011-11-29 16:38:14 -0800 | [diff] [blame] | 239 | mAudioManager.setRingerMode(ringerMode); |
| 240 | } |
Daniel Sandler | 2c91784 | 2010-04-21 15:24:24 -0400 | [diff] [blame] | 241 | |
Amith Yamasani | dfb6543 | 2011-11-29 16:38:14 -0800 | [diff] [blame] | 242 | private String getPhoneSilentModeSettingValue() { |
| 243 | switch (mAudioManager.getRingerMode()) { |
| 244 | case AudioManager.RINGER_MODE_NORMAL: |
| 245 | return SILENT_MODE_OFF; |
| 246 | case AudioManager.RINGER_MODE_VIBRATE: |
| 247 | return SILENT_MODE_VIBRATE; |
| 248 | case AudioManager.RINGER_MODE_SILENT: |
| 249 | return SILENT_MODE_MUTE; |
Daniel Sandler | 2c91784 | 2010-04-21 15:24:24 -0400 | [diff] [blame] | 250 | } |
Amith Yamasani | dfb6543 | 2011-11-29 16:38:14 -0800 | [diff] [blame] | 251 | // Shouldn't happen |
| 252 | return SILENT_MODE_OFF; |
Daniel Sandler | 2c91784 | 2010-04-21 15:24:24 -0400 | [diff] [blame] | 253 | } |
| 254 | |
Daniel Sandler | 58cf829 | 2010-02-26 15:25:04 -0500 | [diff] [blame] | 255 | // updateState in fact updates the UI to reflect the system state |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 256 | private void updateState(boolean force) { |
Amith Yamasani | eb99f2f | 2010-12-15 14:12:43 -0800 | [diff] [blame] | 257 | if (getActivity() == null) return; |
| 258 | |
Amith Yamasani | dfb6543 | 2011-11-29 16:38:14 -0800 | [diff] [blame] | 259 | mSilentMode.setValue(getPhoneSilentModeSettingValue()); |
Michael Chan | df9504e | 2009-12-06 01:04:04 -0800 | [diff] [blame] | 260 | |
Amith Yamasani | dfb6543 | 2011-11-29 16:38:14 -0800 | [diff] [blame] | 261 | mSilentMode.setSummary(mSilentMode.getEntry()); |
Amith Yamasani | 823bf0c | 2011-08-01 15:55:06 -0700 | [diff] [blame] | 262 | } |
Michael Chan | df9504e | 2009-12-06 01:04:04 -0800 | [diff] [blame] | 263 | |
Amith Yamasani | 823bf0c | 2011-08-01 15:55:06 -0700 | [diff] [blame] | 264 | private void updateRingtoneName(int type, Preference preference, int msg) { |
| 265 | if (preference == null) return; |
| 266 | Context context = getActivity(); |
| 267 | if (context == null) return; |
| 268 | Uri ringtoneUri = RingtoneManager.getActualDefaultRingtoneUri(context, type); |
| 269 | CharSequence summary = context.getString(com.android.internal.R.string.ringtone_unknown); |
| 270 | // Is it a silent ringtone? |
| 271 | if (ringtoneUri == null) { |
| 272 | summary = context.getString(com.android.internal.R.string.ringtone_silent); |
| 273 | } else { |
| 274 | // Fetch the ringtone title from the media provider |
| 275 | try { |
| 276 | Cursor cursor = context.getContentResolver().query(ringtoneUri, |
| 277 | new String[] { MediaStore.Audio.Media.TITLE }, null, null, null); |
Amith Yamasani | c86755b | 2011-10-04 15:00:21 -0700 | [diff] [blame] | 278 | if (cursor != null) { |
| 279 | if (cursor.moveToFirst()) { |
| 280 | summary = cursor.getString(0); |
| 281 | } |
| 282 | cursor.close(); |
Amith Yamasani | 823bf0c | 2011-08-01 15:55:06 -0700 | [diff] [blame] | 283 | } |
| 284 | } catch (SQLiteException sqle) { |
| 285 | // Unknown title for the ringtone |
| 286 | } |
| 287 | } |
| 288 | mHandler.sendMessage(mHandler.obtainMessage(msg, summary)); |
| 289 | } |
| 290 | |
| 291 | private void lookupRingtoneNames() { |
| 292 | new Thread(mRingtoneLookupRunnable).start(); |
Dianne Hackborn | 7631539 | 2009-09-03 13:33:55 -0700 | [diff] [blame] | 293 | } |
Michael Chan | df9504e | 2009-12-06 01:04:04 -0800 | [diff] [blame] | 294 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 295 | @Override |
| 296 | public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { |
Amith Yamasani | dfb6543 | 2011-11-29 16:38:14 -0800 | [diff] [blame] | 297 | if (preference == mDtmfTone) { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 298 | Settings.System.putInt(getContentResolver(), Settings.System.DTMF_TONE_WHEN_DIALING, |
| 299 | mDtmfTone.isChecked() ? 1 : 0); |
Michael Chan | df9504e | 2009-12-06 01:04:04 -0800 | [diff] [blame] | 300 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 301 | } else if (preference == mSoundEffects) { |
| 302 | if (mSoundEffects.isChecked()) { |
| 303 | mAudioManager.loadSoundEffects(); |
| 304 | } else { |
| 305 | mAudioManager.unloadSoundEffects(); |
| 306 | } |
| 307 | Settings.System.putInt(getContentResolver(), Settings.System.SOUND_EFFECTS_ENABLED, |
| 308 | mSoundEffects.isChecked() ? 1 : 0); |
Dan Murphy | 22e1868 | 2009-09-22 11:47:08 -0500 | [diff] [blame] | 309 | |
| 310 | } else if (preference == mHapticFeedback) { |
| 311 | Settings.System.putInt(getContentResolver(), Settings.System.HAPTIC_FEEDBACK_ENABLED, |
| 312 | mHapticFeedback.isChecked() ? 1 : 0); |
Michael Chan | df9504e | 2009-12-06 01:04:04 -0800 | [diff] [blame] | 313 | |
Daniel Sandler | 231d880 | 2010-02-17 15:35:21 -0500 | [diff] [blame] | 314 | } else if (preference == mLockSounds) { |
| 315 | Settings.System.putInt(getContentResolver(), Settings.System.LOCKSCREEN_SOUNDS_ENABLED, |
| 316 | mLockSounds.isChecked() ? 1 : 0); |
| 317 | |
Marco Nelissen | 6eca4b3 | 2011-07-15 15:02:03 -0700 | [diff] [blame] | 318 | } else if (preference == mMusicFx) { |
| 319 | // let the framework fire off the intent |
| 320 | return false; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 321 | } |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 322 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 323 | return true; |
| 324 | } |
| 325 | |
| 326 | public boolean onPreferenceChange(Preference preference, Object objValue) { |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 327 | final String key = preference.getKey(); |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 328 | if (KEY_EMERGENCY_TONE.equals(key)) { |
Chouting Zhang | 386278a | 2009-06-24 14:25:43 -0500 | [diff] [blame] | 329 | try { |
Peter Kuterna | 378b6f6 | 2010-11-28 22:35:31 +0100 | [diff] [blame] | 330 | int value = Integer.parseInt((String) objValue); |
Chouting Zhang | 386278a | 2009-06-24 14:25:43 -0500 | [diff] [blame] | 331 | Settings.System.putInt(getContentResolver(), |
| 332 | Settings.System.EMERGENCY_TONE, value); |
| 333 | } catch (NumberFormatException e) { |
| 334 | Log.e(TAG, "could not persist emergency tone setting", e); |
| 335 | } |
Amith Yamasani | dfb6543 | 2011-11-29 16:38:14 -0800 | [diff] [blame] | 336 | } else if (preference == mSilentMode) { |
| 337 | setPhoneSilentSettingValue(objValue.toString()); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 338 | } |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 339 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 340 | return true; |
| 341 | } |
Amith Yamasani | b0b37ae | 2012-04-23 15:35:36 -0700 | [diff] [blame^] | 342 | |
| 343 | @Override |
| 344 | protected int getHelpResource() { |
| 345 | return R.string.help_url_sound; |
| 346 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 347 | } |