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