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 | |
Chris Wren | 2bc32ae | 2012-09-24 14:23:46 -0400 | [diff] [blame] | 19 | import com.android.settings.bluetooth.DockEventReceiver; |
| 20 | |
| 21 | import android.app.AlertDialog; |
| 22 | import android.app.Dialog; |
| 23 | import android.bluetooth.BluetoothDevice; |
| 24 | import android.content.BroadcastReceiver; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 25 | import android.content.ContentResolver; |
| 26 | import android.content.Context; |
| 27 | import android.content.Intent; |
Chris Wren | 2bc32ae | 2012-09-24 14:23:46 -0400 | [diff] [blame] | 28 | import android.content.IntentFilter; |
Marco Nelissen | 6eca4b3 | 2011-07-15 15:02:03 -0700 | [diff] [blame] | 29 | import android.content.pm.PackageManager; |
| 30 | import android.content.pm.ResolveInfo; |
Amith Yamasani | 823bf0c | 2011-08-01 15:55:06 -0700 | [diff] [blame] | 31 | import android.database.Cursor; |
| 32 | import android.database.sqlite.SQLiteException; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 33 | import android.media.AudioManager; |
Amith Yamasani | 823bf0c | 2011-08-01 15:55:06 -0700 | [diff] [blame] | 34 | import android.media.RingtoneManager; |
Marco Nelissen | 6eca4b3 | 2011-07-15 15:02:03 -0700 | [diff] [blame] | 35 | import android.media.audiofx.AudioEffect; |
Amith Yamasani | 823bf0c | 2011-08-01 15:55:06 -0700 | [diff] [blame] | 36 | import android.net.Uri; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 37 | import android.os.Bundle; |
Amith Yamasani | 823bf0c | 2011-08-01 15:55:06 -0700 | [diff] [blame] | 38 | import android.os.Handler; |
| 39 | import android.os.Message; |
Dianne Hackborn | 0a115aa | 2010-11-04 11:40:31 -0700 | [diff] [blame] | 40 | import android.os.Vibrator; |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 41 | import android.preference.CheckBoxPreference; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 42 | import android.preference.ListPreference; |
| 43 | import android.preference.Preference; |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 44 | import android.preference.PreferenceGroup; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 45 | import android.preference.PreferenceScreen; |
Amith Yamasani | 823bf0c | 2011-08-01 15:55:06 -0700 | [diff] [blame] | 46 | import android.provider.MediaStore; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 47 | import android.provider.Settings; |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 48 | import android.telephony.TelephonyManager; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 49 | import android.util.Log; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 50 | |
Marco Nelissen | 6eca4b3 | 2011-07-15 15:02:03 -0700 | [diff] [blame] | 51 | import java.util.List; |
| 52 | |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 53 | public class SoundSettings extends SettingsPreferenceFragment implements |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 54 | Preference.OnPreferenceChangeListener { |
Amith Yamasani | 823bf0c | 2011-08-01 15:55:06 -0700 | [diff] [blame] | 55 | private static final String TAG = "SoundSettings"; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 56 | |
Chris Wren | 2bc32ae | 2012-09-24 14:23:46 -0400 | [diff] [blame] | 57 | private static final int DIALOG_NOT_DOCKED = 1; |
| 58 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 59 | /** If there is no setting in the provider, use this. */ |
Chouting Zhang | 386278a | 2009-06-24 14:25:43 -0500 | [diff] [blame] | 60 | private static final int FALLBACK_EMERGENCY_TONE_VALUE = 0; |
Michael Chan | df9504e | 2009-12-06 01:04:04 -0800 | [diff] [blame] | 61 | |
Daisuke Miyakawa | 8b878db | 2012-05-08 12:26:23 -0700 | [diff] [blame] | 62 | private static final String KEY_VIBRATE = "vibrate_when_ringing"; |
Joe Onorato | 057f181 | 2011-01-12 15:35:47 -0800 | [diff] [blame] | 63 | private static final String KEY_RING_VOLUME = "ring_volume"; |
Marco Nelissen | 6eca4b3 | 2011-07-15 15:02:03 -0700 | [diff] [blame] | 64 | private static final String KEY_MUSICFX = "musicfx"; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 65 | private static final String KEY_DTMF_TONE = "dtmf_tone"; |
| 66 | private static final String KEY_SOUND_EFFECTS = "sound_effects"; |
Dan Murphy | 22e1868 | 2009-09-22 11:47:08 -0500 | [diff] [blame] | 67 | private static final String KEY_HAPTIC_FEEDBACK = "haptic_feedback"; |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 68 | private static final String KEY_EMERGENCY_TONE = "emergency_tone"; |
| 69 | private static final String KEY_SOUND_SETTINGS = "sound_settings"; |
Daniel Sandler | 231d880 | 2010-02-17 15:35:21 -0500 | [diff] [blame] | 70 | private static final String KEY_LOCK_SOUNDS = "lock_sounds"; |
Amith Yamasani | 60133dd | 2010-09-11 14:17:31 -0700 | [diff] [blame] | 71 | private static final String KEY_RINGTONE = "ringtone"; |
| 72 | private static final String KEY_NOTIFICATION_SOUND = "notification_sound"; |
Daisuke Miyakawa | dba00b6 | 2012-05-16 08:41:38 -0700 | [diff] [blame] | 73 | private static final String KEY_CATEGORY_CALLS = "category_calls_and_notification"; |
Chris Wren | 2bc32ae | 2012-09-24 14:23:46 -0400 | [diff] [blame] | 74 | private static final String KEY_DOCK_CATEGORY = "dock_category"; |
| 75 | private static final String KEY_AUDIO_SETTINGS = "dock_audio"; |
| 76 | private static final String KEY_DOCK_SOUNDS = "dock_sounds"; |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 77 | |
Amith Yamasani | 60133dd | 2010-09-11 14:17:31 -0700 | [diff] [blame] | 78 | private static final String[] NEED_VOICE_CAPABILITY = { |
| 79 | KEY_RINGTONE, KEY_DTMF_TONE, KEY_CATEGORY_CALLS, |
| 80 | KEY_EMERGENCY_TONE |
| 81 | }; |
| 82 | |
Amith Yamasani | 823bf0c | 2011-08-01 15:55:06 -0700 | [diff] [blame] | 83 | private static final int MSG_UPDATE_RINGTONE_SUMMARY = 1; |
| 84 | private static final int MSG_UPDATE_NOTIFICATION_SUMMARY = 2; |
| 85 | |
Daisuke Miyakawa | 8b878db | 2012-05-08 12:26:23 -0700 | [diff] [blame] | 86 | private CheckBoxPreference mVibrateWhenRinging; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 87 | private CheckBoxPreference mDtmfTone; |
| 88 | private CheckBoxPreference mSoundEffects; |
Dan Murphy | 22e1868 | 2009-09-22 11:47:08 -0500 | [diff] [blame] | 89 | private CheckBoxPreference mHapticFeedback; |
Marco Nelissen | 6eca4b3 | 2011-07-15 15:02:03 -0700 | [diff] [blame] | 90 | private Preference mMusicFx; |
Daniel Sandler | 231d880 | 2010-02-17 15:35:21 -0500 | [diff] [blame] | 91 | private CheckBoxPreference mLockSounds; |
Amith Yamasani | 823bf0c | 2011-08-01 15:55:06 -0700 | [diff] [blame] | 92 | private Preference mRingtonePreference; |
| 93 | private Preference mNotificationPreference; |
| 94 | |
| 95 | private Runnable mRingtoneLookupRunnable; |
Michael Chan | df9504e | 2009-12-06 01:04:04 -0800 | [diff] [blame] | 96 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 97 | private AudioManager mAudioManager; |
Michael Chan | df9504e | 2009-12-06 01:04:04 -0800 | [diff] [blame] | 98 | |
Chris Wren | 2bc32ae | 2012-09-24 14:23:46 -0400 | [diff] [blame] | 99 | private Preference mDockAudioSettings; |
| 100 | private CheckBoxPreference mDockSounds; |
| 101 | private Intent mDockIntent; |
| 102 | |
Amith Yamasani | 823bf0c | 2011-08-01 15:55:06 -0700 | [diff] [blame] | 103 | private Handler mHandler = new Handler() { |
| 104 | public void handleMessage(Message msg) { |
| 105 | switch (msg.what) { |
| 106 | case MSG_UPDATE_RINGTONE_SUMMARY: |
| 107 | mRingtonePreference.setSummary((CharSequence) msg.obj); |
| 108 | break; |
| 109 | case MSG_UPDATE_NOTIFICATION_SUMMARY: |
| 110 | mNotificationPreference.setSummary((CharSequence) msg.obj); |
| 111 | break; |
| 112 | } |
| 113 | } |
| 114 | }; |
| 115 | |
Chris Wren | 2bc32ae | 2012-09-24 14:23:46 -0400 | [diff] [blame] | 116 | private final BroadcastReceiver mReceiver = new BroadcastReceiver() { |
| 117 | @Override |
| 118 | public void onReceive(Context context, Intent intent) { |
| 119 | if (intent.getAction().equals(Intent.ACTION_DOCK_EVENT)) { |
| 120 | handleDockChange(intent); |
| 121 | } |
| 122 | } |
| 123 | }; |
| 124 | |
Amith Yamasani | d2b3ab0 | 2009-12-02 13:56:05 -0800 | [diff] [blame] | 125 | private PreferenceGroup mSoundSettings; |
| 126 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 127 | @Override |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 128 | public void onCreate(Bundle savedInstanceState) { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 129 | super.onCreate(savedInstanceState); |
| 130 | ContentResolver resolver = getContentResolver(); |
Wink Saville | 327147e | 2011-02-02 11:30:25 -0800 | [diff] [blame] | 131 | int activePhoneType = TelephonyManager.getDefault().getCurrentPhoneType(); |
Michael Chan | df9504e | 2009-12-06 01:04:04 -0800 | [diff] [blame] | 132 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 133 | mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 134 | |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 135 | addPreferencesFromResource(R.xml.sound_settings); |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 136 | |
Chouting Zhang | 386278a | 2009-06-24 14:25:43 -0500 | [diff] [blame] | 137 | if (TelephonyManager.PHONE_TYPE_CDMA != activePhoneType) { |
| 138 | // device is not CDMA, do not display CDMA emergency_tone |
| 139 | getPreferenceScreen().removePreference(findPreference(KEY_EMERGENCY_TONE)); |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 140 | } |
Chouting Zhang | 386278a | 2009-06-24 14:25:43 -0500 | [diff] [blame] | 141 | |
Joe Onorato | 057f181 | 2011-01-12 15:35:47 -0800 | [diff] [blame] | 142 | if (!getResources().getBoolean(R.bool.has_silent_mode)) { |
Joe Onorato | 057f181 | 2011-01-12 15:35:47 -0800 | [diff] [blame] | 143 | findPreference(KEY_RING_VOLUME).setDependency(null); |
| 144 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 145 | |
Daisuke Miyakawa | 8b878db | 2012-05-08 12:26:23 -0700 | [diff] [blame] | 146 | mVibrateWhenRinging = (CheckBoxPreference) findPreference(KEY_VIBRATE); |
| 147 | mVibrateWhenRinging.setPersistent(false); |
| 148 | mVibrateWhenRinging.setChecked(Settings.System.getInt(resolver, |
| 149 | Settings.System.VIBRATE_WHEN_RINGING, 0) != 0); |
| 150 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 151 | mDtmfTone = (CheckBoxPreference) findPreference(KEY_DTMF_TONE); |
| 152 | mDtmfTone.setPersistent(false); |
| 153 | mDtmfTone.setChecked(Settings.System.getInt(resolver, |
| 154 | Settings.System.DTMF_TONE_WHEN_DIALING, 1) != 0); |
| 155 | mSoundEffects = (CheckBoxPreference) findPreference(KEY_SOUND_EFFECTS); |
| 156 | mSoundEffects.setPersistent(false); |
| 157 | mSoundEffects.setChecked(Settings.System.getInt(resolver, |
Amith Yamasani | 823bf0c | 2011-08-01 15:55:06 -0700 | [diff] [blame] | 158 | Settings.System.SOUND_EFFECTS_ENABLED, 1) != 0); |
Dan Murphy | 22e1868 | 2009-09-22 11:47:08 -0500 | [diff] [blame] | 159 | mHapticFeedback = (CheckBoxPreference) findPreference(KEY_HAPTIC_FEEDBACK); |
| 160 | mHapticFeedback.setPersistent(false); |
| 161 | mHapticFeedback.setChecked(Settings.System.getInt(resolver, |
Amith Yamasani | 823bf0c | 2011-08-01 15:55:06 -0700 | [diff] [blame] | 162 | Settings.System.HAPTIC_FEEDBACK_ENABLED, 1) != 0); |
Daniel Sandler | 231d880 | 2010-02-17 15:35:21 -0500 | [diff] [blame] | 163 | mLockSounds = (CheckBoxPreference) findPreference(KEY_LOCK_SOUNDS); |
| 164 | mLockSounds.setPersistent(false); |
| 165 | mLockSounds.setChecked(Settings.System.getInt(resolver, |
| 166 | Settings.System.LOCKSCREEN_SOUNDS_ENABLED, 1) != 0); |
Chouting Zhang | 386278a | 2009-06-24 14:25:43 -0500 | [diff] [blame] | 167 | |
Amith Yamasani | 823bf0c | 2011-08-01 15:55:06 -0700 | [diff] [blame] | 168 | mRingtonePreference = findPreference(KEY_RINGTONE); |
| 169 | mNotificationPreference = findPreference(KEY_NOTIFICATION_SOUND); |
| 170 | |
Daisuke Miyakawa | 8b878db | 2012-05-08 12:26:23 -0700 | [diff] [blame] | 171 | Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); |
| 172 | if (vibrator == null || !vibrator.hasVibrator()) { |
| 173 | getPreferenceScreen().removePreference(mVibrateWhenRinging); |
Amith Yamasani | edac9af | 2010-11-17 09:08:21 -0800 | [diff] [blame] | 174 | getPreferenceScreen().removePreference(mHapticFeedback); |
| 175 | } |
| 176 | |
Chouting Zhang | 386278a | 2009-06-24 14:25:43 -0500 | [diff] [blame] | 177 | if (TelephonyManager.PHONE_TYPE_CDMA == activePhoneType) { |
| 178 | ListPreference emergencyTonePreference = |
| 179 | (ListPreference) findPreference(KEY_EMERGENCY_TONE); |
Jeff Sharkey | a2c12a6 | 2012-10-01 13:39:24 -0700 | [diff] [blame^] | 180 | emergencyTonePreference.setValue(String.valueOf(Settings.Global.getInt( |
| 181 | resolver, Settings.Global.EMERGENCY_TONE, FALLBACK_EMERGENCY_TONE_VALUE))); |
Chouting Zhang | 386278a | 2009-06-24 14:25:43 -0500 | [diff] [blame] | 182 | emergencyTonePreference.setOnPreferenceChangeListener(this); |
| 183 | } |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 184 | |
Amith Yamasani | d2b3ab0 | 2009-12-02 13:56:05 -0800 | [diff] [blame] | 185 | mSoundSettings = (PreferenceGroup) findPreference(KEY_SOUND_SETTINGS); |
Amith Yamasani | d2b3ab0 | 2009-12-02 13:56:05 -0800 | [diff] [blame] | 186 | |
Marco Nelissen | 6eca4b3 | 2011-07-15 15:02:03 -0700 | [diff] [blame] | 187 | mMusicFx = mSoundSettings.findPreference(KEY_MUSICFX); |
| 188 | Intent i = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL); |
| 189 | PackageManager p = getPackageManager(); |
| 190 | List<ResolveInfo> ris = p.queryIntentActivities(i, PackageManager.GET_DISABLED_COMPONENTS); |
| 191 | if (ris.size() <= 2) { |
| 192 | // no need to show the item if there is no choice for the user to make |
| 193 | // note: the built in musicfx panel has two activities (one being a |
| 194 | // compatibility shim that launches either the other activity, or a |
| 195 | // third party one), hence the check for <=2. If the implementation |
| 196 | // of the compatbility layer changes, this check may need to be updated. |
| 197 | mSoundSettings.removePreference(mMusicFx); |
| 198 | } |
| 199 | |
Amith Yamasani | 60133dd | 2010-09-11 14:17:31 -0700 | [diff] [blame] | 200 | if (!Utils.isVoiceCapable(getActivity())) { |
| 201 | for (String prefKey : NEED_VOICE_CAPABILITY) { |
| 202 | Preference pref = findPreference(prefKey); |
| 203 | if (pref != null) { |
| 204 | getPreferenceScreen().removePreference(pref); |
| 205 | } |
| 206 | } |
| 207 | } |
Amith Yamasani | 823bf0c | 2011-08-01 15:55:06 -0700 | [diff] [blame] | 208 | |
| 209 | mRingtoneLookupRunnable = new Runnable() { |
| 210 | public void run() { |
| 211 | if (mRingtonePreference != null) { |
| 212 | updateRingtoneName(RingtoneManager.TYPE_RINGTONE, mRingtonePreference, |
| 213 | MSG_UPDATE_RINGTONE_SUMMARY); |
| 214 | } |
| 215 | if (mNotificationPreference != null) { |
| 216 | updateRingtoneName(RingtoneManager.TYPE_NOTIFICATION, mNotificationPreference, |
| 217 | MSG_UPDATE_NOTIFICATION_SUMMARY); |
| 218 | } |
| 219 | } |
| 220 | }; |
Chris Wren | 2bc32ae | 2012-09-24 14:23:46 -0400 | [diff] [blame] | 221 | |
| 222 | initDockSettings(); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 223 | } |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 224 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 225 | @Override |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 226 | public void onResume() { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 227 | super.onResume(); |
Michael Chan | df9504e | 2009-12-06 01:04:04 -0800 | [diff] [blame] | 228 | |
Amith Yamasani | 823bf0c | 2011-08-01 15:55:06 -0700 | [diff] [blame] | 229 | lookupRingtoneNames(); |
Chris Wren | 2bc32ae | 2012-09-24 14:23:46 -0400 | [diff] [blame] | 230 | |
| 231 | IntentFilter filter = new IntentFilter(Intent.ACTION_DOCK_EVENT); |
| 232 | getActivity().registerReceiver(mReceiver, filter); |
| 233 | } |
| 234 | |
| 235 | @Override |
| 236 | public void onPause() { |
| 237 | super.onPause(); |
| 238 | |
| 239 | getActivity().unregisterReceiver(mReceiver); |
Amith Yamasani | 823bf0c | 2011-08-01 15:55:06 -0700 | [diff] [blame] | 240 | } |
Michael Chan | df9504e | 2009-12-06 01:04:04 -0800 | [diff] [blame] | 241 | |
Amith Yamasani | 823bf0c | 2011-08-01 15:55:06 -0700 | [diff] [blame] | 242 | private void updateRingtoneName(int type, Preference preference, int msg) { |
| 243 | if (preference == null) return; |
| 244 | Context context = getActivity(); |
| 245 | if (context == null) return; |
| 246 | Uri ringtoneUri = RingtoneManager.getActualDefaultRingtoneUri(context, type); |
| 247 | CharSequence summary = context.getString(com.android.internal.R.string.ringtone_unknown); |
| 248 | // Is it a silent ringtone? |
| 249 | if (ringtoneUri == null) { |
| 250 | summary = context.getString(com.android.internal.R.string.ringtone_silent); |
| 251 | } else { |
| 252 | // Fetch the ringtone title from the media provider |
| 253 | try { |
| 254 | Cursor cursor = context.getContentResolver().query(ringtoneUri, |
| 255 | new String[] { MediaStore.Audio.Media.TITLE }, null, null, null); |
Amith Yamasani | c86755b | 2011-10-04 15:00:21 -0700 | [diff] [blame] | 256 | if (cursor != null) { |
| 257 | if (cursor.moveToFirst()) { |
| 258 | summary = cursor.getString(0); |
| 259 | } |
| 260 | cursor.close(); |
Amith Yamasani | 823bf0c | 2011-08-01 15:55:06 -0700 | [diff] [blame] | 261 | } |
| 262 | } catch (SQLiteException sqle) { |
| 263 | // Unknown title for the ringtone |
| 264 | } |
| 265 | } |
| 266 | mHandler.sendMessage(mHandler.obtainMessage(msg, summary)); |
| 267 | } |
| 268 | |
| 269 | private void lookupRingtoneNames() { |
| 270 | new Thread(mRingtoneLookupRunnable).start(); |
Dianne Hackborn | 7631539 | 2009-09-03 13:33:55 -0700 | [diff] [blame] | 271 | } |
Michael Chan | df9504e | 2009-12-06 01:04:04 -0800 | [diff] [blame] | 272 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 273 | @Override |
| 274 | public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { |
Daisuke Miyakawa | 8b878db | 2012-05-08 12:26:23 -0700 | [diff] [blame] | 275 | if (preference == mVibrateWhenRinging) { |
| 276 | Settings.System.putInt(getContentResolver(), Settings.System.VIBRATE_WHEN_RINGING, |
| 277 | mVibrateWhenRinging.isChecked() ? 1 : 0); |
| 278 | } else if (preference == mDtmfTone) { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 279 | Settings.System.putInt(getContentResolver(), Settings.System.DTMF_TONE_WHEN_DIALING, |
| 280 | mDtmfTone.isChecked() ? 1 : 0); |
Michael Chan | df9504e | 2009-12-06 01:04:04 -0800 | [diff] [blame] | 281 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 282 | } else if (preference == mSoundEffects) { |
| 283 | if (mSoundEffects.isChecked()) { |
| 284 | mAudioManager.loadSoundEffects(); |
| 285 | } else { |
| 286 | mAudioManager.unloadSoundEffects(); |
| 287 | } |
| 288 | Settings.System.putInt(getContentResolver(), Settings.System.SOUND_EFFECTS_ENABLED, |
| 289 | mSoundEffects.isChecked() ? 1 : 0); |
Dan Murphy | 22e1868 | 2009-09-22 11:47:08 -0500 | [diff] [blame] | 290 | |
| 291 | } else if (preference == mHapticFeedback) { |
| 292 | Settings.System.putInt(getContentResolver(), Settings.System.HAPTIC_FEEDBACK_ENABLED, |
| 293 | mHapticFeedback.isChecked() ? 1 : 0); |
Michael Chan | df9504e | 2009-12-06 01:04:04 -0800 | [diff] [blame] | 294 | |
Daniel Sandler | 231d880 | 2010-02-17 15:35:21 -0500 | [diff] [blame] | 295 | } else if (preference == mLockSounds) { |
| 296 | Settings.System.putInt(getContentResolver(), Settings.System.LOCKSCREEN_SOUNDS_ENABLED, |
| 297 | mLockSounds.isChecked() ? 1 : 0); |
| 298 | |
Marco Nelissen | 6eca4b3 | 2011-07-15 15:02:03 -0700 | [diff] [blame] | 299 | } else if (preference == mMusicFx) { |
| 300 | // let the framework fire off the intent |
| 301 | return false; |
Chris Wren | 2bc32ae | 2012-09-24 14:23:46 -0400 | [diff] [blame] | 302 | } else if (preference == mDockAudioSettings) { |
| 303 | int dockState = mDockIntent != null |
| 304 | ? mDockIntent.getIntExtra(Intent.EXTRA_DOCK_STATE, 0) |
| 305 | : Intent.EXTRA_DOCK_STATE_UNDOCKED; |
| 306 | if (dockState == Intent.EXTRA_DOCK_STATE_UNDOCKED) { |
| 307 | showDialog(DIALOG_NOT_DOCKED); |
| 308 | } else { |
| 309 | Intent i = new Intent(mDockIntent); |
| 310 | i.setAction(DockEventReceiver.ACTION_DOCK_SHOW_UI); |
| 311 | i.setClass(getActivity(), DockEventReceiver.class); |
| 312 | getActivity().sendBroadcast(i); |
| 313 | } |
| 314 | } else if (preference == mDockSounds) { |
| 315 | Settings.System.putInt(getContentResolver(), Settings.System.DOCK_SOUNDS_ENABLED, |
| 316 | mDockSounds.isChecked() ? 1 : 0); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 317 | } |
| 318 | return true; |
| 319 | } |
| 320 | |
| 321 | public boolean onPreferenceChange(Preference preference, Object objValue) { |
Amith Yamasani | 8f2fb65b | 2009-12-01 19:06:14 -0800 | [diff] [blame] | 322 | final String key = preference.getKey(); |
Amith Yamasani | 992f102 | 2010-01-25 09:17:53 -0800 | [diff] [blame] | 323 | if (KEY_EMERGENCY_TONE.equals(key)) { |
Chouting Zhang | 386278a | 2009-06-24 14:25:43 -0500 | [diff] [blame] | 324 | try { |
Peter Kuterna | 378b6f6 | 2010-11-28 22:35:31 +0100 | [diff] [blame] | 325 | int value = Integer.parseInt((String) objValue); |
Jeff Sharkey | a2c12a6 | 2012-10-01 13:39:24 -0700 | [diff] [blame^] | 326 | Settings.Global.putInt(getContentResolver(), |
| 327 | Settings.Global.EMERGENCY_TONE, value); |
Chouting Zhang | 386278a | 2009-06-24 14:25:43 -0500 | [diff] [blame] | 328 | } catch (NumberFormatException e) { |
| 329 | Log.e(TAG, "could not persist emergency tone setting", e); |
| 330 | } |
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 | } |
Amith Yamasani | b0b37ae | 2012-04-23 15:35:36 -0700 | [diff] [blame] | 335 | |
| 336 | @Override |
| 337 | protected int getHelpResource() { |
| 338 | return R.string.help_url_sound; |
| 339 | } |
Chris Wren | 2bc32ae | 2012-09-24 14:23:46 -0400 | [diff] [blame] | 340 | |
| 341 | private boolean needsDockSettings() { |
| 342 | return getResources().getBoolean(R.bool.has_dock_settings); |
| 343 | } |
| 344 | |
| 345 | private void initDockSettings() { |
| 346 | if (needsDockSettings()) { |
| 347 | |
| 348 | ContentResolver resolver = getContentResolver(); |
| 349 | |
| 350 | mDockAudioSettings = findPreference(KEY_AUDIO_SETTINGS); |
| 351 | |
| 352 | mDockSounds = (CheckBoxPreference) findPreference(KEY_DOCK_SOUNDS); |
| 353 | mDockSounds.setPersistent(false); |
| 354 | mDockSounds.setChecked(Settings.System.getInt(resolver, |
| 355 | Settings.System.DOCK_SOUNDS_ENABLED, 0) != 0); |
| 356 | } else { |
| 357 | getPreferenceScreen().removePreference(findPreference(KEY_DOCK_CATEGORY)); |
| 358 | getPreferenceScreen().removePreference(findPreference(KEY_AUDIO_SETTINGS)); |
| 359 | getPreferenceScreen().removePreference(findPreference(KEY_DOCK_SOUNDS)); |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | private void handleDockChange(Intent intent) { |
| 364 | if (mDockAudioSettings != null) { |
| 365 | int dockState = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, 0); |
| 366 | |
| 367 | boolean isBluetooth = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE) != null; |
| 368 | |
| 369 | if (!isBluetooth) { |
| 370 | // No dock audio if not on Bluetooth. |
| 371 | mDockAudioSettings.setEnabled(false); |
| 372 | } else { |
| 373 | mDockAudioSettings.setEnabled(true); |
| 374 | mDockIntent = intent; |
| 375 | } |
| 376 | |
| 377 | if (dockState != Intent.EXTRA_DOCK_STATE_UNDOCKED) { |
| 378 | // remove undocked dialog if currently showing. |
| 379 | try { |
| 380 | removeDialog(DIALOG_NOT_DOCKED); |
| 381 | } catch (IllegalArgumentException iae) { |
| 382 | // Maybe it was already dismissed |
| 383 | } |
| 384 | } |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | @Override |
| 389 | public Dialog onCreateDialog(int id) { |
| 390 | if (id == DIALOG_NOT_DOCKED) { |
| 391 | return createUndockedMessage(); |
| 392 | } |
| 393 | return null; |
| 394 | } |
| 395 | |
| 396 | private Dialog createUndockedMessage() { |
| 397 | final AlertDialog.Builder ab = new AlertDialog.Builder(getActivity()); |
| 398 | ab.setTitle(R.string.dock_not_found_title); |
| 399 | ab.setMessage(R.string.dock_not_found_text); |
| 400 | ab.setPositiveButton(android.R.string.ok, null); |
| 401 | return ab.create(); |
| 402 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 403 | } |
Chris Wren | 2bc32ae | 2012-09-24 14:23:46 -0400 | [diff] [blame] | 404 | |