Settings: Remove sound settings.

- Move the remaining conditional preferences into
  the combined Sound & Notifications screen.
- Refactor the "Other sounds" sub-settings screen to
  provide a home for the new preferences.
- Migrate docking sounds, conditional on config.
- Migrate docking media, conditional on config.
- Migrate emergency tones, conditional on CDMA.
- Move all boilerplate preference <-> setting plumbing into
  a separate helper.
- Since some preferences in Other sounds are now conditional,
  create a special indexer for searching.
- Remove SoundSettings (and xml), create aliases in the manifest
  to avoid breaking shortcuts.

Bug:15279526
Change-Id: I5ae3ecda2f899b1948f7908bd217a799326c2c56
This commit is contained in:
John Spurlock
2014-05-28 09:43:45 -04:00
parent 9e8bd809fc
commit 4e4cdeffdb
15 changed files with 521 additions and 855 deletions

View File

@@ -523,35 +523,6 @@
android:resource="@id/language_settings" />
</activity-alias>
<activity android:name="Settings$SoundSettingsActivity"
android:label="@string/sound_settings"
android:taskAffinity=""
android:excludeFromRecents="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="com.android.settings.SOUND_SETTINGS" />
<action android:name="android.settings.SOUND_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.VOICE_LAUNCH" />
<category android:name="com.android.settings.SHORTCUT" />
</intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.SoundSettings" />
<meta-data android:name="com.android.settings.TOP_LEVEL_HEADER_ID"
android:resource="@id/sound_settings" />
</activity>
<!-- Keep compatibility with old shortcuts. -->
<activity-alias android:name="SoundSettings"
android:label="@string/sound_settings"
android:exported="true"
android:targetActivity="Settings$SoundSettingsActivity">
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.SoundSettings" />
<meta-data android:name="com.android.settings.TOP_LEVEL_HEADER_ID"
android:resource="@id/sound_settings" />
</activity-alias>
<activity android:name="Settings$ZenModeSettingsActivity"
android:label="@string/zen_mode_settings_title"
android:exported="true"
@@ -1712,6 +1683,37 @@
android:resource="@id/notification_settings" />
</activity>
<!-- Keep compatibility with old shortcuts. -->
<activity-alias android:name="Settings$SoundSettingsActivity"
android:label="@string/notification_settings"
android:taskAffinity=""
android:excludeFromRecents="true"
android:targetActivity="Settings$NotificationSettingsActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="com.android.settings.SOUND_SETTINGS" />
<action android:name="android.settings.SOUND_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.VOICE_LAUNCH" />
<category android:name="com.android.settings.SHORTCUT" />
</intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.notification.NotificationSettings" />
<meta-data android:name="com.android.settings.TOP_LEVEL_HEADER_ID"
android:resource="@id/notification_settings" />
</activity-alias>
<!-- Keep compatibility with old shortcuts. -->
<activity-alias android:name="SoundSettings"
android:label="@string/notification_settings"
android:exported="true"
android:targetActivity="Settings$NotificationSettingsActivity">
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.notification.NotificationSettings" />
<meta-data android:name="com.android.settings.TOP_LEVEL_HEADER_ID"
android:resource="@id/notification_settings" />
</activity-alias>
<activity android:name="Settings$NotificationDisplaySettingsActivity"
android:label="@string/notification_display_settings"
android:exported="true"
@@ -1728,18 +1730,18 @@
android:resource="@id/notification_settings" />
</activity>
<activity android:name="Settings$TouchSoundSettingsActivity"
android:label="@string/touch_sound_settings"
<activity android:name="Settings$OtherSoundSettingsActivity"
android:label="@string/other_sound_settings"
android:exported="true"
android:taskAffinity=""
android:excludeFromRecents="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.settings.ACTION_TOUCH_SOUND_SETTINGS" />
<action android:name="android.settings.ACTION_OTHER_SOUND_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.notification.TouchSoundSettings" />
android:value="com.android.settings.notification.OtherSoundSettings" />
<meta-data android:name="com.android.settings.TOP_LEVEL_HEADER_ID"
android:resource="@id/notification_settings" />
</activity>

View File

@@ -471,20 +471,6 @@
<item>Manual</item>
</string-array>
<!-- Sound settings for emergency tone. -->
<string-array name="emergency_tone_entries">
<item>Off</item>
<item>Alert</item>
<item>Vibrate</item>
</string-array>
<!-- Do not translate. -->
<string-array name="emergency_tone_values">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>
<!-- Locales in this list are displayed with the corresponding
name from special_locale_names instead of using the name
from Locale.getDisplayName(). -->

View File

@@ -5134,21 +5134,42 @@
<!-- Sounds & notifications > Showing notifications: Title for the option managing notifications per application. [CHAR LIMIT=30] -->
<string name="app_notifications_title">App notifications</string>
<!-- Sounds & notifications: Title for the touch sounds option and associated settings page. [CHAR LIMIT=30] -->
<string name="touch_sound_settings">Touch sounds</string>
<!-- Sounds & notifications: Title for the other sounds option and associated settings page. [CHAR LIMIT=30] -->
<string name="other_sound_settings">Other sounds</string>
<!-- Sounds & notifications > Touch sounds: Title for the option enabling touch sounds for dial pad tones. [CHAR LIMIT=30] -->
<!-- Sounds & notifications > Other sounds: Title for the option enabling touch sounds for dial pad tones. [CHAR LIMIT=30] -->
<string name="dial_pad_tones_title">Dial pad tones</string>
<!-- Sounds & notifications > Touch sounds: Title for the option enabling touch sounds for screen locking and unlocking. [CHAR LIMIT=30] -->
<string name="screen_locking_sounds_title">Screen locking &amp; unlocking</string>
<!-- Sounds & notifications > Other sounds: Title for the option enabling touch sounds for screen locking sounds. [CHAR LIMIT=30] -->
<string name="screen_locking_sounds_title">Screen locking sounds</string>
<!-- Sounds & notifications > Touch sounds: Title for the option enabling other touch sounds. [CHAR LIMIT=30] -->
<string name="other_touch_sounds_title">Other touch sounds</string>
<!-- Sounds & notifications > Other sounds: Title for the option enabling docking sounds. [CHAR LIMIT=30] -->
<string name="docking_sounds_title">Docking sounds</string>
<!-- Sounds & notifications > Touch sounds: Title for the option enabling haptic feedback on touch. [CHAR LIMIT=30] -->
<!-- Sounds & notifications > Other sounds: Title for the option enabling touch sounds. [CHAR LIMIT=30] -->
<string name="touch_sounds_title">Touch sounds</string>
<!-- Sounds & notifications > Other sounds: Title for the option enabling haptic feedback on touch. [CHAR LIMIT=30] -->
<string name="vibrate_on_touch_title">Vibrate on touch</string>
<!-- Sounds & notifications > Other sounds: Title for the option enabling dock audio media. [CHAR LIMIT=30] -->
<string name="dock_audio_media_title">Dock speaker plays</string>
<!-- Sounds & notifications > Other sounds: Value for the dock audio media with value 0: disabled. [CHAR LIMIT=30] -->
<string name="dock_audio_media_disabled">All audio</string>
<!-- Sounds & notifications > Other sounds: Value for the dock audio media with value 1: enabled. [CHAR LIMIT=30] -->
<string name="dock_audio_media_enabled">Media audio only</string>
<!-- Sounds & notifications > Other sounds: Value for the emergency tone option with value 0: silent. [CHAR LIMIT=30] -->
<string name="emergency_tone_silent">Silent</string>
<!-- Sounds & notifications > Other sounds: Value for the emergency tone option with value 1: alert. [CHAR LIMIT=30] -->
<string name="emergency_tone_alert">Alert</string>
<!-- Sounds & notifications > Other sounds: Value for the emergency tone option with value 2: vibrate. [CHAR LIMIT=30] -->
<string name="emergency_tone_vibrate">Vibrate</string>
<!-- Sounds & notifications: Title for managing notification listeners option. [CHAR LIMIT=30] -->
<string name="manage_notification_access_title">Notification access</string>

