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

@@ -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();
}
}
}
}