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