View File

@@ -76,14 +76,6 @@
android:icon="@drawable/ic_settings_home"
/>
<!-- Sound -->
<dashboard-tile
android:id="@+id/sound_settings"
android:title="@string/sound_settings"
android:fragment="com.android.settings.SoundSettings"
android:icon="@drawable/ic_settings_sound"
/>
<!-- Display -->
<dashboard-tile
android:id="@+id/display_settings"

View File

@@ -88,10 +88,10 @@
<!-- Touch sounds -->
<Preference
android:key="touch_sounds"
android:title="@string/touch_sound_settings"
android:key="other_sounds"
android:title="@string/other_sound_settings"
android:persistent="false"
android:fragment="com.android.settings.notification.TouchSoundSettings" />
android:fragment="com.android.settings.notification.OtherSoundSettings" />
<!-- Notification access -->
<Preference

View File

@@ -15,8 +15,8 @@
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/touch_sound_settings"
android:key="touch_sound_settings"
android:title="@string/other_sound_settings"
android:key="other_sound_settings"
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
<!-- Dial pad tones -->
@@ -27,7 +27,7 @@
android:switchTextOn=""
android:persistent="false" />
<!-- Screen locking / unlocking -->
<!-- Screen locking sounds -->
<SwitchPreference
android:key="screen_locking_sounds"
android:title="@string/screen_locking_sounds_title"
@@ -35,10 +35,18 @@
android:switchTextOn=""
android:persistent="false" />
<!-- Other touch sounds -->
<!-- Docking sounds -->
<SwitchPreference
android:key="other_touch_sounds"
android:title="@string/other_touch_sounds_title"
android:key="docking_sounds"
android:title="@string/docking_sounds_title"
android:switchTextOff=""
android:switchTextOn=""
android:persistent="false" />
<!-- Touch sounds -->
<SwitchPreference
android:key="touch_sounds"
android:title="@string/touch_sounds_title"
android:switchTextOff=""
android:switchTextOn=""
android:persistent="false" />
@@ -51,4 +59,16 @@
android:switchTextOn=""
android:persistent="false" />
<!-- Dock speaker plays -->
<com.android.settings.notification.DropDownPreference
android:key="dock_audio_media"
android:title="@string/dock_audio_media_title"
android:persistent="false" />
<!-- Emergency tone -->
<com.android.settings.notification.DropDownPreference
android:key="emergency_tone"
android:title="@string/emergency_tone_title"
android:persistent="false" />
</PreferenceScreen>

View File

@@ -1,112 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2008 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/sound_settings"
android:key="sound_settings"
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
<com.android.settings.RingerVolumePreference
android:key="ring_volume"
android:title="@string/all_volume_title"
android:dialogTitle="@string/all_volume_title"
android:persistent="false"
android:streamType="ring" />
<Preference
android:key="musicfx"
android:title="@string/musicfx_title">
<intent android:targetPackage="com.android.musicfx"
android:targetClass="com.android.musicfx.ControlPanelPicker" />
</Preference>
<PreferenceCategory
android:key="category_calls_and_notification"
android:title="@string/sound_category_call_ringtone_vibrate_title"/>
<!-- Do not nest these, or removals in code will break -->
<com.android.settings.DefaultRingtonePreference
android:key="ringtone"
android:title="@string/ringtone_title"
android:dialogTitle="@string/ringtone_title"
android:persistent="false"
android:ringtoneType="ringtone" />
<CheckBoxPreference
android:key="vibrate_when_ringing"
android:title="@string/vibrate_when_ringing_title"
android:persistent="false" />
<PreferenceCategory
android:title="@string/sound_category_system_title"/>
<!-- Do not nest these, or removals in code will break -->
<com.android.settings.DefaultRingtonePreference
android:key="notification_sound"
android:title="@string/notification_sound_title"
android:dialogTitle="@string/notification_sound_dialog_title"
android:persistent="false"
android:ringtoneType="notification" />
<CheckBoxPreference
android:key="dtmf_tone"
android:title="@string/dtmf_tone_enable_title"
android:defaultValue="true" />
<CheckBoxPreference
android:key="sound_effects"
android:title="@string/sound_effects_enable_title"
android:defaultValue="true" />
<CheckBoxPreference
android:key="lock_sounds"
android:title="@string/lock_sounds_enable_title"
android:defaultValue="true" />
<CheckBoxPreference
android:key="haptic_feedback"
android:title="@string/haptic_feedback_enable_title"
android:defaultValue="true" />
<ListPreference
android:key="emergency_tone"
android:title="@string/emergency_tone_title"
android:entries="@array/emergency_tone_entries"
android:entryValues="@array/emergency_tone_values" />
<!-- Dock -->
<PreferenceCategory
android:key="dock_category"
android:title="@string/dock_settings"/>
<!-- Do not nest these, or removals in code will break -->
<PreferenceScreen
android:key="dock_audio"
android:title="@string/dock_audio_settings_title">
<CheckBoxPreference
android:title="@string/bluetooth_dock_settings_a2dp"
android:key="dock_audio_media_enabled"
android:enabled="true"
/>
</PreferenceScreen>
<CheckBoxPreference
android:key="dock_sounds"
android:title="@string/dock_sounds_enable_title"
android:defaultValue="false" />
</PreferenceScreen>

