Settings: Hide phone-related settings on tablets.

Bug:15002393
Bug:15091008
Change-Id: I8238b7990572f46e1530a800897ab2d39a189055
This commit is contained in:
John Spurlock
2014-05-27 11:10:52 -04:00
parent 85ba0ee6ec
commit 57c713d1d9
5 changed files with 132 additions and 49 deletions

View File

@@ -5060,46 +5060,52 @@
<!-- Sounds & notifications: Settings header. [CHAR LIMIT=20] -->
<string name="notification_settings">Sounds &amp; Notifications</string>
<!-- Sounds & notifications: Title for the option managing media volume. [CHAR LIMIT=NONE] -->
<!-- Sounds & notifications: Title for the option managing media volume. [CHAR LIMIT=30] -->
<string name="media_volume_option_title">Media volume</string>
<!-- Sounds & notifications: Title for the option managing alarm volume. [CHAR LIMIT=NONE] -->
<!-- Sounds & notifications: Title for the option managing alarm volume. [CHAR LIMIT=30] -->
<string name="alarm_volume_option_title">Alarm volume</string>
<!-- Sounds & notifications: Title for the option managing ringer volume. [CHAR LIMIT=NONE] -->
<!-- Sounds & notifications: Title for the option managing ringer volume. [CHAR LIMIT=30] -->
<string name="ring_volume_option_title">Ring volume</string>
<!-- Sounds & notifications: Title for the Do not disturb option and associated settings page. [CHAR LIMIT=NONE] -->
<!-- Sounds & notifications: Title for the option managing notification volume. [CHAR LIMIT=30] -->
<string name="notification_volume_option_title">Notification volume</string>
<!-- Sounds & notifications: Title for the Do not disturb option and associated settings page. [CHAR LIMIT=30] -->
<string name="zen_mode_settings_title">Do not disturb</string>
<!-- Sounds & notifications: Title for the ringer mode option. [CHAR LIMIT=NONE] -->
<!-- Sounds & notifications: Title for the ringer mode option. [CHAR LIMIT=60] -->
<string name="ringer_mode_title">When calls and notifications arrive</string>
<!-- Sounds & notifications: Value for the ringer mode option when audible. [CHAR LIMIT=NONE] -->
<!-- Sounds & notifications: Title for the ringer mode option on devices without voice. [CHAR LIMIT=30] -->
<string name="ringer_mode_title_novoice">When notifications arrive</string>
<!-- Sounds & notifications: Value for the ringer mode option when audible. [CHAR LIMIT=30] -->
<string name="ringer_mode_audible">Ring</string>
<!-- Sounds & notifications: Value for the ringer mode option when vibrate. [CHAR LIMIT=NONE] -->
<!-- Sounds & notifications: Value for the ringer mode option when vibrate. [CHAR LIMIT=30] -->
<string name="ringer_mode_vibrate">Vibrate instead of ringing</string>
<!-- Sounds & notifications: Value for the ringer mode option when silent. [CHAR LIMIT=NONE] -->
<!-- Sounds & notifications: Value for the ringer mode option when silent. [CHAR LIMIT=30] -->
<string name="ringer_mode_silent">Don\'t ring or vibrate</string>
<!-- Sounds & notifications: Title for the option defining the phone ringtone. [CHAR LIMIT=NONE] -->
<!-- Sounds & notifications: Title for the option defining the phone ringtone. [CHAR LIMIT=30] -->
<string name="ringtone_title">Phone ringtone</string>
<!-- Sounds & notifications: Title for the option defining the default notification ringtone. [CHAR LIMIT=NONE] -->
<!-- Sounds & notifications: Title for the option defining the default notification ringtone. [CHAR LIMIT=30] -->
<string name="notification_ringtone_title">Default notification ringtone</string>
<!-- Sounds & notifications: Title for the option managing whether or not to vibrate when ringing. [CHAR LIMIT=NONE] -->
<!-- Sounds & notifications: Title for the option managing whether or not to vibrate when ringing. [CHAR LIMIT=30] -->
<string name="vibrate_when_ringing_title">Vibrate when ringing</string>
<!-- Sounds & notifications: Title for the showing notifications option and associated settings page. [CHAR LIMIT=NONE] -->
<!-- Sounds & notifications: Title for the showing notifications option and associated settings page. [CHAR LIMIT=30] -->
<string name="notification_display_settings">Showing notifications</string>
<!-- Sounds & notifications > Showing notifications: Title for the pulse notification light option. [CHAR LIMIT=NONE] -->
<!-- Sounds & notifications > Showing notifications: Title for the pulse notification light option. [CHAR LIMIT=30] -->
<string name="notification_pulse_title">Pulse notification light</string>
<!-- Sounds & notifications > Showing notifications: Title for the option controlling notifications on the lockscreen. [CHAR LIMIT=NONE] -->
<!-- Sounds & notifications > Showing notifications: Title for the option controlling notifications on the lockscreen. [CHAR LIMIT=30] -->
<string name="lock_screen_notifications_title">When device is locked</string>
<!-- Sounds & notifications > Showing notifications: Value for lockscreen notifications: all information will be
@@ -5116,7 +5122,7 @@
[CHAR LIMIT=50] -->
<string name="lock_screen_notifications_summary_disable">Don\'t show notifications at all</string>
<!-- Sounds & notifications > Showing notifications: Title for the option managing notification display in zen mode. [CHAR LIMIT=NONE] -->
<!-- Sounds & notifications > Showing notifications: Title for the option managing notification display in zen mode. [CHAR LIMIT=30] -->
<string name="zen_mode_notifications_title">When do not disturb is on</string>
<!-- Sounds & notifications > Showing notifications: Value for zen mode notifications: notifications will be suppressed in zen mode [CHAR LIMIT=50] -->
@@ -5125,25 +5131,25 @@
<!-- Sounds & notifications > Showing notifications: Value for zen mode notifications: notifications will be displayed in zen mode [CHAR LIMIT=50] -->
<string name="zen_mode_notifications_summary_show">Show all notifications in the list</string>
<!-- Sounds & notifications > Showing notifications: Title for the option managing notifications per application. [CHAR LIMIT=NONE] -->
<!-- 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=NONE] -->
<!-- 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 > Touch sounds: Title for the option enabling touch sounds for dial pad tones. [CHAR LIMIT=NONE] -->
<!-- Sounds & notifications > Touch 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=NONE] -->
<!-- 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 > Touch sounds: Title for the option enabling other touch sounds. [CHAR LIMIT=NONE] -->
<!-- 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 > Touch sounds: Title for the option enabling haptic feedback on touch. [CHAR LIMIT=NONE] -->
<!-- Sounds & notifications > Touch 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: Title for managing notification listeners option. [CHAR LIMIT=NONE] -->
<!-- Sounds & notifications: Title for managing notification listeners option. [CHAR LIMIT=30] -->
<string name="manage_notification_access_title">Notification access</string>
<!-- Summary of preference to manage notification listeners, when none are enabled -->

