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 | |
| 19 | import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 20 | import android.content.BroadcastReceiver; |
| 21 | import android.content.ContentResolver; |
| 22 | import android.content.Context; |
| 23 | import android.content.Intent; |
| 24 | import android.content.IntentFilter; |
| 25 | import android.media.AudioManager; |
| 26 | import android.os.Bundle; |
| 27 | import android.os.IMountService; |
| 28 | import android.os.RemoteException; |
| 29 | import android.os.ServiceManager; |
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; |
| 33 | import android.preference.PreferenceActivity; |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 34 | import android.preference.PreferenceGroup; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 35 | import android.preference.PreferenceScreen; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 36 | import android.provider.Settings; |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 37 | import android.provider.Settings.SettingNotFoundException; |
| 38 | import android.telephony.TelephonyManager; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 39 | import android.util.Log; |
| 40 | import android.view.IWindowManager; |
| 41 | |
| 42 | public class SoundAndDisplaySettings extends PreferenceActivity implements |
| 43 | Preference.OnPreferenceChangeListener { |
| 44 | private static final String TAG = "SoundAndDisplaysSettings"; |
| 45 | |
| 46 | /** If there is no setting in the provider, use this. */ |
| 47 | private static final int FALLBACK_SCREEN_TIMEOUT_VALUE = 30000; |
Chouting Zhang | 386278a | 2009-06-24 14:25:43 -0500 | [diff] [blame] | 48 | private static final int FALLBACK_EMERGENCY_TONE_VALUE = 0; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 49 | |
| 50 | private static final String KEY_SILENT = "silent"; |
| 51 | private static final String KEY_VIBRATE = "vibrate"; |
| 52 | private static final String KEY_SCREEN_TIMEOUT = "screen_timeout"; |
| 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"; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 56 | private static final String KEY_ANIMATIONS = "animations"; |
The Android Open Source Project | 648bf5f | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 57 | private static final String KEY_ACCELEROMETER = "accelerometer"; |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 58 | private static final String KEY_PLAY_MEDIA_NOTIFICATION_SOUNDS = |
| 59 | "play_media_notification_sounds"; |
| 60 | private static final String KEY_EMERGENCY_TONE = "emergency_tone"; |
| 61 | private static final String KEY_SOUND_SETTINGS = "sound_settings"; |
| 62 | private static final String KEY_NOTIFICATION_PULSE = "notification_pulse"; |
Amith Yamasani | d2b3ab0 | 2009-12-02 13:56:05 -0800 | [diff] [blame^] | 63 | private static final String KEY_DOCK_SETTINGS = "dock_settings"; |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 64 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 65 | private CheckBoxPreference mSilent; |
| 66 | |
| 67 | private CheckBoxPreference mPlayMediaNotificationSounds; |
| 68 | |
Amith Yamasani | d2b3ab0 | 2009-12-02 13:56:05 -0800 | [diff] [blame^] | 69 | private Preference mDockSettings; |
| 70 | private boolean mHasDockSettings; |
| 71 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 72 | private IMountService mMountService = null; |
| 73 | |
| 74 | /* |
| 75 | * If we are currently in one of the silent modes (the ringer mode is set to either |
| 76 | * "silent mode" or "vibrate mode"), then toggling the "Phone vibrate" |
| 77 | * preference will switch between "silent mode" and "vibrate mode". |
| 78 | * Otherwise, it will adjust the normal ringer mode's ring or ring+vibrate |
| 79 | * setting. |
| 80 | */ |
| 81 | private CheckBoxPreference mVibrate; |
| 82 | private CheckBoxPreference mDtmfTone; |
| 83 | private CheckBoxPreference mSoundEffects; |
Dan Murphy | 22e1868 | 2009-09-22 11:47:08 -0500 | [diff] [blame] | 84 | private CheckBoxPreference mHapticFeedback; |
Dianne Hackborn | 7631539 | 2009-09-03 13:33:55 -0700 | [diff] [blame] | 85 | private ListPreference mAnimations; |
The Android Open Source Project | 648bf5f | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 86 | private CheckBoxPreference mAccelerometer; |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 87 | private CheckBoxPreference mNotificationPulse; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 88 | private float[] mAnimationScales; |
| 89 | |
| 90 | private AudioManager mAudioManager; |
| 91 | |
| 92 | private IWindowManager mWindowManager; |
| 93 | |
| 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); |
| 99 | } else if (intent.getAction().equals(Intent.ACTION_DOCK_EVENT)) { |
| 100 | handleDockChange(intent); |
| 101 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 102 | } |
| 103 | }; |
| 104 | |
Amith Yamasani | d2b3ab0 | 2009-12-02 13:56:05 -0800 | [diff] [blame^] | 105 | private PreferenceGroup mSoundSettings; |
| 106 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 107 | @Override |
| 108 | protected void onCreate(Bundle savedInstanceState) { |
| 109 | super.onCreate(savedInstanceState); |
| 110 | ContentResolver resolver = getContentResolver(); |
Chouting Zhang | 386278a | 2009-06-24 14:25:43 -0500 | [diff] [blame] | 111 | int activePhoneType = TelephonyManager.getDefault().getPhoneType(); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 112 | |
| 113 | mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); |
| 114 | mWindowManager = IWindowManager.Stub.asInterface(ServiceManager.getService("window")); |
| 115 | |
| 116 | mMountService = IMountService.Stub.asInterface(ServiceManager.getService("mount")); |
| 117 | |
| 118 | addPreferencesFromResource(R.xml.sound_and_display_settings); |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 119 | |
Chouting Zhang | 386278a | 2009-06-24 14:25:43 -0500 | [diff] [blame] | 120 | if (TelephonyManager.PHONE_TYPE_CDMA != activePhoneType) { |
| 121 | // device is not CDMA, do not display CDMA emergency_tone |
| 122 | getPreferenceScreen().removePreference(findPreference(KEY_EMERGENCY_TONE)); |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 123 | } |
Chouting Zhang | 386278a | 2009-06-24 14:25:43 -0500 | [diff] [blame] | 124 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 125 | mSilent = (CheckBoxPreference) findPreference(KEY_SILENT); |
| 126 | mPlayMediaNotificationSounds = (CheckBoxPreference) findPreference(KEY_PLAY_MEDIA_NOTIFICATION_SOUNDS); |
| 127 | |
| 128 | mVibrate = (CheckBoxPreference) findPreference(KEY_VIBRATE); |
| 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); |
Dianne Hackborn | 7631539 | 2009-09-03 13:33:55 -0700 | [diff] [blame] | 141 | mAnimations = (ListPreference) findPreference(KEY_ANIMATIONS); |
| 142 | mAnimations.setOnPreferenceChangeListener(this); |
The Android Open Source Project | 648bf5f | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 143 | mAccelerometer = (CheckBoxPreference) findPreference(KEY_ACCELEROMETER); |
| 144 | mAccelerometer.setPersistent(false); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 145 | |
| 146 | ListPreference screenTimeoutPreference = |
| 147 | (ListPreference) findPreference(KEY_SCREEN_TIMEOUT); |
| 148 | screenTimeoutPreference.setValue(String.valueOf(Settings.System.getInt( |
| 149 | resolver, SCREEN_OFF_TIMEOUT, FALLBACK_SCREEN_TIMEOUT_VALUE))); |
| 150 | screenTimeoutPreference.setOnPreferenceChangeListener(this); |
Chouting Zhang | 386278a | 2009-06-24 14:25:43 -0500 | [diff] [blame] | 151 | |
| 152 | if (TelephonyManager.PHONE_TYPE_CDMA == activePhoneType) { |
| 153 | ListPreference emergencyTonePreference = |
| 154 | (ListPreference) findPreference(KEY_EMERGENCY_TONE); |
| 155 | emergencyTonePreference.setValue(String.valueOf(Settings.System.getInt( |
| 156 | resolver, Settings.System.EMERGENCY_TONE, FALLBACK_EMERGENCY_TONE_VALUE))); |
| 157 | emergencyTonePreference.setOnPreferenceChangeListener(this); |
| 158 | } |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 159 | |
Amith Yamasani | d2b3ab0 | 2009-12-02 13:56:05 -0800 | [diff] [blame^] | 160 | mSoundSettings = (PreferenceGroup) findPreference(KEY_SOUND_SETTINGS); |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 161 | mNotificationPulse = (CheckBoxPreference) |
Amith Yamasani | d2b3ab0 | 2009-12-02 13:56:05 -0800 | [diff] [blame^] | 162 | mSoundSettings.findPreference(KEY_NOTIFICATION_PULSE); |
| 163 | if (mNotificationPulse != null && |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 164 | getResources().getBoolean(R.bool.has_intrusive_led) == false) { |
Amith Yamasani | d2b3ab0 | 2009-12-02 13:56:05 -0800 | [diff] [blame^] | 165 | mSoundSettings.removePreference(mNotificationPulse); |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 166 | } else { |
| 167 | try { |
| 168 | mNotificationPulse.setChecked(Settings.System.getInt(resolver, |
| 169 | Settings.System.NOTIFICATION_LIGHT_PULSE) == 1); |
| 170 | mNotificationPulse.setOnPreferenceChangeListener(this); |
| 171 | } catch (SettingNotFoundException snfe) { |
| 172 | Log.e(TAG, Settings.System.NOTIFICATION_LIGHT_PULSE + " not found"); |
| 173 | } |
| 174 | } |
Amith Yamasani | d2b3ab0 | 2009-12-02 13:56:05 -0800 | [diff] [blame^] | 175 | |
| 176 | initDockSettings(); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 177 | } |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 178 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 179 | @Override |
| 180 | protected void onResume() { |
| 181 | super.onResume(); |
| 182 | |
| 183 | updateState(true); |
| 184 | |
| 185 | IntentFilter filter = new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION); |
Amith Yamasani | d2b3ab0 | 2009-12-02 13:56:05 -0800 | [diff] [blame^] | 186 | if (mHasDockSettings) { |
| 187 | if (mDockSettings != null) { |
| 188 | mSoundSettings.removePreference(mDockSettings); |
| 189 | } |
| 190 | filter.addAction(Intent.ACTION_DOCK_EVENT); |
| 191 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 192 | registerReceiver(mReceiver, filter); |
| 193 | } |
| 194 | |
| 195 | @Override |
| 196 | protected void onPause() { |
| 197 | super.onPause(); |
| 198 | |
| 199 | unregisterReceiver(mReceiver); |
| 200 | } |
| 201 | |
Amith Yamasani | d2b3ab0 | 2009-12-02 13:56:05 -0800 | [diff] [blame^] | 202 | private void initDockSettings() { |
| 203 | mDockSettings = mSoundSettings.findPreference(KEY_DOCK_SETTINGS); |
| 204 | mHasDockSettings = getResources().getBoolean(R.bool.has_dock_settings); |
| 205 | if (mDockSettings != null) { |
| 206 | mSoundSettings.removePreference(mDockSettings); |
| 207 | // Don't care even if we dock |
| 208 | if (getResources().getBoolean(R.bool.has_dock_settings) == false) { |
| 209 | mDockSettings = null; |
| 210 | } |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | private void handleDockChange(Intent intent) { |
| 215 | if (mHasDockSettings && mDockSettings != null) { |
| 216 | int dockState = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, 0); |
| 217 | if (dockState != Intent.EXTRA_DOCK_STATE_UNDOCKED) { |
| 218 | // Show dock settings item |
| 219 | mSoundSettings.addPreference(mDockSettings); |
| 220 | } else { |
| 221 | // Remove dock settings item |
| 222 | mSoundSettings.removePreference(mDockSettings); |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 227 | private void updateState(boolean force) { |
| 228 | final int ringerMode = mAudioManager.getRingerMode(); |
| 229 | final boolean silentOrVibrateMode = |
| 230 | ringerMode != AudioManager.RINGER_MODE_NORMAL; |
| 231 | |
| 232 | if (silentOrVibrateMode != mSilent.isChecked() || force) { |
| 233 | mSilent.setChecked(silentOrVibrateMode); |
| 234 | } |
| 235 | |
| 236 | try { |
| 237 | mPlayMediaNotificationSounds.setChecked(mMountService.getPlayNotificationSounds()); |
| 238 | } catch (RemoteException e) { |
| 239 | } |
| 240 | |
| 241 | boolean vibrateSetting; |
| 242 | if (silentOrVibrateMode) { |
| 243 | vibrateSetting = ringerMode == AudioManager.RINGER_MODE_VIBRATE; |
| 244 | } else { |
| 245 | vibrateSetting = mAudioManager.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER) |
| 246 | == AudioManager.VIBRATE_SETTING_ON; |
| 247 | } |
| 248 | if (vibrateSetting != mVibrate.isChecked() || force) { |
| 249 | mVibrate.setChecked(vibrateSetting); |
| 250 | } |
| 251 | |
Jason Parekh | 2c9b326 | 2009-03-24 17:48:28 -0700 | [diff] [blame] | 252 | int silentModeStreams = Settings.System.getInt(getContentResolver(), |
| 253 | Settings.System.MODE_RINGER_STREAMS_AFFECTED, 0); |
| 254 | boolean isAlarmInclSilentMode = (silentModeStreams & (1 << AudioManager.STREAM_ALARM)) != 0; |
| 255 | mSilent.setSummary(isAlarmInclSilentMode ? |
| 256 | R.string.silent_mode_incl_alarm_summary : |
| 257 | R.string.silent_mode_summary); |
| 258 | |
Dianne Hackborn | 7631539 | 2009-09-03 13:33:55 -0700 | [diff] [blame] | 259 | int animations = 0; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 260 | try { |
| 261 | mAnimationScales = mWindowManager.getAnimationScales(); |
| 262 | } catch (RemoteException e) { |
| 263 | } |
| 264 | if (mAnimationScales != null) { |
Dianne Hackborn | 7631539 | 2009-09-03 13:33:55 -0700 | [diff] [blame] | 265 | if (mAnimationScales.length >= 1) { |
| 266 | animations = ((int)(mAnimationScales[0]+.5f)) % 10; |
| 267 | } |
| 268 | if (mAnimationScales.length >= 2) { |
| 269 | animations += (((int)(mAnimationScales[1]+.5f)) & 0x7) * 10; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 270 | } |
| 271 | } |
Dianne Hackborn | 7631539 | 2009-09-03 13:33:55 -0700 | [diff] [blame] | 272 | int idx = 0; |
| 273 | int best = 0; |
| 274 | CharSequence[] aents = mAnimations.getEntryValues(); |
| 275 | for (int i=0; i<aents.length; i++) { |
| 276 | int val = Integer.parseInt(aents[i].toString()); |
| 277 | if (val <= animations && val > best) { |
| 278 | best = val; |
| 279 | idx = i; |
| 280 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 281 | } |
Dianne Hackborn | 7631539 | 2009-09-03 13:33:55 -0700 | [diff] [blame] | 282 | mAnimations.setValueIndex(idx); |
| 283 | updateAnimationsSummary(mAnimations.getValue()); |
The Android Open Source Project | 648bf5f | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 284 | mAccelerometer.setChecked(Settings.System.getInt( |
| 285 | getContentResolver(), |
| 286 | Settings.System.ACCELEROMETER_ROTATION, 0) != 0); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 287 | } |
| 288 | |
Dianne Hackborn | 7631539 | 2009-09-03 13:33:55 -0700 | [diff] [blame] | 289 | private void updateAnimationsSummary(Object value) { |
| 290 | CharSequence[] summaries = getResources().getTextArray(R.array.animations_summaries); |
| 291 | CharSequence[] values = mAnimations.getEntryValues(); |
| 292 | for (int i=0; i<values.length; i++) { |
Marco Nelissen | 620e5f9 | 2009-09-09 09:06:40 -0700 | [diff] [blame] | 293 | //Log.i("foo", "Comparing entry "+ values[i] + " to current " |
| 294 | // + mAnimations.getValue()); |
Dianne Hackborn | 7631539 | 2009-09-03 13:33:55 -0700 | [diff] [blame] | 295 | if (values[i].equals(value)) { |
| 296 | mAnimations.setSummary(summaries[i]); |
| 297 | break; |
| 298 | } |
| 299 | } |
| 300 | } |
| 301 | |
Amith Yamasani | eb72bcd | 2009-07-07 11:37:08 -0700 | [diff] [blame] | 302 | private void setRingerMode(boolean silent, boolean vibrate) { |
| 303 | if (silent) { |
| 304 | mAudioManager.setRingerMode(vibrate ? AudioManager.RINGER_MODE_VIBRATE : |
| 305 | AudioManager.RINGER_MODE_SILENT); |
| 306 | } else { |
| 307 | mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); |
| 308 | mAudioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, |
| 309 | vibrate ? AudioManager.VIBRATE_SETTING_ON |
| 310 | : AudioManager.VIBRATE_SETTING_OFF); |
| 311 | } |
| 312 | } |
| 313 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 314 | @Override |
| 315 | public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { |
Amith Yamasani | eb72bcd | 2009-07-07 11:37:08 -0700 | [diff] [blame] | 316 | if (preference == mSilent || preference == mVibrate) { |
| 317 | setRingerMode(mSilent.isChecked(), mVibrate.isChecked()); |
| 318 | if (preference == mSilent) updateState(false); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 319 | } else if (preference == mPlayMediaNotificationSounds) { |
| 320 | try { |
| 321 | mMountService.setPlayNotificationSounds(mPlayMediaNotificationSounds.isChecked()); |
| 322 | } catch (RemoteException e) { |
| 323 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 324 | } else if (preference == mDtmfTone) { |
| 325 | Settings.System.putInt(getContentResolver(), Settings.System.DTMF_TONE_WHEN_DIALING, |
| 326 | mDtmfTone.isChecked() ? 1 : 0); |
| 327 | |
| 328 | } else if (preference == mSoundEffects) { |
| 329 | if (mSoundEffects.isChecked()) { |
| 330 | mAudioManager.loadSoundEffects(); |
| 331 | } else { |
| 332 | mAudioManager.unloadSoundEffects(); |
| 333 | } |
| 334 | Settings.System.putInt(getContentResolver(), Settings.System.SOUND_EFFECTS_ENABLED, |
| 335 | mSoundEffects.isChecked() ? 1 : 0); |
Dan Murphy | 22e1868 | 2009-09-22 11:47:08 -0500 | [diff] [blame] | 336 | |
| 337 | } else if (preference == mHapticFeedback) { |
| 338 | Settings.System.putInt(getContentResolver(), Settings.System.HAPTIC_FEEDBACK_ENABLED, |
| 339 | mHapticFeedback.isChecked() ? 1 : 0); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 340 | |
The Android Open Source Project | 648bf5f | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 341 | } else if (preference == mAccelerometer) { |
| 342 | Settings.System.putInt(getContentResolver(), |
| 343 | Settings.System.ACCELEROMETER_ROTATION, |
| 344 | mAccelerometer.isChecked() ? 1 : 0); |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 345 | } else if (preference == mNotificationPulse) { |
| 346 | boolean value = mNotificationPulse.isChecked(); |
| 347 | Settings.System.putInt(getContentResolver(), |
| 348 | Settings.System.NOTIFICATION_LIGHT_PULSE, value ? 1 : 0); |
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 | } |
| 353 | |
| 354 | public boolean onPreferenceChange(Preference preference, Object objValue) { |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 355 | final String key = preference.getKey(); |
| 356 | if (KEY_ANIMATIONS.equals(key)) { |
Dianne Hackborn | 7631539 | 2009-09-03 13:33:55 -0700 | [diff] [blame] | 357 | try { |
| 358 | int value = Integer.parseInt((String) objValue); |
| 359 | if (mAnimationScales.length >= 1) { |
| 360 | mAnimationScales[0] = value%10; |
| 361 | } |
| 362 | if (mAnimationScales.length >= 2) { |
| 363 | mAnimationScales[1] = (value/10)%10; |
| 364 | } |
| 365 | try { |
| 366 | mWindowManager.setAnimationScales(mAnimationScales); |
| 367 | } catch (RemoteException e) { |
| 368 | } |
| 369 | updateAnimationsSummary(objValue); |
| 370 | } catch (NumberFormatException e) { |
| 371 | Log.e(TAG, "could not persist animation setting", e); |
| 372 | } |
| 373 | |
| 374 | } |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 375 | if (KEY_SCREEN_TIMEOUT.equals(key)) { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 376 | int value = Integer.parseInt((String) objValue); |
| 377 | try { |
| 378 | Settings.System.putInt(getContentResolver(), |
| 379 | SCREEN_OFF_TIMEOUT, value); |
| 380 | } catch (NumberFormatException e) { |
| 381 | Log.e(TAG, "could not persist screen timeout setting", e); |
| 382 | } |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 383 | } else if (KEY_EMERGENCY_TONE.equals(key)) { |
Chouting Zhang | 386278a | 2009-06-24 14:25:43 -0500 | [diff] [blame] | 384 | int value = Integer.parseInt((String) objValue); |
| 385 | try { |
| 386 | Settings.System.putInt(getContentResolver(), |
| 387 | Settings.System.EMERGENCY_TONE, value); |
| 388 | } catch (NumberFormatException e) { |
| 389 | Log.e(TAG, "could not persist emergency tone setting", e); |
| 390 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 391 | } |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 392 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 393 | return true; |
| 394 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 395 | } |