View File

@@ -40,7 +40,6 @@ public class Settings extends SettingsActivity {
public static class SpellCheckersSettingsActivity extends SettingsActivity { /* empty */ }
public static class LocalePickerActivity extends SettingsActivity { /* empty */ }
public static class UserDictionarySettingsActivity extends SettingsActivity { /* empty */ }
public static class SoundSettingsActivity extends SettingsActivity { /* empty */ }
public static class DisplaySettingsActivity extends SettingsActivity { /* empty */ }
public static class DeviceInfoSettingsActivity extends SettingsActivity { /* empty */ }
public static class ApplicationSettingsActivity extends SettingsActivity { /* empty */ }
@@ -90,7 +89,7 @@ public class Settings extends SettingsActivity {
public static class NotificationSettingsActivity extends SettingsActivity { /* empty */ }
public static class NotificationDisplaySettingsActivity extends SettingsActivity { /* empty */ }
public static class AppNotificationSettingsActivity extends SettingsActivity { /* empty */ }
public static class TouchSoundSettingsActivity extends SettingsActivity { /* empty */ }
public static class OtherSoundSettingsActivity extends SettingsActivity { /* empty */ }
public static class TopLevelSettings extends SettingsActivity { /* empty */ }
}

View File

@@ -200,7 +200,7 @@ public class SettingsActivity extends Activity
R.id.data_usage_settings,
R.id.wireless_settings,
R.id.device_section,
R.id.sound_settings,
R.id.notification_settings,
R.id.display_settings,
R.id.storage_settings,
R.id.application_settings,
@@ -236,7 +236,6 @@ public class SettingsActivity extends Activity
SpellCheckersSettings.class.getName(),
UserDictionaryList.class.getName(),
UserDictionarySettings.class.getName(),
SoundSettings.class.getName(),
DisplaySettings.class.getName(),
DeviceInfoSettings.class.getName(),
ManageApplications.class.getName(),

View File

@@ -1,477 +0,0 @@
/*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings;
import com.android.settings.bluetooth.DockEventReceiver;
import android.app.AlertDialog;
import android.app.Dialog;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.database.Cursor;
import android.database.sqlite.SQLiteException;
import android.media.AudioManager;
import android.media.RingtoneManager;
import android.media.audiofx.AudioEffect;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Vibrator;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
import android.provider.MediaStore;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.util.Log;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import java.util.ArrayList;
import java.util.List;
public class SoundSettings extends SettingsPreferenceFragment implements
Preference.OnPreferenceChangeListener, Indexable {
private static final String TAG = "SoundSettings";
private static final int DIALOG_NOT_DOCKED = 1;
/** If there is no setting in the provider, use this. */
private static final int FALLBACK_EMERGENCY_TONE_VALUE = 0;
private static final String KEY_VIBRATE = "vibrate_when_ringing";
private static final String KEY_RING_VOLUME = "ring_volume";
private static final String KEY_MUSICFX = "musicfx";
private static final String KEY_DTMF_TONE = "dtmf_tone";
private static final String KEY_SOUND_EFFECTS = "sound_effects";
private static final String KEY_HAPTIC_FEEDBACK = "haptic_feedback";
private static final String KEY_EMERGENCY_TONE = "emergency_tone";
private static final String KEY_SOUND_SETTINGS = "sound_settings";
private static final String KEY_LOCK_SOUNDS = "lock_sounds";
private static final String KEY_RINGTONE = "ringtone";
private static final String KEY_NOTIFICATION_SOUND = "notification_sound";
private static final String KEY_CATEGORY_CALLS = "category_calls_and_notification";
private static final String KEY_DOCK_CATEGORY = "dock_category";
private static final String KEY_DOCK_AUDIO_SETTINGS = "dock_audio";
private static final String KEY_DOCK_SOUNDS = "dock_sounds";
private static final String KEY_DOCK_AUDIO_MEDIA_ENABLED = "dock_audio_media_enabled";
private static final String[] NEED_VOICE_CAPABILITY = {
KEY_RINGTONE, KEY_DTMF_TONE, KEY_CATEGORY_CALLS,
KEY_EMERGENCY_TONE, KEY_VIBRATE
};
private static final int MSG_UPDATE_RINGTONE_SUMMARY = 1;
private static final int MSG_UPDATE_NOTIFICATION_SUMMARY = 2;
private CheckBoxPreference mVibrateWhenRinging;
private CheckBoxPreference mDtmfTone;
private CheckBoxPreference mSoundEffects;
private CheckBoxPreference mHapticFeedback;
private Preference mMusicFx;
private CheckBoxPreference mLockSounds;
private Preference mRingtonePreference;
private Preference mNotificationPreference;
private Runnable mRingtoneLookupRunnable;
private AudioManager mAudioManager;
private Preference mDockAudioSettings;
private CheckBoxPreference mDockSounds;
private Intent mDockIntent;
private CheckBoxPreference mDockAudioMediaEnabled;
private Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
switch (msg.what) {
case MSG_UPDATE_RINGTONE_SUMMARY:
mRingtonePreference.setSummary((CharSequence) msg.obj);
break;
case MSG_UPDATE_NOTIFICATION_SUMMARY:
mNotificationPreference.setSummary((CharSequence) msg.obj);
break;
}
}
};
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_DOCK_EVENT)) {
handleDockChange(intent);
}
}
};
private PreferenceGroup mSoundSettings;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ContentResolver resolver = getContentResolver();
int activePhoneType = TelephonyManager.getDefault().getCurrentPhoneType();
mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
addPreferencesFromResource(R.xml.sound_settings);
if (TelephonyManager.PHONE_TYPE_CDMA != activePhoneType) {
// device is not CDMA, do not display CDMA emergency_tone
Preference pref = findPreference(KEY_EMERGENCY_TONE);
if (pref != null) {
getPreferenceScreen().removePreference(pref);
}
}
if (!getResources().getBoolean(R.bool.has_silent_mode)) {
findPreference(KEY_RING_VOLUME).setDependency(null);
}
if (getResources().getBoolean(com.android.internal.R.bool.config_useFixedVolume)) {
// device with fixed volume policy, do not display volumes submenu
Preference pref = findPreference(KEY_RING_VOLUME);
if (pref != null) {
getPreferenceScreen().removePreference(pref);
}
}
mVibrateWhenRinging = (CheckBoxPreference) findPreference(KEY_VIBRATE);
mVibrateWhenRinging.setPersistent(false);
mVibrateWhenRinging.setChecked(Settings.System.getInt(resolver,
Settings.System.VIBRATE_WHEN_RINGING, 0) != 0);
mDtmfTone = (CheckBoxPreference) findPreference(KEY_DTMF_TONE);
mDtmfTone.setPersistent(false);
mDtmfTone.setChecked(Settings.System.getInt(resolver,
Settings.System.DTMF_TONE_WHEN_DIALING, 1) != 0);
mSoundEffects = (CheckBoxPreference) findPreference(KEY_SOUND_EFFECTS);
mSoundEffects.setPersistent(false);
mSoundEffects.setChecked(Settings.System.getInt(resolver,
Settings.System.SOUND_EFFECTS_ENABLED, 1) != 0);
mHapticFeedback = (CheckBoxPreference) findPreference(KEY_HAPTIC_FEEDBACK);
mHapticFeedback.setPersistent(false);
mHapticFeedback.setChecked(Settings.System.getInt(resolver,
Settings.System.HAPTIC_FEEDBACK_ENABLED, 1) != 0);
mLockSounds = (CheckBoxPreference) findPreference(KEY_LOCK_SOUNDS);
mLockSounds.setPersistent(false);
mLockSounds.setChecked(Settings.System.getInt(resolver,
Settings.System.LOCKSCREEN_SOUNDS_ENABLED, 1) != 0);
mRingtonePreference = findPreference(KEY_RINGTONE);
mNotificationPreference = findPreference(KEY_NOTIFICATION_SOUND);
Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
if (vibrator == null || !vibrator.hasVibrator()) {
removePreference(KEY_VIBRATE);
removePreference(KEY_HAPTIC_FEEDBACK);
}
if (TelephonyManager.PHONE_TYPE_CDMA == activePhoneType) {
ListPreference emergencyTonePreference =
(ListPreference) findPreference(KEY_EMERGENCY_TONE);
emergencyTonePreference.setValue(String.valueOf(Settings.Global.getInt(
resolver, Settings.Global.EMERGENCY_TONE, FALLBACK_EMERGENCY_TONE_VALUE)));
emergencyTonePreference.setOnPreferenceChangeListener(this);
}
mSoundSettings = (PreferenceGroup) findPreference(KEY_SOUND_SETTINGS);
mMusicFx = mSoundSettings.findPreference(KEY_MUSICFX);
Intent i = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL);
PackageManager p = getPackageManager();
List<ResolveInfo> ris = p.queryIntentActivities(i, PackageManager.GET_DISABLED_COMPONENTS);
if (ris.size() <= 2) {
// no need to show the item if there is no choice for the user to make
// note: the built in musicfx panel has two activities (one being a
// compatibility shim that launches either the other activity, or a
// third party one), hence the check for <=2. If the implementation
// of the compatbility layer changes, this check may need to be updated.
mSoundSettings.removePreference(mMusicFx);
}
if (!Utils.isVoiceCapable(getActivity())) {
for (String prefKey : NEED_VOICE_CAPABILITY) {
Preference pref = findPreference(prefKey);
if (pref != null) {
getPreferenceScreen().removePreference(pref);
}
}
}
mRingtoneLookupRunnable = new Runnable() {
public void run() {
if (mRingtonePreference != null) {
updateRingtoneName(RingtoneManager.TYPE_RINGTONE, mRingtonePreference,
MSG_UPDATE_RINGTONE_SUMMARY);
}
if (mNotificationPreference != null) {
updateRingtoneName(RingtoneManager.TYPE_NOTIFICATION, mNotificationPreference,
MSG_UPDATE_NOTIFICATION_SUMMARY);
}
}
};
initDockSettings();
}
@Override
public void onResume() {
super.onResume();
lookupRingtoneNames();
IntentFilter filter = new IntentFilter(Intent.ACTION_DOCK_EVENT);
getActivity().registerReceiver(mReceiver, filter);
}
@Override
public void onPause() {
super.onPause();
getActivity().unregisterReceiver(mReceiver);
}
private void updateRingtoneName(int type, Preference preference, int msg) {
if (preference == null) return;
final CharSequence summary = updateRingtoneName(getActivity(), type);
if (summary == null) return;
mHandler.sendMessage(mHandler.obtainMessage(msg, summary));
}
public static CharSequence updateRingtoneName(Context context, int type) {
if (context == null) return null;
Uri ringtoneUri = RingtoneManager.getActualDefaultRingtoneUri(context, type);
CharSequence summary = context.getString(com.android.internal.R.string.ringtone_unknown);
// Is it a silent ringtone?
if (ringtoneUri == null) {
summary = context.getString(com.android.internal.R.string.ringtone_silent);
} else {
// Fetch the ringtone title from the media provider
try {
Cursor cursor = context.getContentResolver().query(ringtoneUri,
new String[] { MediaStore.Audio.Media.TITLE }, null, null, null);
if (cursor != null) {
if (cursor.moveToFirst()) {
summary = cursor.getString(0);
}
cursor.close();
}
} catch (SQLiteException sqle) {
// Unknown title for the ringtone
}
}
return summary;
}
private void lookupRingtoneNames() {
new Thread(mRingtoneLookupRunnable).start();
}
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
if (preference == mVibrateWhenRinging) {
Settings.System.putInt(getContentResolver(), Settings.System.VIBRATE_WHEN_RINGING,
mVibrateWhenRinging.isChecked() ? 1 : 0);
} else if (preference == mDtmfTone) {
Settings.System.putInt(getContentResolver(), Settings.System.DTMF_TONE_WHEN_DIALING,
mDtmfTone.isChecked() ? 1 : 0);
} else if (preference == mSoundEffects) {
if (mSoundEffects.isChecked()) {
mAudioManager.loadSoundEffects();
} else {
mAudioManager.unloadSoundEffects();
}
Settings.System.putInt(getContentResolver(), Settings.System.SOUND_EFFECTS_ENABLED,
mSoundEffects.isChecked() ? 1 : 0);
} else if (preference == mHapticFeedback) {
Settings.System.putInt(getContentResolver(), Settings.System.HAPTIC_FEEDBACK_ENABLED,
mHapticFeedback.isChecked() ? 1 : 0);
} else if (preference == mLockSounds) {
Settings.System.putInt(getContentResolver(), Settings.System.LOCKSCREEN_SOUNDS_ENABLED,
mLockSounds.isChecked() ? 1 : 0);
} else if (preference == mMusicFx) {
// let the framework fire off the intent
return false;
} else if (preference == mDockAudioSettings) {
int dockState = mDockIntent != null
? mDockIntent.getIntExtra(Intent.EXTRA_DOCK_STATE, 0)
: Intent.EXTRA_DOCK_STATE_UNDOCKED;
if (dockState == Intent.EXTRA_DOCK_STATE_UNDOCKED) {
showDialog(DIALOG_NOT_DOCKED);
} else {
boolean isBluetooth = mDockIntent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE) != null;
if (isBluetooth) {
Intent i = new Intent(mDockIntent);
i.setAction(DockEventReceiver.ACTION_DOCK_SHOW_UI);
i.setClass(getActivity(), DockEventReceiver.class);
getActivity().sendBroadcast(i);
} else {
PreferenceScreen ps = (PreferenceScreen)mDockAudioSettings;
Bundle extras = ps.getExtras();
extras.putBoolean("checked",
Settings.Global.getInt(getContentResolver(),
Settings.Global.DOCK_AUDIO_MEDIA_ENABLED, 0) == 1);
super.onPreferenceTreeClick(ps, ps);
}
}
} else if (preference == mDockSounds) {
Settings.Global.putInt(getContentResolver(), Settings.Global.DOCK_SOUNDS_ENABLED,
mDockSounds.isChecked() ? 1 : 0);
} else if (preference == mDockAudioMediaEnabled) {
Settings.Global.putInt(getContentResolver(), Settings.Global.DOCK_AUDIO_MEDIA_ENABLED,
mDockAudioMediaEnabled.isChecked() ? 1 : 0);
}
return true;
}
public boolean onPreferenceChange(Preference preference, Object objValue) {
final String key = preference.getKey();
if (KEY_EMERGENCY_TONE.equals(key)) {
try {
int value = Integer.parseInt((String) objValue);
Settings.Global.putInt(getContentResolver(),
Settings.Global.EMERGENCY_TONE, value);
} catch (NumberFormatException e) {
Log.e(TAG, "could not persist emergency tone setting", e);
}
}
return true;
}
@Override
protected int getHelpResource() {
return R.string.help_url_sound;
}
private boolean needsDockSettings() {
return getResources().getBoolean(R.bool.has_dock_settings);
}
private void initDockSettings() {
ContentResolver resolver = getContentResolver();
if (needsDockSettings()) {
mDockSounds = (CheckBoxPreference) findPreference(KEY_DOCK_SOUNDS);
mDockSounds.setPersistent(false);
mDockSounds.setChecked(Settings.Global.getInt(resolver,
Settings.Global.DOCK_SOUNDS_ENABLED, 0) != 0);
mDockAudioSettings = findPreference(KEY_DOCK_AUDIO_SETTINGS);
mDockAudioSettings.setEnabled(false);
} else {
getPreferenceScreen().removePreference(findPreference(KEY_DOCK_CATEGORY));
getPreferenceScreen().removePreference(findPreference(KEY_DOCK_AUDIO_SETTINGS));
getPreferenceScreen().removePreference(findPreference(KEY_DOCK_SOUNDS));
Settings.Global.putInt(resolver, Settings.Global.DOCK_AUDIO_MEDIA_ENABLED, 1);
}
}
private void handleDockChange(Intent intent) {
if (mDockAudioSettings != null) {
int dockState = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, 0);
boolean isBluetooth =
intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE) != null;
mDockIntent = intent;
if (dockState != Intent.EXTRA_DOCK_STATE_UNDOCKED) {
// remove undocked dialog if currently showing.
try {
removeDialog(DIALOG_NOT_DOCKED);
} catch (IllegalArgumentException iae) {
// Maybe it was already dismissed
}
if (isBluetooth) {
mDockAudioSettings.setEnabled(true);
} else {
if (dockState == Intent.EXTRA_DOCK_STATE_LE_DESK) {
ContentResolver resolver = getContentResolver();
mDockAudioSettings.setEnabled(true);
if (Settings.Global.getInt(resolver,
Settings.Global.DOCK_AUDIO_MEDIA_ENABLED, -1) == -1) {
Settings.Global.putInt(resolver,
Settings.Global.DOCK_AUDIO_MEDIA_ENABLED, 0);
}
mDockAudioMediaEnabled =
(CheckBoxPreference) findPreference(KEY_DOCK_AUDIO_MEDIA_ENABLED);
mDockAudioMediaEnabled.setPersistent(false);
mDockAudioMediaEnabled.setChecked(
Settings.Global.getInt(resolver,
Settings.Global.DOCK_AUDIO_MEDIA_ENABLED, 0) != 0);
} else {
mDockAudioSettings.setEnabled(false);
}
}
} else {
mDockAudioSettings.setEnabled(false);
}
}
}
@Override
public Dialog onCreateDialog(int id) {
if (id == DIALOG_NOT_DOCKED) {
return createUndockedMessage();
}
return null;
}
private Dialog createUndockedMessage() {
final AlertDialog.Builder ab = new AlertDialog.Builder(getActivity());
ab.setTitle(R.string.dock_not_found_title);
ab.setMessage(R.string.dock_not_found_text);
ab.setPositiveButton(android.R.string.ok, null);
return ab.create();
}
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
public List<String> getNonIndexableKeys(Context context) {
final List<String> keys = new ArrayList<String>();
int activePhoneType = TelephonyManager.getDefault().getCurrentPhoneType();
if (TelephonyManager.PHONE_TYPE_CDMA != activePhoneType) {
// device is not CDMA, do not display CDMA emergency_tone
keys.add(KEY_EMERGENCY_TONE);
}
return keys;
}
};
}

