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