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