View File

@@ -23,6 +23,8 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.database.ContentObserver;
import android.database.Cursor;
import android.database.sqlite.SQLiteException;
import android.media.AudioManager;
import android.media.RingtoneManager;
import android.net.Uri;
@@ -36,16 +38,15 @@ import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceScreen;
import android.preference.SeekBarVolumizer;
import android.preference.TwoStatePreference;
import android.provider.MediaStore;
import android.provider.SearchIndexableResource;
import android.provider.Settings;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.SoundSettings;
import com.android.settings.Utils;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settings.search.Indexable.SearchIndexProvider;
import java.util.ArrayList;
import java.util.Arrays;
@@ -201,14 +202,14 @@ public class NotificationSettings extends SettingsPreferenceFragment implements
@Override
public void run() {
if (mPhoneRingtonePreference != null) {
final CharSequence summary = SoundSettings.updateRingtoneName(
final CharSequence summary = updateRingtoneName(
mContext, RingtoneManager.TYPE_RINGTONE);
if (summary != null) {
mHandler.obtainMessage(H.UPDATE_PHONE_RINGTONE, summary).sendToTarget();
}
}
if (mNotificationRingtonePreference != null) {
final CharSequence summary = SoundSettings.updateRingtoneName(
final CharSequence summary = updateRingtoneName(
mContext, RingtoneManager.TYPE_NOTIFICATION);
if (summary != null) {
mHandler.obtainMessage(H.UPDATE_NOTIFICATION_RINGTONE, summary).sendToTarget();
@@ -217,6 +218,35 @@ public class NotificationSettings extends SettingsPreferenceFragment implements
}
};
private static CharSequence updateRingtoneName(Context context, int type) {
if (context == null) return null;
Uri ringtoneUri = RingtoneManager.getActualDefaultRingtoneUri(context, type);
CharSequence summary = context.getString(com.android.internal.R.string.ringtone_unknown);
// Is it a silent ringtone?
if (ringtoneUri == null) {
summary = context.getString(com.android.internal.R.string.ringtone_silent);
} else {
// Fetch the ringtone title from the media provider
Cursor cursor = null;
try {
cursor = context.getContentResolver().query(ringtoneUri,
new String[] { MediaStore.Audio.Media.TITLE }, null, null, null);
if (cursor != null) {
if (cursor.moveToFirst()) {
summary = cursor.getString(0);
}
}
} catch (SQLiteException sqle) {
// Unknown title for the ringtone
} finally {
if (cursor != null) {
cursor.close();
}
}
}
return summary;
}
// === Vibrate when ringing ===
private void initVibrateWhenRinging(PreferenceScreen root) {

View File

@@ -0,0 +1,242 @@
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.notification;
import static com.android.settings.notification.SettingPref.TYPE_GLOBAL;
import static com.android.settings.notification.SettingPref.TYPE_SYSTEM;
import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
import android.media.AudioManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Vibrator;
import android.provider.SearchIndexableResource;
import android.provider.Settings.Global;
import android.provider.Settings.System;
import android.telephony.TelephonyManager;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.Utils;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class OtherSoundSettings extends SettingsPreferenceFragment implements Indexable {
private static final String TAG = "OtherSoundSettings";
private static final int DEFAULT_ON = 1;
private static final int EMERGENCY_TONE_SILENT = 0;
private static final int EMERGENCY_TONE_ALERT = 1;
private static final int EMERGENCY_TONE_VIBRATE = 2;
private static final int DEFAULT_EMERGENCY_TONE = EMERGENCY_TONE_SILENT;
private static final int DOCK_AUDIO_MEDIA_DISABLED = 0;
private static final int DOCK_AUDIO_MEDIA_ENABLED = 1;
private static final int DEFAULT_DOCK_AUDIO_MEDIA = DOCK_AUDIO_MEDIA_DISABLED;
private static final String KEY_DIAL_PAD_TONES = "dial_pad_tones";
private static final String KEY_SCREEN_LOCKING_SOUNDS = "screen_locking_sounds";
private static final String KEY_DOCKING_SOUNDS = "docking_sounds";
private static final String KEY_TOUCH_SOUNDS = "touch_sounds";
private static final String KEY_VIBRATE_ON_TOUCH = "vibrate_on_touch";
private static final String KEY_DOCK_AUDIO_MEDIA = "dock_audio_media";
private static final String KEY_EMERGENCY_TONE = "emergency_tone";
private static final SettingPref PREF_DIAL_PAD_TONES = new SettingPref(
TYPE_SYSTEM, KEY_DIAL_PAD_TONES, System.DTMF_TONE_WHEN_DIALING, DEFAULT_ON) {
@Override
public boolean isApplicable(Context context) {
return Utils.isVoiceCapable(context);
}
};
private static final SettingPref PREF_SCREEN_LOCKING_SOUNDS = new SettingPref(
TYPE_SYSTEM, KEY_SCREEN_LOCKING_SOUNDS, System.LOCKSCREEN_SOUNDS_ENABLED, DEFAULT_ON);
private static final SettingPref PREF_DOCKING_SOUNDS = new SettingPref(
TYPE_GLOBAL, KEY_DOCKING_SOUNDS, Global.DOCK_SOUNDS_ENABLED, DEFAULT_ON) {
@Override
public boolean isApplicable(Context context) {
return hasDockSettings(context);
}
};
private static final SettingPref PREF_TOUCH_SOUNDS = new SettingPref(
TYPE_SYSTEM, KEY_TOUCH_SOUNDS, System.SOUND_EFFECTS_ENABLED, DEFAULT_ON) {
@Override
protected boolean setSetting(Context context, int value) {
final AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
if (value != 0) {
am.loadSoundEffects();
} else {
am.unloadSoundEffects();
}
return super.setSetting(context, value);
}
};
private static final SettingPref PREF_VIBRATE_ON_TOUCH = new SettingPref(
TYPE_SYSTEM, KEY_VIBRATE_ON_TOUCH, System.HAPTIC_FEEDBACK_ENABLED, DEFAULT_ON) {
@Override
public boolean isApplicable(Context context) {
return hasHaptic(context);
}
};
private static final SettingPref PREF_DOCK_AUDIO_MEDIA = new SettingPref(
TYPE_GLOBAL, KEY_DOCK_AUDIO_MEDIA, Global.DOCK_AUDIO_MEDIA_ENABLED,
DEFAULT_DOCK_AUDIO_MEDIA, DOCK_AUDIO_MEDIA_DISABLED, DOCK_AUDIO_MEDIA_ENABLED) {
@Override
public boolean isApplicable(Context context) {
return hasDockSettings(context);
}
@Override
protected int getResId(Context context, int value) {
if (value == DOCK_AUDIO_MEDIA_DISABLED) return R.string.dock_audio_media_disabled;
if (value == DOCK_AUDIO_MEDIA_ENABLED) return R.string.dock_audio_media_enabled;
throw new IllegalArgumentException();
}
};
private static final SettingPref PREF_EMERGENCY_TONE = new SettingPref(
TYPE_GLOBAL, KEY_EMERGENCY_TONE, Global.EMERGENCY_TONE, DEFAULT_EMERGENCY_TONE,
EMERGENCY_TONE_ALERT, EMERGENCY_TONE_VIBRATE, EMERGENCY_TONE_SILENT) {
@Override
public boolean isApplicable(Context context) {
final int activePhoneType = TelephonyManager.getDefault().getCurrentPhoneType();
return activePhoneType == TelephonyManager.PHONE_TYPE_CDMA;
}
@Override
protected int getResId(Context context, int value) {
if (value == EMERGENCY_TONE_SILENT) return R.string.emergency_tone_silent;
if (value == EMERGENCY_TONE_ALERT) return R.string.emergency_tone_alert;
if (value == EMERGENCY_TONE_VIBRATE) return R.string.emergency_tone_vibrate;
throw new IllegalArgumentException();
}
};
private static final SettingPref[] PREFS = {
PREF_DIAL_PAD_TONES,
PREF_SCREEN_LOCKING_SOUNDS,
PREF_DOCKING_SOUNDS,
PREF_TOUCH_SOUNDS,
PREF_VIBRATE_ON_TOUCH,
PREF_DOCK_AUDIO_MEDIA,
PREF_EMERGENCY_TONE,
};
private final SettingsObserver mSettingsObserver = new SettingsObserver();
private Context mContext;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.other_sound_settings);
mContext = getActivity();
for (SettingPref pref : PREFS) {
pref.init(this);
}
}
@Override
public void onResume() {
super.onResume();
mSettingsObserver.register(true);
}
@Override
public void onPause() {
super.onPause();
mSettingsObserver.register(false);
}
private static boolean hasDockSettings(Context context) {
return context.getResources().getBoolean(R.bool.has_dock_settings);
}
private static boolean hasHaptic(Context context) {
final Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
return vibrator != null && vibrator.hasVibrator();
}
// === Callbacks ===
private final class SettingsObserver extends ContentObserver {
public SettingsObserver() {
super(new Handler());
}
public void register(boolean register) {
final ContentResolver cr = getContentResolver();
if (register) {
for (SettingPref pref : PREFS) {
cr.registerContentObserver(pref.getUri(), false, this);
}
} else {
cr.unregisterContentObserver(this);
}
}
@Override
public void onChange(boolean selfChange, Uri uri) {
super.onChange(selfChange, uri);
for (SettingPref pref : PREFS) {
if (pref.getUri().equals(uri)) {
pref.update(mContext);
return;
}
}
}
}
// === Indexing ===
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
public List<SearchIndexableResource> getXmlResourcesToIndex(
Context context, boolean enabled) {
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.other_sound_settings;
return Arrays.asList(sir);
}
public List<String> getNonIndexableKeys(Context context) {
final ArrayList<String> rt = new ArrayList<String>();
for (SettingPref pref : PREFS) {
if (!pref.isApplicable(context)) {
rt.add(pref.getKey());
}
}
return rt;
}
};
}

View File

@@ -0,0 +1,146 @@
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.notification;
import android.content.ContentResolver;
import android.content.Context;
import android.net.Uri;
import android.preference.Preference;
import android.preference.TwoStatePreference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.provider.Settings.Global;
import android.provider.Settings.System;
import com.android.settings.SettingsPreferenceFragment;
/** Helper to manage a two-state or dropdown preference bound to a global or system setting. */
public class SettingPref {
public static final int TYPE_GLOBAL = 1;
public static final int TYPE_SYSTEM = 2;
private final int mType;
private final String mKey;
private final String mSetting;
private final int mDefault;
private final int[] mValues;
private final Uri mUri;
private TwoStatePreference mTwoState;
private DropDownPreference mDropDown;
public SettingPref(int type, String key, String setting, int def, int... values) {
mType = type;
mKey = key;
mSetting = setting;
mDefault = def;
mValues = values;
mUri = getUriFor(mType, mSetting);
}
public boolean isApplicable(Context context) {
return true;
}
protected int getResId(Context context, int value) {
throw new UnsupportedOperationException();
}
public void init(SettingsPreferenceFragment settings) {
final Context context = settings.getActivity();
Preference p = settings.getPreferenceScreen().findPreference(mKey);
if (p != null && !isApplicable(context)) {
settings.getPreferenceScreen().removePreference(p);
p = null;
}
if (p instanceof TwoStatePreference) {
mTwoState = (TwoStatePreference) p;
} else if (p instanceof DropDownPreference) {
mDropDown = (DropDownPreference) p;
for (int value : mValues) {
mDropDown.addItem(getResId(context, value), value);
}
}
update(context);
if (mTwoState != null) {
p.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
setSetting(context, (Boolean) newValue ? 1 : 0);
return true;
}
});
} else if (mDropDown != null) {
mDropDown.setCallback(new DropDownPreference.Callback() {
@Override
public boolean onItemSelected(int pos, Object value) {
return setSetting(context, (Integer) value);
}
});
}
}
protected boolean setSetting(Context context, int value) {
return putInt(mType, context.getContentResolver(), mSetting, value);
}
public Uri getUri() {
return mUri;
}
public String getKey() {
return mKey;
}
public void update(Context context) {
final int val = getInt(mType, context.getContentResolver(), mSetting, mDefault);
if (mTwoState != null) {
mTwoState.setChecked(val != 0);
} else if (mDropDown != null) {
mDropDown.setSelectedValue(val);
}
}
private static Uri getUriFor(int type, String setting) {
switch(type) {
case TYPE_GLOBAL:
return Global.getUriFor(setting);
case TYPE_SYSTEM:
return System.getUriFor(setting);
}
throw new IllegalArgumentException();
}
private static boolean putInt(int type, ContentResolver cr, String setting, int value) {
switch(type) {
case TYPE_GLOBAL:
return Global.putInt(cr, setting, value);
case TYPE_SYSTEM:
return System.putInt(cr, setting, value);
}
throw new IllegalArgumentException();
}
private static int getInt(int type, ContentResolver cr, String setting, int def) {
switch(type) {
case TYPE_GLOBAL:
return Global.getInt(cr, setting, def);
case TYPE_SYSTEM:
return System.getInt(cr, setting, def);
}
throw new IllegalArgumentException();
}
}