View File

@@ -37,6 +37,12 @@
android:icon="@*android:drawable/ic_audio_ring_notif"
android:title="@string/ring_volume_option_title" />
<!-- Notification volume -->
<com.android.settings.notification.VolumeSeekBarPreference
android:key="notification_volume"
android:icon="@*android:drawable/ic_audio_ring_notif"
android:title="@string/notification_volume_option_title" />
<!-- Do not disturb -->
<PreferenceScreen
android:key="zen_mode"

View File

@@ -36,18 +36,28 @@ import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceScreen;
import android.preference.SeekBarVolumizer;
import android.preference.TwoStatePreference;
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;
public class NotificationSettings extends SettingsPreferenceFragment {
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class NotificationSettings extends SettingsPreferenceFragment implements Indexable {
private static final String TAG = "NotificationSettings";
private static final String KEY_MEDIA_VOLUME = "media_volume";
private static final String KEY_ALARM_VOLUME = "alarm_volume";
private static final String KEY_RING_VOLUME = "ring_volume";
private static final String KEY_NOTIFICATION_VOLUME = "notification_volume";
private static final String KEY_RINGER_MODE = "ringer_mode";
private static final String KEY_PHONE_RINGTONE = "ringtone";
private static final String KEY_NOTIFICATION_RINGTONE = "notification_ringtone";
@@ -62,6 +72,7 @@ public class NotificationSettings extends SettingsPreferenceFragment {
private Context mContext;
private PackageManager mPM;
private boolean mVoiceCapable;
private DropDownPreference mRingerMode;
private Preference mPhoneRingtonePreference;
@@ -74,13 +85,19 @@ public class NotificationSettings extends SettingsPreferenceFragment {
super.onCreate(savedInstanceState);
mContext = getActivity();
mPM = mContext.getPackageManager();
mVoiceCapable = Utils.isVoiceCapable(mContext);
addPreferencesFromResource(R.xml.notification_settings);
final PreferenceScreen root = getPreferenceScreen();
initVolumePreference(KEY_MEDIA_VOLUME, AudioManager.STREAM_MUSIC);
initVolumePreference(KEY_ALARM_VOLUME, AudioManager.STREAM_ALARM);
initVolumePreference(KEY_RING_VOLUME, AudioManager.STREAM_RING);
if (mVoiceCapable) {
initVolumePreference(KEY_RING_VOLUME, AudioManager.STREAM_RING);
removePreference(KEY_NOTIFICATION_VOLUME);
} else {
initVolumePreference(KEY_NOTIFICATION_VOLUME, AudioManager.STREAM_NOTIFICATION);
removePreference(KEY_RING_VOLUME);
}
initRingerMode(root);
initRingtones(root);
initVibrateWhenRinging(root);
@@ -142,6 +159,9 @@ public class NotificationSettings extends SettingsPreferenceFragment {
private void initRingerMode(PreferenceScreen root) {
mRingerMode = (DropDownPreference) root.findPreference(KEY_RINGER_MODE);
if (mRingerMode == null) return;
if (!mVoiceCapable) {
mRingerMode.setTitle(R.string.ringer_mode_title_novoice);
}
final AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
mRingerMode.addItem(R.string.ringer_mode_audible, AudioManager.RINGER_MODE_NORMAL);
mRingerMode.addItem(R.string.ringer_mode_vibrate, AudioManager.RINGER_MODE_VIBRATE);
@@ -166,6 +186,10 @@ public class NotificationSettings extends SettingsPreferenceFragment {
private void initRingtones(PreferenceScreen root) {
mPhoneRingtonePreference = root.findPreference(KEY_PHONE_RINGTONE);
if (mPhoneRingtonePreference != null && !mVoiceCapable) {
root.removePreference(mPhoneRingtonePreference);
mPhoneRingtonePreference = null;
}
mNotificationRingtonePreference = root.findPreference(KEY_NOTIFICATION_RINGTONE);
}
@@ -196,8 +220,13 @@ public class NotificationSettings extends SettingsPreferenceFragment {
// === Vibrate when ringing ===
private void initVibrateWhenRinging(PreferenceScreen root) {
mVibrateWhenRinging = (TwoStatePreference) findPreference(KEY_VIBRATE_WHEN_RINGING);
mVibrateWhenRinging = (TwoStatePreference) root.findPreference(KEY_VIBRATE_WHEN_RINGING);
if (mVibrateWhenRinging == null) return;
if (!mVoiceCapable) {
root.removePreference(mVibrateWhenRinging);
mVibrateWhenRinging = null;
return;
}
mVibrateWhenRinging.setPersistent(false);
updateVibrateWhenRinging();
mVibrateWhenRinging.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@@ -299,4 +328,29 @@ public class NotificationSettings extends SettingsPreferenceFragment {
}
}
}
// === 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.notification_settings;
return Arrays.asList(sir);
}
public List<String> getNonIndexableKeys(Context context) {
final ArrayList<String> rt = new ArrayList<String>();
if (Utils.isVoiceCapable(context)) {
rt.add(KEY_NOTIFICATION_VOLUME);
} else {
rt.add(KEY_RING_VOLUME);
rt.add(KEY_PHONE_RINGTONE);
rt.add(KEY_VIBRATE_WHEN_RINGING);
}
return rt;
}
};
}

View File

@@ -55,6 +55,7 @@ import android.widget.TimePicker;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.Utils;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settings.search.SearchIndexableRaw;
@@ -83,12 +84,12 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
private static final String KEY_ENTRY = "entry";
private static final String KEY_CONDITION_PROVIDERS = "manage_condition_providers";
private static final SparseArray<String> ALL_KEY_TITLES = allKeyTitles();
private static SparseArray<String> allKeyTitles() {
private static SparseArray<String> allKeyTitles(Context context) {
final SparseArray<String> rt = new SparseArray<String>();
rt.put(R.string.zen_mode_general_category, KEY_GENERAL);
rt.put(R.string.zen_mode_phone_calls, KEY_CALLS);
if (Utils.isVoiceCapable(context)) {
rt.put(R.string.zen_mode_phone_calls, KEY_CALLS);
}
rt.put(R.string.zen_mode_messages, KEY_MESSAGES);
rt.put(R.string.zen_mode_automatic_category, KEY_AUTOMATIC);
rt.put(R.string.zen_mode_when, KEY_WHEN);
@@ -159,21 +160,26 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
final PreferenceCategory general = (PreferenceCategory) root.findPreference(KEY_GENERAL);
mCalls = (SwitchPreference) root.findPreference(KEY_CALLS);
mCalls.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (mDisableListeners) return true;
final boolean val = (Boolean) newValue;
if (val == mConfig.allowCalls) return true;
if (DEBUG) Log.d(TAG, "onPrefChange allowCalls=" + val);
final ZenModeConfig newConfig = mConfig.copy();
newConfig.allowCalls = val;
return setZenModeConfig(newConfig);
}
});
mCalls = (SwitchPreference) general.findPreference(KEY_CALLS);
if (Utils.isVoiceCapable(mContext)) {
mCalls.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (mDisableListeners) return true;
final boolean val = (Boolean) newValue;
if (val == mConfig.allowCalls) return true;
if (DEBUG) Log.d(TAG, "onPrefChange allowCalls=" + val);
final ZenModeConfig newConfig = mConfig.copy();
newConfig.allowCalls = val;
return setZenModeConfig(newConfig);
}
});
} else {
general.removePreference(mCalls);
mCalls = null;
}
mMessages = (SwitchPreference) root.findPreference(KEY_MESSAGES);
mMessages = (SwitchPreference) general.findPreference(KEY_MESSAGES);
mMessages.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
@@ -307,7 +313,9 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
private void updateControls() {
mDisableListeners = true;
mCalls.setChecked(mConfig.allowCalls);
if (mCalls != null) {
mCalls.setChecked(mConfig.allowCalls);
}
mMessages.setChecked(mConfig.allowMessages);
mStarred.setSelectedItem(0);
mWhen.setSelectedValue(mConfig.sleepMode);
@@ -470,18 +478,27 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
new BaseSearchIndexProvider() {
@Override
public List<SearchIndexableRaw> getRawDataToIndex(Context context, boolean enabled) {
final int N = ALL_KEY_TITLES.size();
final SparseArray<String> keyTitles = allKeyTitles(context);
final int N = keyTitles.size();
final List<SearchIndexableRaw> result = new ArrayList<SearchIndexableRaw>(N);
final Resources res = context.getResources();
for (int i = 0; i < N; i++) {
final SearchIndexableRaw data = new SearchIndexableRaw(context);
data.key = ALL_KEY_TITLES.valueAt(i);
data.title = res.getString(ALL_KEY_TITLES.keyAt(i));
data.key = keyTitles.valueAt(i);
data.title = res.getString(keyTitles.keyAt(i));
data.screenTitle = res.getString(R.string.zen_mode_settings_title);
result.add(data);
}
return result;
}
public List<String> getNonIndexableKeys(Context context) {
final ArrayList<String> rt = new ArrayList<String>();
if (!Utils.isVoiceCapable(context)) {
rt.add(KEY_CALLS);
}
return rt;
}
};
private final class SettingsObserver extends ContentObserver {

View File

@@ -135,7 +135,7 @@ public final class SearchIndexableResources {
sResMap.put(NotificationSettings.class.getName(),
new SearchIndexableResource(RANK_NOTIFICATIONS,
R.xml.notification_settings,
NO_DATA_RES_ID,
NotificationSettings.class.getName(),
R.drawable.ic_settings_notifications));