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