View File

@@ -1,174 +0,0 @@
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.notification;
import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
import android.media.AudioManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Vibrator;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.TwoStatePreference;
import android.provider.Settings.System;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.Utils;
public class TouchSoundSettings extends SettingsPreferenceFragment {
private static final String TAG = "TouchSoundSettings";
private static final String KEY_DIAL_PAD_TONES = "dial_pad_tones";
private static final String KEY_SCREEN_LOCKING_SOUNDS = "screen_locking_sounds";
private static final String KEY_OTHER_TOUCH_SOUNDS = "other_touch_sounds";
private static final String KEY_VIBRATE_ON_TOUCH = "vibrate_on_touch";
private final Handler mHandler = new Handler();
private final SettingsObserver mSettingsObserver = new SettingsObserver();
private AudioManager mAudioManager;
private SystemSettingPref mDialPadTones;
private SystemSettingPref mScreenLockingSounds;
private SystemSettingPref mOtherTouchSounds;
private SystemSettingPref mVibrateOnTouch;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.touch_sound_settings);
mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
final boolean hasVoice = Utils.isVoiceCapable(getActivity());
final Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
final boolean hasHaptic = vibrator != null && vibrator.hasVibrator();
mDialPadTones = new SystemSettingPref(hasVoice,
KEY_DIAL_PAD_TONES, System.DTMF_TONE_WHEN_DIALING);
mScreenLockingSounds = new SystemSettingPref(true,
KEY_SCREEN_LOCKING_SOUNDS, System.LOCKSCREEN_SOUNDS_ENABLED);
mOtherTouchSounds = new SystemSettingPref(true,
KEY_OTHER_TOUCH_SOUNDS,System.SOUND_EFFECTS_ENABLED) {
@Override
protected void setSetting(boolean value) {
if (value) {
mAudioManager.loadSoundEffects();
} else {
mAudioManager.unloadSoundEffects();
}
super.setSetting(value);
}
};
mVibrateOnTouch = new SystemSettingPref(hasHaptic,
KEY_VIBRATE_ON_TOUCH, System.HAPTIC_FEEDBACK_ENABLED);
}
@Override
public void onResume() {
super.onResume();
mSettingsObserver.register(true);
}
@Override
public void onPause() {
super.onPause();
mSettingsObserver.register(false);
}
// === Common system setting preference helper ===
private class SystemSettingPref {
private final String mSetting;
private final Uri mUri;
private TwoStatePreference mPref;
private SystemSettingPref(boolean applicable, String key, String setting) {
mSetting = setting;
mUri = System.getUriFor(mSetting);
if (!applicable) removePreference(key);
mPref = (TwoStatePreference) getPreferenceScreen().findPreference(key);
if (mPref == null) return;
update();
mPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
setSetting((Boolean)newValue);
return true;
}
});
}
protected void setSetting(boolean value) {
System.putInt(getContentResolver(), mSetting, value ? 1 : 0);
}
private Uri getUri() {
return mUri;
}
private void update() {
if (mPref == null) return;
mPref.setChecked(System.getInt(getContentResolver(), mSetting, 1) != 0);
}
}
// === Callbacks ===
private final class SettingsObserver extends ContentObserver {
public SettingsObserver() {
super(mHandler);
}
public void register(boolean register) {
final ContentResolver cr = getContentResolver();
if (register) {
cr.registerContentObserver(mDialPadTones.getUri(), false, this);
cr.registerContentObserver(mScreenLockingSounds.getUri(), false, this);
cr.registerContentObserver(mOtherTouchSounds.getUri(), false, this);
cr.registerContentObserver(mVibrateOnTouch.getUri(), false, this);
} else {
cr.unregisterContentObserver(this);
}
}
@Override
public void onChange(boolean selfChange, Uri uri) {
super.onChange(selfChange, uri);
if (mDialPadTones.getUri().equals(uri)) {
mDialPadTones.update();
}
if (mScreenLockingSounds.getUri().equals(uri)) {
mScreenLockingSounds.update();
}
if (mOtherTouchSounds.getUri().equals(uri)) {
mOtherTouchSounds.update();
}
if (mVibrateOnTouch.getUri().equals(uri)) {
mVibrateOnTouch.update();
}
}
}
}

