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