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; |
| 24 | import android.media.AudioManager; |
| 25 | import android.os.Bundle; |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 26 | import android.preference.CheckBoxPreference; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 27 | import android.preference.ListPreference; |
| 28 | import android.preference.Preference; |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 29 | import android.preference.PreferenceGroup; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 30 | import android.preference.PreferenceScreen; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 31 | import android.provider.Settings; |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 32 | import android.provider.Settings.SettingNotFoundException; |
| 33 | import android.telephony.TelephonyManager; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 34 | import android.util.Log; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 35 | |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 36 | public class SoundSettings extends SettingsPreferenceFragment implements |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 37 | Preference.OnPreferenceChangeListener { |
| 38 | private static final String TAG = "SoundAndDisplaysSettings"; |
| 39 | |
| 40 | /** If there is no setting in the provider, use this. */ |
Chouting Zhang | 386278a | 2009-06-24 14:25:43 -0500 | [diff] [blame] | 41 | private static final int FALLBACK_EMERGENCY_TONE_VALUE = 0; |
Michael Chan | df9504e | 2009-12-06 01:04:04 -0800 | [diff] [blame] | 42 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 43 | private static final String KEY_SILENT = "silent"; |
| 44 | private static final String KEY_VIBRATE = "vibrate"; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 45 | private static final String KEY_DTMF_TONE = "dtmf_tone"; |
| 46 | private static final String KEY_SOUND_EFFECTS = "sound_effects"; |
Dan Murphy | 22e1868 | 2009-09-22 11:47:08 -0500 | [diff] [blame] | 47 | private static final String KEY_HAPTIC_FEEDBACK = "haptic_feedback"; |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 48 | private static final String KEY_EMERGENCY_TONE = "emergency_tone"; |
| 49 | private static final String KEY_SOUND_SETTINGS = "sound_settings"; |
| 50 | private static final String KEY_NOTIFICATION_PULSE = "notification_pulse"; |
Daniel Sandler | 231d880 | 2010-02-17 15:35:21 -0500 | [diff] [blame] | 51 | private static final String KEY_LOCK_SOUNDS = "lock_sounds"; |
Amith Yamasani | 60133dd | 2010-09-11 14:17:31 -0700 | [diff] [blame^] | 52 | private static final String KEY_RINGTONE = "ringtone"; |
| 53 | private static final String KEY_NOTIFICATION_SOUND = "notification_sound"; |
| 54 | private static final String KEY_CATEGORY_CALLS = "category_calls"; |
| 55 | private static final String KEY_CATEGORY_NOTIFICATION = "category_notification"; |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 56 | |
Daniel Sandler | 2c91784 | 2010-04-21 15:24:24 -0400 | [diff] [blame] | 57 | private static final String VALUE_VIBRATE_NEVER = "never"; |
| 58 | private static final String VALUE_VIBRATE_ALWAYS = "always"; |
| 59 | private static final String VALUE_VIBRATE_ONLY_SILENT = "silent"; |
| 60 | private static final String VALUE_VIBRATE_UNLESS_SILENT = "notsilent"; |
| 61 | |
Amith Yamasani | 60133dd | 2010-09-11 14:17:31 -0700 | [diff] [blame^] | 62 | private static final String[] NEED_VOICE_CAPABILITY = { |
| 63 | KEY_RINGTONE, KEY_DTMF_TONE, KEY_CATEGORY_CALLS, |
| 64 | KEY_EMERGENCY_TONE |
| 65 | }; |
| 66 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 67 | private CheckBoxPreference mSilent; |
| 68 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 69 | /* |
| 70 | * If we are currently in one of the silent modes (the ringer mode is set to either |
| 71 | * "silent mode" or "vibrate mode"), then toggling the "Phone vibrate" |
| 72 | * preference will switch between "silent mode" and "vibrate mode". |
| 73 | * Otherwise, it will adjust the normal ringer mode's ring or ring+vibrate |
| 74 | * setting. |
| 75 | */ |
Daniel Sandler | 2c91784 | 2010-04-21 15:24:24 -0400 | [diff] [blame] | 76 | private ListPreference mVibrate; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 77 | private CheckBoxPreference mDtmfTone; |
| 78 | private CheckBoxPreference mSoundEffects; |
Dan Murphy | 22e1868 | 2009-09-22 11:47:08 -0500 | [diff] [blame] | 79 | private CheckBoxPreference mHapticFeedback; |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 80 | private CheckBoxPreference mNotificationPulse; |
Daniel Sandler | 231d880 | 2010-02-17 15:35:21 -0500 | [diff] [blame] | 81 | private CheckBoxPreference mLockSounds; |
Michael Chan | df9504e | 2009-12-06 01:04:04 -0800 | [diff] [blame] | 82 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 83 | private AudioManager mAudioManager; |
Michael Chan | df9504e | 2009-12-06 01:04:04 -0800 | [diff] [blame] | 84 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 85 | private BroadcastReceiver mReceiver = new BroadcastReceiver() { |
| 86 | @Override |
| 87 | public void onReceive(Context context, Intent intent) { |
Amith Yamasani | d2b3ab0 | 2009-12-02 13:56:05 -0800 | [diff] [blame] | 88 | if (intent.getAction().equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) { |
| 89 | updateState(false); |
Amith Yamasani | d2b3ab0 | 2009-12-02 13:56:05 -0800 | [diff] [blame] | 90 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 91 | } |
| 92 | }; |
| 93 | |
Amith Yamasani | d2b3ab0 | 2009-12-02 13:56:05 -0800 | [diff] [blame] | 94 | private PreferenceGroup mSoundSettings; |
| 95 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 96 | @Override |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 97 | public void onCreate(Bundle savedInstanceState) { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 98 | super.onCreate(savedInstanceState); |
| 99 | ContentResolver resolver = getContentResolver(); |
Chouting Zhang | 386278a | 2009-06-24 14:25:43 -0500 | [diff] [blame] | 100 | int activePhoneType = TelephonyManager.getDefault().getPhoneType(); |
Michael Chan | df9504e | 2009-12-06 01:04:04 -0800 | [diff] [blame] | 101 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 102 | mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 103 | |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 104 | addPreferencesFromResource(R.xml.sound_settings); |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 105 | |
Chouting Zhang | 386278a | 2009-06-24 14:25:43 -0500 | [diff] [blame] | 106 | if (TelephonyManager.PHONE_TYPE_CDMA != activePhoneType) { |
| 107 | // device is not CDMA, do not display CDMA emergency_tone |
| 108 | getPreferenceScreen().removePreference(findPreference(KEY_EMERGENCY_TONE)); |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 109 | } |
Chouting Zhang | 386278a | 2009-06-24 14:25:43 -0500 | [diff] [blame] | 110 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 111 | mSilent = (CheckBoxPreference) findPreference(KEY_SILENT); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 112 | |
Daniel Sandler | 2c91784 | 2010-04-21 15:24:24 -0400 | [diff] [blame] | 113 | mVibrate = (ListPreference) findPreference(KEY_VIBRATE); |
| 114 | mVibrate.setOnPreferenceChangeListener(this); |
Daniel Sandler | 4ce4f75 | 2010-03-08 15:08:34 -0500 | [diff] [blame] | 115 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 116 | mDtmfTone = (CheckBoxPreference) findPreference(KEY_DTMF_TONE); |
| 117 | mDtmfTone.setPersistent(false); |
| 118 | mDtmfTone.setChecked(Settings.System.getInt(resolver, |
| 119 | Settings.System.DTMF_TONE_WHEN_DIALING, 1) != 0); |
| 120 | mSoundEffects = (CheckBoxPreference) findPreference(KEY_SOUND_EFFECTS); |
| 121 | mSoundEffects.setPersistent(false); |
| 122 | mSoundEffects.setChecked(Settings.System.getInt(resolver, |
| 123 | Settings.System.SOUND_EFFECTS_ENABLED, 0) != 0); |
Dan Murphy | 22e1868 | 2009-09-22 11:47:08 -0500 | [diff] [blame] | 124 | mHapticFeedback = (CheckBoxPreference) findPreference(KEY_HAPTIC_FEEDBACK); |
| 125 | mHapticFeedback.setPersistent(false); |
| 126 | mHapticFeedback.setChecked(Settings.System.getInt(resolver, |
| 127 | Settings.System.HAPTIC_FEEDBACK_ENABLED, 0) != 0); |
Daniel Sandler | 231d880 | 2010-02-17 15:35:21 -0500 | [diff] [blame] | 128 | mLockSounds = (CheckBoxPreference) findPreference(KEY_LOCK_SOUNDS); |
| 129 | mLockSounds.setPersistent(false); |
| 130 | mLockSounds.setChecked(Settings.System.getInt(resolver, |
| 131 | Settings.System.LOCKSCREEN_SOUNDS_ENABLED, 1) != 0); |
Chouting Zhang | 386278a | 2009-06-24 14:25:43 -0500 | [diff] [blame] | 132 | |
| 133 | if (TelephonyManager.PHONE_TYPE_CDMA == activePhoneType) { |
| 134 | ListPreference emergencyTonePreference = |
| 135 | (ListPreference) findPreference(KEY_EMERGENCY_TONE); |
| 136 | emergencyTonePreference.setValue(String.valueOf(Settings.System.getInt( |
| 137 | resolver, Settings.System.EMERGENCY_TONE, FALLBACK_EMERGENCY_TONE_VALUE))); |
| 138 | emergencyTonePreference.setOnPreferenceChangeListener(this); |
| 139 | } |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 140 | |
Amith Yamasani | d2b3ab0 | 2009-12-02 13:56:05 -0800 | [diff] [blame] | 141 | mSoundSettings = (PreferenceGroup) findPreference(KEY_SOUND_SETTINGS); |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 142 | mNotificationPulse = (CheckBoxPreference) |
Amith Yamasani | d2b3ab0 | 2009-12-02 13:56:05 -0800 | [diff] [blame] | 143 | mSoundSettings.findPreference(KEY_NOTIFICATION_PULSE); |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 144 | if (mNotificationPulse != null |
| 145 | && getResources().getBoolean(R.bool.has_intrusive_led) == false) { |
Amith Yamasani | d2b3ab0 | 2009-12-02 13:56:05 -0800 | [diff] [blame] | 146 | mSoundSettings.removePreference(mNotificationPulse); |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 147 | } else { |
| 148 | try { |
| 149 | mNotificationPulse.setChecked(Settings.System.getInt(resolver, |
| 150 | Settings.System.NOTIFICATION_LIGHT_PULSE) == 1); |
| 151 | mNotificationPulse.setOnPreferenceChangeListener(this); |
| 152 | } catch (SettingNotFoundException snfe) { |
| 153 | Log.e(TAG, Settings.System.NOTIFICATION_LIGHT_PULSE + " not found"); |
| 154 | } |
| 155 | } |
Amith Yamasani | d2b3ab0 | 2009-12-02 13:56:05 -0800 | [diff] [blame] | 156 | |
Amith Yamasani | 60133dd | 2010-09-11 14:17:31 -0700 | [diff] [blame^] | 157 | if (!Utils.isVoiceCapable(getActivity())) { |
| 158 | for (String prefKey : NEED_VOICE_CAPABILITY) { |
| 159 | Preference pref = findPreference(prefKey); |
| 160 | if (pref != null) { |
| 161 | getPreferenceScreen().removePreference(pref); |
| 162 | } |
| 163 | } |
| 164 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 165 | } |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 166 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 167 | @Override |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 168 | public void onResume() { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 169 | super.onResume(); |
Michael Chan | df9504e | 2009-12-06 01:04:04 -0800 | [diff] [blame] | 170 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 171 | updateState(true); |
Michael Chan | df9504e | 2009-12-06 01:04:04 -0800 | [diff] [blame] | 172 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 173 | IntentFilter filter = new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION); |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 174 | getActivity().registerReceiver(mReceiver, filter); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | @Override |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 178 | public void onPause() { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 179 | super.onPause(); |
| 180 | |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 181 | getActivity().unregisterReceiver(mReceiver); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 182 | } |
| 183 | |
Daniel Sandler | 2c91784 | 2010-04-21 15:24:24 -0400 | [diff] [blame] | 184 | private String getPhoneVibrateSettingValue() { |
| 185 | boolean vibeInSilent = (Settings.System.getInt( |
| 186 | getContentResolver(), |
| 187 | Settings.System.VIBRATE_IN_SILENT, |
| 188 | 1) == 1); |
| 189 | |
| 190 | // Control phone vibe independent of silent mode |
| 191 | int callsVibrateSetting = |
| 192 | mAudioManager.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER); |
| 193 | |
| 194 | if (vibeInSilent) { |
| 195 | if (callsVibrateSetting == AudioManager.VIBRATE_SETTING_OFF) { |
| 196 | // this state does not make sense; fix it up for the user |
| 197 | mAudioManager.setVibrateSetting( |
| 198 | AudioManager.VIBRATE_TYPE_RINGER, |
| 199 | AudioManager.VIBRATE_SETTING_ONLY_SILENT); |
| 200 | } |
| 201 | if (callsVibrateSetting == AudioManager.VIBRATE_SETTING_ON) { |
| 202 | return VALUE_VIBRATE_ALWAYS; |
| 203 | } else { |
| 204 | return VALUE_VIBRATE_ONLY_SILENT; |
| 205 | } |
| 206 | } else { |
| 207 | if (callsVibrateSetting == AudioManager.VIBRATE_SETTING_ONLY_SILENT) { |
| 208 | // this state does not make sense; fix it up |
| 209 | mAudioManager.setVibrateSetting( |
| 210 | AudioManager.VIBRATE_TYPE_RINGER, |
| 211 | AudioManager.VIBRATE_SETTING_OFF); |
| 212 | } |
| 213 | if (callsVibrateSetting == AudioManager.VIBRATE_SETTING_ON) { |
| 214 | return VALUE_VIBRATE_UNLESS_SILENT; |
| 215 | } else { |
| 216 | return VALUE_VIBRATE_NEVER; |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | private void setPhoneVibrateSettingValue(String value) { |
| 222 | boolean vibeInSilent; |
| 223 | int callsVibrateSetting; |
| 224 | |
| 225 | if (value.equals(VALUE_VIBRATE_UNLESS_SILENT)) { |
| 226 | callsVibrateSetting = AudioManager.VIBRATE_SETTING_ON; |
| 227 | vibeInSilent = false; |
| 228 | } else if (value.equals(VALUE_VIBRATE_NEVER)) { |
| 229 | callsVibrateSetting = AudioManager.VIBRATE_SETTING_OFF; |
| 230 | vibeInSilent = false; |
| 231 | } else if (value.equals(VALUE_VIBRATE_ONLY_SILENT)) { |
| 232 | callsVibrateSetting = AudioManager.VIBRATE_SETTING_ONLY_SILENT; |
| 233 | vibeInSilent = true; |
| 234 | } else { //VALUE_VIBRATE_ALWAYS |
| 235 | callsVibrateSetting = AudioManager.VIBRATE_SETTING_ON; |
| 236 | vibeInSilent = true; |
| 237 | } |
| 238 | |
| 239 | Settings.System.putInt(getContentResolver(), |
| 240 | Settings.System.VIBRATE_IN_SILENT, |
| 241 | vibeInSilent ? 1 : 0); |
| 242 | |
| 243 | // might need to switch the ringer mode from one kind of "silent" to |
| 244 | // another |
| 245 | if (mSilent.isChecked()) { |
| 246 | mAudioManager.setRingerMode( |
| 247 | vibeInSilent ? AudioManager.RINGER_MODE_VIBRATE |
| 248 | : AudioManager.RINGER_MODE_SILENT); |
| 249 | } |
| 250 | |
| 251 | mAudioManager.setVibrateSetting( |
| 252 | AudioManager.VIBRATE_TYPE_RINGER, |
| 253 | callsVibrateSetting); |
| 254 | } |
| 255 | |
Daniel Sandler | 58cf829 | 2010-02-26 15:25:04 -0500 | [diff] [blame] | 256 | // 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] | 257 | private void updateState(boolean force) { |
| 258 | final int ringerMode = mAudioManager.getRingerMode(); |
Daniel Sandler | 58cf829 | 2010-02-26 15:25:04 -0500 | [diff] [blame] | 259 | |
| 260 | // NB: in the UI we now simply call this "silent mode". A separate |
| 261 | // setting controls whether we're in RINGER_MODE_SILENT or |
| 262 | // RINGER_MODE_VIBRATE. |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 263 | final boolean silentOrVibrateMode = |
| 264 | ringerMode != AudioManager.RINGER_MODE_NORMAL; |
Michael Chan | df9504e | 2009-12-06 01:04:04 -0800 | [diff] [blame] | 265 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 266 | if (silentOrVibrateMode != mSilent.isChecked() || force) { |
| 267 | mSilent.setChecked(silentOrVibrateMode); |
| 268 | } |
| 269 | |
Daniel Sandler | 2c91784 | 2010-04-21 15:24:24 -0400 | [diff] [blame] | 270 | String phoneVibrateSetting = getPhoneVibrateSettingValue(); |
Daniel Sandler | 58cf829 | 2010-02-26 15:25:04 -0500 | [diff] [blame] | 271 | |
Daniel Sandler | 2c91784 | 2010-04-21 15:24:24 -0400 | [diff] [blame] | 272 | if (! phoneVibrateSetting.equals(mVibrate.getValue()) || force) { |
| 273 | mVibrate.setValue(phoneVibrateSetting); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 274 | } |
Daniel Sandler | 2c91784 | 2010-04-21 15:24:24 -0400 | [diff] [blame] | 275 | mVibrate.setSummary(mVibrate.getEntry()); |
Michael Chan | df9504e | 2009-12-06 01:04:04 -0800 | [diff] [blame] | 276 | |
Jason Parekh | 2c9b326 | 2009-03-24 17:48:28 -0700 | [diff] [blame] | 277 | int silentModeStreams = Settings.System.getInt(getContentResolver(), |
| 278 | Settings.System.MODE_RINGER_STREAMS_AFFECTED, 0); |
Michael Chan | df9504e | 2009-12-06 01:04:04 -0800 | [diff] [blame] | 279 | boolean isAlarmInclSilentMode = (silentModeStreams & (1 << AudioManager.STREAM_ALARM)) != 0; |
Jason Parekh | 2c9b326 | 2009-03-24 17:48:28 -0700 | [diff] [blame] | 280 | mSilent.setSummary(isAlarmInclSilentMode ? |
| 281 | R.string.silent_mode_incl_alarm_summary : |
| 282 | R.string.silent_mode_summary); |
Dianne Hackborn | 7631539 | 2009-09-03 13:33:55 -0700 | [diff] [blame] | 283 | } |
Michael Chan | df9504e | 2009-12-06 01:04:04 -0800 | [diff] [blame] | 284 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 285 | @Override |
| 286 | public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { |
Daniel Sandler | 58cf829 | 2010-02-26 15:25:04 -0500 | [diff] [blame] | 287 | if (preference == mSilent) { |
| 288 | if (mSilent.isChecked()) { |
Daniel Sandler | 2c91784 | 2010-04-21 15:24:24 -0400 | [diff] [blame] | 289 | boolean vibeInSilent = (1 == Settings.System.getInt( |
| 290 | getContentResolver(), |
| 291 | Settings.System.VIBRATE_IN_SILENT, |
| 292 | 1)); |
Daniel Sandler | 58cf829 | 2010-02-26 15:25:04 -0500 | [diff] [blame] | 293 | mAudioManager.setRingerMode( |
| 294 | vibeInSilent ? AudioManager.RINGER_MODE_VIBRATE |
| 295 | : AudioManager.RINGER_MODE_SILENT); |
| 296 | } else { |
| 297 | mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); |
| 298 | } |
| 299 | updateState(false); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 300 | } else if (preference == mDtmfTone) { |
| 301 | Settings.System.putInt(getContentResolver(), Settings.System.DTMF_TONE_WHEN_DIALING, |
| 302 | mDtmfTone.isChecked() ? 1 : 0); |
Michael Chan | df9504e | 2009-12-06 01:04:04 -0800 | [diff] [blame] | 303 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 304 | } else if (preference == mSoundEffects) { |
| 305 | if (mSoundEffects.isChecked()) { |
| 306 | mAudioManager.loadSoundEffects(); |
| 307 | } else { |
| 308 | mAudioManager.unloadSoundEffects(); |
| 309 | } |
| 310 | Settings.System.putInt(getContentResolver(), Settings.System.SOUND_EFFECTS_ENABLED, |
| 311 | mSoundEffects.isChecked() ? 1 : 0); |
Dan Murphy | 22e1868 | 2009-09-22 11:47:08 -0500 | [diff] [blame] | 312 | |
| 313 | } else if (preference == mHapticFeedback) { |
| 314 | Settings.System.putInt(getContentResolver(), Settings.System.HAPTIC_FEEDBACK_ENABLED, |
| 315 | mHapticFeedback.isChecked() ? 1 : 0); |
Michael Chan | df9504e | 2009-12-06 01:04:04 -0800 | [diff] [blame] | 316 | |
Daniel Sandler | 231d880 | 2010-02-17 15:35:21 -0500 | [diff] [blame] | 317 | } else if (preference == mLockSounds) { |
| 318 | Settings.System.putInt(getContentResolver(), Settings.System.LOCKSCREEN_SOUNDS_ENABLED, |
| 319 | mLockSounds.isChecked() ? 1 : 0); |
| 320 | |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 321 | } else if (preference == mNotificationPulse) { |
| 322 | boolean value = mNotificationPulse.isChecked(); |
| 323 | Settings.System.putInt(getContentResolver(), |
| 324 | Settings.System.NOTIFICATION_LIGHT_PULSE, value ? 1 : 0); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 325 | } |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 326 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 327 | return true; |
| 328 | } |
| 329 | |
| 330 | public boolean onPreferenceChange(Preference preference, Object objValue) { |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 331 | final String key = preference.getKey(); |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 332 | if (KEY_EMERGENCY_TONE.equals(key)) { |
Chouting Zhang | 386278a | 2009-06-24 14:25:43 -0500 | [diff] [blame] | 333 | int value = Integer.parseInt((String) objValue); |
| 334 | try { |
| 335 | Settings.System.putInt(getContentResolver(), |
| 336 | Settings.System.EMERGENCY_TONE, value); |
| 337 | } catch (NumberFormatException e) { |
| 338 | Log.e(TAG, "could not persist emergency tone setting", e); |
| 339 | } |
Daniel Sandler | 2c91784 | 2010-04-21 15:24:24 -0400 | [diff] [blame] | 340 | } else if (preference == mVibrate) { |
| 341 | setPhoneVibrateSettingValue(objValue.toString()); |
| 342 | updateState(false); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 343 | } |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 344 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 345 | return true; |
| 346 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 347 | } |