View File

@@ -27,7 +27,6 @@ import com.android.settings.HomeSettings;
import com.android.settings.PrivacySettings;
import com.android.settings.R;
import com.android.settings.SecuritySettings;
import com.android.settings.SoundSettings;
import com.android.settings.WallpaperTypeSettings;
import com.android.settings.WirelessSettings;
import com.android.settings.accessibility.AccessibilitySettings;
@@ -38,7 +37,7 @@ import com.android.settings.inputmethod.InputMethodAndLanguageSettings;
import com.android.settings.location.LocationSettings;
import com.android.settings.notification.NotificationDisplaySettings;
import com.android.settings.notification.NotificationSettings;
import com.android.settings.notification.TouchSoundSettings;
import com.android.settings.notification.OtherSoundSettings;
import com.android.settings.notification.ZenModeSettings;
import com.android.settings.print.PrintSettingsFragment;
import com.android.settings.users.UserSettings;
@@ -57,7 +56,6 @@ public final class SearchIndexableResources {
public static final int RANK_DATA_USAGE = 3;
public static final int RANK_WIRELESS = 4;
public static final int RANK_HOME = 5;
public static final int RANK_SOUND = 6;
public static final int RANK_DISPLAY = 7;
public static final int RANK_WALLPAPER = 7;
public static final int RANK_NOTIFICATIONS = 8;
@@ -115,12 +113,6 @@ public final class SearchIndexableResources {
HomeSettings.class.getName(),
R.drawable.ic_settings_home));
sResMap.put(SoundSettings.class.getName(),
new SearchIndexableResource(RANK_SOUND,
R.xml.sound_settings,
SoundSettings.class.getName(),
R.drawable.ic_settings_sound));
sResMap.put(DisplaySettings.class.getName(),
new SearchIndexableResource(RANK_DISPLAY,
R.xml.display_settings,
@@ -145,10 +137,10 @@ public final class SearchIndexableResources {
NotificationDisplaySettings.class.getName(),
R.drawable.ic_settings_notifications));
sResMap.put(TouchSoundSettings.class.getName(),
sResMap.put(OtherSoundSettings.class.getName(),
new SearchIndexableResource(RANK_NOTIFICATIONS,
R.xml.touch_sound_settings,
TouchSoundSettings.class.getName(),
NO_DATA_RES_ID,
OtherSoundSettings.class.getName(),
R.drawable.ic_settings_notifications));
sResMap.put(ZenModeSettings.class.getName(),