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

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