Merge "Settings: Update to follow new volume design."

This commit is contained in:
John Spurlock
2014-07-07 23:27:13 +00:00
committed by Android (Google) Code Review
18 changed files with 521 additions and 619 deletions

View File

@@ -88,7 +88,6 @@ public class Settings extends SettingsActivity {
public static class PrintJobSettingsActivity extends SettingsActivity { /* empty */ }
public static class ZenModeSettingsActivity extends SettingsActivity { /* empty */ }
public static class NotificationSettingsActivity extends SettingsActivity { /* empty */ }
public static class NotificationDisplaySettingsActivity extends SettingsActivity { /* empty */ }
public static class AppNotificationSettingsActivity extends SettingsActivity { /* empty */ }
public static class OtherSoundSettingsActivity extends SettingsActivity { /* empty */ }

View File

@@ -353,7 +353,7 @@ public class AppNotificationSettings extends ListFragment {
public void bindView(final View view, Row r, boolean animate) {
if (!(r instanceof AppRow)) {
// it's a section row
TextView tv = (TextView)view;
final TextView tv = (TextView)view.findViewById(android.R.id.title);
tv.setText(r.section);
return;
}

View File

@@ -1,184 +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.database.ContentObserver;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceScreen;
import android.preference.TwoStatePreference;
import android.provider.Settings;
import android.util.Log;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
public class NotificationDisplaySettings extends SettingsPreferenceFragment {
private static final String TAG = "NotificationDisplaySettings";
private static final String KEY_NOTIFICATION_PULSE = "notification_pulse";
private static final String KEY_LOCK_SCREEN_NOTIFICATIONS = "lock_screen_notifications";
private final Handler mHandler = new Handler();
private final SettingsObserver mSettingsObserver = new SettingsObserver();
private TwoStatePreference mNotificationPulse;
private DropDownPreference mLockscreen;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.notification_display_settings);
final PreferenceScreen root = getPreferenceScreen();
initPulse(root);
initLockscreenNotifications(root);
}
@Override
public void onResume() {
super.onResume();
mSettingsObserver.register(true);
}
@Override
public void onPause() {
super.onPause();
mSettingsObserver.register(false);
}
// === Pulse notification light ===
private void initPulse(PreferenceScreen parent) {
mNotificationPulse = (TwoStatePreference) parent.findPreference(KEY_NOTIFICATION_PULSE);
if (mNotificationPulse == null) return;
if (!getResources()
.getBoolean(com.android.internal.R.bool.config_intrusiveNotificationLed)) {
parent.removePreference(mNotificationPulse);
} else {
updatePulse();
mNotificationPulse.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean val = (Boolean)newValue;
return Settings.System.putInt(getContentResolver(),
Settings.System.NOTIFICATION_LIGHT_PULSE,
val ? 1 : 0);
}
});
}
}
private void updatePulse() {
if (mNotificationPulse == null) return;
try {
mNotificationPulse.setChecked(Settings.System.getInt(getContentResolver(),
Settings.System.NOTIFICATION_LIGHT_PULSE) == 1);
} catch (Settings.SettingNotFoundException snfe) {
Log.e(TAG, Settings.System.NOTIFICATION_LIGHT_PULSE + " not found");
}
}
// === Lockscreen (public / private) notifications ===
private void initLockscreenNotifications(PreferenceScreen parent) {
mLockscreen = (DropDownPreference) parent.findPreference(KEY_LOCK_SCREEN_NOTIFICATIONS);
if (mLockscreen == null) return;
mLockscreen.addItem(R.string.lock_screen_notifications_summary_show,
R.string.lock_screen_notifications_summary_show);
mLockscreen.addItem(R.string.lock_screen_notifications_summary_hide,
R.string.lock_screen_notifications_summary_hide);
mLockscreen.addItem(R.string.lock_screen_notifications_summary_disable,
R.string.lock_screen_notifications_summary_disable);
updateLockscreenNotifications();
mLockscreen.setCallback(new DropDownPreference.Callback() {
@Override
public boolean onItemSelected(int pos, Object value) {
final int val = (Integer) value;
final boolean enabled = val != R.string.lock_screen_notifications_summary_disable;
final boolean show = val == R.string.lock_screen_notifications_summary_show;
Settings.Secure.putInt(getContentResolver(),
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, show ? 1 : 0);
Settings.Global.putInt(getContentResolver(),
Settings.Global.LOCK_SCREEN_SHOW_NOTIFICATIONS, enabled ? 1 : 0);
return true;
}
});
}
private void updateLockscreenNotifications() {
if (mLockscreen == null) return;
final boolean allowPrivate = getLockscreenAllowPrivateNotifications();
final boolean enabled = getLockscreenNotificationsEnabled();
final int val = !enabled ? R.string.lock_screen_notifications_summary_disable :
allowPrivate ? R.string.lock_screen_notifications_summary_show :
R.string.lock_screen_notifications_summary_hide;
mLockscreen.setSelectedValue(val);
}
private boolean getLockscreenNotificationsEnabled() {
return Settings.Global.getInt(getContentResolver(),
Settings.Global.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0) != 0;
}
private boolean getLockscreenAllowPrivateNotifications() {
return Settings.Secure.getInt(getContentResolver(),
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0) != 0;
}
// === Callbacks ===
private final class SettingsObserver extends ContentObserver {
private final Uri NOTIFICATION_LIGHT_PULSE_URI =
Settings.System.getUriFor(Settings.System.NOTIFICATION_LIGHT_PULSE);
private final Uri LOCK_SCREEN_PRIVATE_URI =
Settings.Secure.getUriFor(Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS);
private final Uri LOCK_SCREEN_SHOW_URI =
Settings.Global.getUriFor(Settings.Global.LOCK_SCREEN_SHOW_NOTIFICATIONS);
public SettingsObserver() {
super(mHandler);
}
public void register(boolean register) {
final ContentResolver cr = getContentResolver();
if (register) {
cr.registerContentObserver(NOTIFICATION_LIGHT_PULSE_URI, false, this);
cr.registerContentObserver(LOCK_SCREEN_PRIVATE_URI, false, this);
cr.registerContentObserver(LOCK_SCREEN_SHOW_URI, false, this);
} else {
cr.unregisterContentObserver(this);
}
}
@Override
public void onChange(boolean selfChange, Uri uri) {
super.onChange(selfChange, uri);
if (NOTIFICATION_LIGHT_PULSE_URI.equals(uri)) {
updatePulse();
}
if (LOCK_SCREEN_PRIVATE_URI.equals(uri) || LOCK_SCREEN_SHOW_URI.equals(uri)) {
updateLockscreenNotifications();
}
}
}
}

View File

@@ -16,11 +16,8 @@
package com.android.settings.notification;
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.database.ContentObserver;
import android.database.Cursor;
@@ -35,12 +32,13 @@ import android.os.Looper;
import android.os.Message;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceScreen;
import android.preference.PreferenceCategory;
import android.preference.SeekBarVolumizer;
import android.preference.TwoStatePreference;
import android.provider.MediaStore;
import android.provider.SearchIndexableResource;
import android.provider.Settings;
import android.util.Log;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
@@ -55,14 +53,17 @@ import java.util.List;
public class NotificationSettings extends SettingsPreferenceFragment implements Indexable {
private static final String TAG = "NotificationSettings";
private static final String KEY_SOUND = "sound";
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";
private static final String KEY_VIBRATE_WHEN_RINGING = "vibrate_when_ringing";
private static final String KEY_NOTIFICATION = "notification";
private static final String KEY_NOTIFICATION_PULSE = "notification_pulse";
private static final String KEY_LOCK_SCREEN_NOTIFICATIONS = "lock_screen_notifications";
private static final String KEY_NOTIFICATION_ACCESS = "manage_notification_access";
private static final int SAMPLE_CUTOFF = 2000; // manually cap sample playback at 2 seconds
@@ -75,10 +76,11 @@ public class NotificationSettings extends SettingsPreferenceFragment implements
private PackageManager mPM;
private boolean mVoiceCapable;
private DropDownPreference mRingerMode;
private Preference mPhoneRingtonePreference;
private Preference mNotificationRingtonePreference;
private TwoStatePreference mVibrateWhenRinging;
private TwoStatePreference mNotificationPulse;
private DropDownPreference mLockscreen;
private Preference mNotificationAccess;
@Override
@@ -89,19 +91,23 @@ public class NotificationSettings extends SettingsPreferenceFragment implements
mVoiceCapable = Utils.isVoiceCapable(mContext);
addPreferencesFromResource(R.xml.notification_settings);
final PreferenceScreen root = getPreferenceScreen();
final PreferenceCategory sound = (PreferenceCategory) findPreference(KEY_SOUND);
initVolumePreference(KEY_MEDIA_VOLUME, AudioManager.STREAM_MUSIC);
initVolumePreference(KEY_ALARM_VOLUME, AudioManager.STREAM_ALARM);
if (mVoiceCapable) {
initVolumePreference(KEY_RING_VOLUME, AudioManager.STREAM_RING);
removePreference(KEY_NOTIFICATION_VOLUME);
sound.removePreference(sound.findPreference(KEY_NOTIFICATION_VOLUME));
} else {
initVolumePreference(KEY_NOTIFICATION_VOLUME, AudioManager.STREAM_NOTIFICATION);
removePreference(KEY_RING_VOLUME);
sound.removePreference(sound.findPreference(KEY_RING_VOLUME));
}
initRingerMode(root);
initRingtones(root);
initVibrateWhenRinging(root);
initRingtones(sound);
initVibrateWhenRinging(sound);
final PreferenceCategory notification = (PreferenceCategory)
findPreference(KEY_NOTIFICATION);
initPulse(notification);
initLockscreenNotifications(notification);
mNotificationAccess = findPreference(KEY_NOTIFICATION_ACCESS);
refreshNotificationListeners();
@@ -112,8 +118,6 @@ public class NotificationSettings extends SettingsPreferenceFragment implements
super.onResume();
refreshNotificationListeners();
lookupRingtoneNames();
final IntentFilter filter = new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION);
mContext.registerReceiver(mReceiver, filter);
mSettingsObserver.register(true);
}
@@ -121,7 +125,6 @@ public class NotificationSettings extends SettingsPreferenceFragment implements
public void onPause() {
super.onPause();
mVolumeCallback.stopSample();
mContext.unregisterReceiver(mReceiver);
mSettingsObserver.register(false);
}
@@ -155,37 +158,10 @@ public class NotificationSettings extends SettingsPreferenceFragment implements
}
};
// === Ringer mode ===
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);
mRingerMode.addItem(R.string.ringer_mode_silent, AudioManager.RINGER_MODE_SILENT);
updateRingerMode();
mRingerMode.setCallback(new DropDownPreference.Callback() {
@Override
public boolean onItemSelected(int pos, Object value) {
final int val = (Integer) value;
am.setRingerMode(val);
return true;
}
});
}
private void updateRingerMode() {
final AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
mRingerMode.setSelectedValue(am.getRingerMode());
}
// === Phone & notification ringtone ===
private void initRingtones(PreferenceScreen root) {
private void initRingtones(PreferenceCategory root) {
mPhoneRingtonePreference = root.findPreference(KEY_PHONE_RINGTONE);
if (mPhoneRingtonePreference != null && !mVoiceCapable) {
root.removePreference(mPhoneRingtonePreference);
@@ -219,7 +195,10 @@ public class NotificationSettings extends SettingsPreferenceFragment implements
};
private static CharSequence updateRingtoneName(Context context, int type) {
if (context == null) return null;
if (context == null) {
Log.e(TAG, "Unable to update ringtone name, no context provided");
return null;
}
Uri ringtoneUri = RingtoneManager.getActualDefaultRingtoneUri(context, type);
CharSequence summary = context.getString(com.android.internal.R.string.ringtone_unknown);
// Is it a silent ringtone?
@@ -249,9 +228,12 @@ public class NotificationSettings extends SettingsPreferenceFragment implements
// === Vibrate when ringing ===
private void initVibrateWhenRinging(PreferenceScreen root) {
private void initVibrateWhenRinging(PreferenceCategory root) {
mVibrateWhenRinging = (TwoStatePreference) root.findPreference(KEY_VIBRATE_WHEN_RINGING);
if (mVibrateWhenRinging == null) return;
if (mVibrateWhenRinging == null) {
Log.i(TAG, "Preference not found: " + KEY_VIBRATE_WHEN_RINGING);
return;
}
if (!mVoiceCapable) {
root.removePreference(mVibrateWhenRinging);
mVibrateWhenRinging = null;
@@ -276,6 +258,95 @@ public class NotificationSettings extends SettingsPreferenceFragment implements
Settings.System.VIBRATE_WHEN_RINGING, 0) != 0);
}
// === Pulse notification light ===
private void initPulse(PreferenceCategory parent) {
mNotificationPulse = (TwoStatePreference) parent.findPreference(KEY_NOTIFICATION_PULSE);
if (mNotificationPulse == null) {
Log.i(TAG, "Preference not found: " + KEY_NOTIFICATION_PULSE);
return;
}
if (!getResources()
.getBoolean(com.android.internal.R.bool.config_intrusiveNotificationLed)) {
parent.removePreference(mNotificationPulse);
} else {
updatePulse();
mNotificationPulse.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean val = (Boolean)newValue;
return Settings.System.putInt(getContentResolver(),
Settings.System.NOTIFICATION_LIGHT_PULSE,
val ? 1 : 0);
}
});
}
}
private void updatePulse() {
if (mNotificationPulse == null) {
return;
}
try {
mNotificationPulse.setChecked(Settings.System.getInt(getContentResolver(),
Settings.System.NOTIFICATION_LIGHT_PULSE) == 1);
} catch (Settings.SettingNotFoundException snfe) {
Log.e(TAG, Settings.System.NOTIFICATION_LIGHT_PULSE + " not found");
}
}
// === Lockscreen (public / private) notifications ===
private void initLockscreenNotifications(PreferenceCategory parent) {
mLockscreen = (DropDownPreference) parent.findPreference(KEY_LOCK_SCREEN_NOTIFICATIONS);
if (mLockscreen == null) {
Log.i(TAG, "Preference not found: " + KEY_LOCK_SCREEN_NOTIFICATIONS);
return;
}
mLockscreen.addItem(R.string.lock_screen_notifications_summary_show,
R.string.lock_screen_notifications_summary_show);
mLockscreen.addItem(R.string.lock_screen_notifications_summary_hide,
R.string.lock_screen_notifications_summary_hide);
mLockscreen.addItem(R.string.lock_screen_notifications_summary_disable,
R.string.lock_screen_notifications_summary_disable);
updateLockscreenNotifications();
mLockscreen.setCallback(new DropDownPreference.Callback() {
@Override
public boolean onItemSelected(int pos, Object value) {
final int val = (Integer) value;
final boolean enabled = val != R.string.lock_screen_notifications_summary_disable;
final boolean show = val == R.string.lock_screen_notifications_summary_show;
Settings.Secure.putInt(getContentResolver(),
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, show ? 1 : 0);
Settings.Global.putInt(getContentResolver(),
Settings.Global.LOCK_SCREEN_SHOW_NOTIFICATIONS, enabled ? 1 : 0);
return true;
}
});
}
private void updateLockscreenNotifications() {
if (mLockscreen == null) {
return;
}
final boolean allowPrivate = getLockscreenAllowPrivateNotifications();
final boolean enabled = getLockscreenNotificationsEnabled();
final int selectedVal = !enabled ? R.string.lock_screen_notifications_summary_disable :
allowPrivate ? R.string.lock_screen_notifications_summary_show :
R.string.lock_screen_notifications_summary_hide;
mLockscreen.setSelectedValue(selectedVal);
}
private boolean getLockscreenNotificationsEnabled() {
return Settings.Global.getInt(getContentResolver(),
Settings.Global.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0) != 0;
}
private boolean getLockscreenAllowPrivateNotifications() {
return Settings.Secure.getInt(getContentResolver(),
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0) != 0;
}
// === Notification listeners ===
private void refreshNotificationListeners() {
@@ -299,18 +370,15 @@ public class NotificationSettings extends SettingsPreferenceFragment implements
// === Callbacks ===
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (AudioManager.RINGER_MODE_CHANGED_ACTION.equals(intent.getAction())) {
updateRingerMode();
}
}
};
private final class SettingsObserver extends ContentObserver {
private final Uri VIBRATE_WHEN_RINGING_URI =
Settings.System.getUriFor(Settings.System.VIBRATE_WHEN_RINGING);
private final Uri NOTIFICATION_LIGHT_PULSE_URI =
Settings.System.getUriFor(Settings.System.NOTIFICATION_LIGHT_PULSE);
private final Uri LOCK_SCREEN_PRIVATE_URI =
Settings.Secure.getUriFor(Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS);
private final Uri LOCK_SCREEN_SHOW_URI =
Settings.Global.getUriFor(Settings.Global.LOCK_SCREEN_SHOW_NOTIFICATIONS);
public SettingsObserver() {
super(mHandler);
@@ -320,6 +388,9 @@ public class NotificationSettings extends SettingsPreferenceFragment implements
final ContentResolver cr = getContentResolver();
if (register) {
cr.registerContentObserver(VIBRATE_WHEN_RINGING_URI, false, this);
cr.registerContentObserver(NOTIFICATION_LIGHT_PULSE_URI, false, this);
cr.registerContentObserver(LOCK_SCREEN_PRIVATE_URI, false, this);
cr.registerContentObserver(LOCK_SCREEN_SHOW_URI, false, this);
} else {
cr.unregisterContentObserver(this);
}
@@ -331,6 +402,12 @@ public class NotificationSettings extends SettingsPreferenceFragment implements
if (VIBRATE_WHEN_RINGING_URI.equals(uri)) {
updateVibrateWhenRinging();
}
if (NOTIFICATION_LIGHT_PULSE_URI.equals(uri)) {
updatePulse();
}
if (LOCK_SCREEN_PRIVATE_URI.equals(uri) || LOCK_SCREEN_SHOW_URI.equals(uri)) {
updateLockscreenNotifications();
}
}
}

View File

@@ -60,7 +60,7 @@ public class SettingPref {
throw new UnsupportedOperationException();
}
public void init(SettingsPreferenceFragment settings) {
public Preference init(SettingsPreferenceFragment settings) {
final Context context = settings.getActivity();
Preference p = settings.getPreferenceScreen().findPreference(mKey);
if (p != null && !isApplicable(context)) {
@@ -84,14 +84,18 @@ public class SettingPref {
return true;
}
});
} else if (mDropDown != null) {
return mTwoState;
}
if (mDropDown != null) {
mDropDown.setCallback(new DropDownPreference.Callback() {
@Override
public boolean onItemSelected(int pos, Object value) {
return setSetting(context, (Integer) value);
}
});
return mDropDown;
}
return null;
}
protected boolean setSetting(Context context, int value) {

View File

@@ -0,0 +1,90 @@
/*
* 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.Context;
import android.service.notification.ZenModeConfig;
import android.util.SparseBooleanArray;
import android.view.LayoutInflater;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.LinearLayout;
import com.android.settings.R;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class ZenModeDowntimeDaysSelection extends LinearLayout {
private static final int[] DAYS = {
Calendar.MONDAY, Calendar.TUESDAY, Calendar.WEDNESDAY, Calendar.THURSDAY, Calendar.FRIDAY,
Calendar.SATURDAY, Calendar.SUNDAY
};
private static final SimpleDateFormat DAY_FORMAT = new SimpleDateFormat("EEEE");
private final SparseBooleanArray mDays = new SparseBooleanArray();
public ZenModeDowntimeDaysSelection(Context context, String mode) {
super(context);
final int[] days = ZenModeConfig.tryParseDays(mode);
if (days != null) {
for (int i = 0; i < days.length; i++) {
mDays.put(days[i], true);
}
}
setOrientation(VERTICAL);
final Calendar c = Calendar.getInstance();
final LayoutInflater inflater = LayoutInflater.from(context);
for (int i = 0; i < DAYS.length; i++) {
final int day = DAYS[i];
final CheckBox checkBox = (CheckBox) inflater.inflate(R.layout.zen_downtime_day,
this, false);
c.set(Calendar.DAY_OF_WEEK, day);
checkBox.setText(DAY_FORMAT.format(c.getTime()));
checkBox.setChecked(mDays.get(day));
checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mDays.put(day, isChecked);
onChanged(getMode());
}
});
addView(checkBox);
}
}
private String getMode() {
final StringBuilder sb = new StringBuilder(ZenModeConfig.SLEEP_MODE_DAYS_PREFIX);
boolean empty = true;
for (int i = 0; i < mDays.size(); i++) {
final int day = mDays.keyAt(i);
if (!mDays.valueAt(i)) continue;
if (empty) {
empty = false;
} else {
sb.append(',');
}
sb.append(day);
}
return empty ? null : sb.toString();
}
protected void onChanged(String mode) {
// event hook for subclasses
}
}

View File

@@ -30,7 +30,6 @@ import android.content.res.Resources;
import android.database.ContentObserver;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.ServiceManager;
@@ -48,37 +47,34 @@ import android.util.Log;
import android.util.SparseArray;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Switch;
import android.widget.TextView;
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;
import com.android.settings.widget.SwitchBar;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Objects;
public class ZenModeSettings extends SettingsPreferenceFragment implements Indexable,
SwitchBar.OnSwitchChangeListener {
public class ZenModeSettings extends SettingsPreferenceFragment implements Indexable {
private static final String TAG = "ZenModeSettings";
private static final boolean DEBUG = true;
private static final boolean SHOW_CONDITION_DIALOG = false;
private static final String KEY_GENERAL = "general";
private static final String KEY_ZEN_MODE = "zen_mode";
private static final String KEY_IMPORTANT = "important";
private static final String KEY_CALLS = "phone_calls";
private static final String KEY_MESSAGES = "messages";
private static final String KEY_STARRED = "starred";
private static final String KEY_AUTOMATIC = "automatic";
private static final String KEY_WHEN = "when";
private static final String KEY_DOWNTIME = "downtime";
private static final String KEY_DAYS = "days";
private static final String KEY_START_TIME = "start_time";
private static final String KEY_END_TIME = "end_time";
@@ -86,16 +82,36 @@ 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 SettingPref PREF_ZEN_MODE = new SettingPref(SettingPref.TYPE_GLOBAL,
KEY_ZEN_MODE, Global.ZEN_MODE, Global.ZEN_MODE_OFF, Global.ZEN_MODE_OFF,
Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS, Global.ZEN_MODE_NO_INTERRUPTIONS) {
protected String getCaption(Resources res, int value) {
switch (value) {
case Global.ZEN_MODE_NO_INTERRUPTIONS:
return res.getString(R.string.zen_mode_option_no_interruptions);
case Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS:
return res.getString(R.string.zen_mode_option_important_interruptions);
default:
return res.getString(R.string.zen_mode_option_off);
}
}
};
private static final SimpleDateFormat DAY_FORMAT = new SimpleDateFormat("EEE");
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_important_category, KEY_IMPORTANT);
if (Utils.isVoiceCapable(context)) {
rt.put(R.string.zen_mode_phone_calls, KEY_CALLS);
rt.put(R.string.zen_mode_option_title, KEY_ZEN_MODE);
} else {
rt.put(R.string.zen_mode_option_title_novoice, KEY_ZEN_MODE);
}
rt.put(R.string.zen_mode_messages, KEY_MESSAGES);
rt.put(R.string.zen_mode_from_starred, KEY_STARRED);
rt.put(R.string.zen_mode_automatic_category, KEY_AUTOMATIC);
rt.put(R.string.zen_mode_when, KEY_WHEN);
rt.put(R.string.zen_mode_downtime_category, KEY_DOWNTIME);
rt.put(R.string.zen_mode_downtime_days, KEY_DAYS);
rt.put(R.string.zen_mode_start_time, KEY_START_TIME);
rt.put(R.string.zen_mode_end_time, KEY_END_TIME);
rt.put(R.string.zen_mode_automation_category, KEY_AUTOMATION);
@@ -106,7 +122,6 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
private final Handler mHandler = new Handler();
private final SettingsObserver mSettingsObserver = new SettingsObserver();
private SwitchBar mSwitchBar;
private Context mContext;
private PackageManager mPM;
private ZenModeConfig mConfig;
@@ -114,42 +129,20 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
private SwitchPreference mCalls;
private SwitchPreference mMessages;
private DropDownPreference mStarred;
private DropDownPreference mWhen;
private Preference mDays;
private TimePickerPreference mStart;
private TimePickerPreference mEnd;
private PreferenceCategory mAutomationCategory;
private Preference mEntry;
private Preference mConditionProviders;
private AlertDialog mDialog;
private boolean mIgnoreNext;
@Override
public void onSwitchChanged(Switch switchView, final boolean isChecked) {
if (DEBUG) Log.d(TAG, "onPreferenceChange isChecked=" + isChecked
+ " mIgnoreNext=" + mIgnoreNext);
if (mIgnoreNext) {
mIgnoreNext = false;
}
AsyncTask.execute(new Runnable() {
@Override
public void run() {
final int v = isChecked ? Global.ZEN_MODE_ON : Global.ZEN_MODE_OFF;
putZenModeSetting(v);
final int n = ConditionProviderSettings.getEnabledProviderCount(mContext);
if (SHOW_CONDITION_DIALOG && n > 0) {
mHandler.post(isChecked ? mShowDialog : mHideDialog);
}
}
});
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = getActivity();
mPM = mContext.getPackageManager();
final Resources res = mContext.getResources();
final int p = res.getDimensionPixelSize(R.dimen.content_margin_left);
final int padding = res.getDimensionPixelSize(R.dimen.content_margin_left);
addPreferencesFromResource(R.xml.zen_mode_settings);
final PreferenceScreen root = getPreferenceScreen();
@@ -157,13 +150,15 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
mConfig = getZenModeConfig();
if (DEBUG) Log.d(TAG, "Loaded mConfig=" + mConfig);
mSwitchBar = ((SettingsActivity) mContext).getSwitchBar();
mSwitchBar.addOnSwitchChangeListener(this);
mSwitchBar.show();
final Preference zenMode = PREF_ZEN_MODE.init(this);
if (!Utils.isVoiceCapable(mContext)) {
zenMode.setTitle(R.string.zen_mode_option_title_novoice);
}
final PreferenceCategory general = (PreferenceCategory) root.findPreference(KEY_GENERAL);
final PreferenceCategory important =
(PreferenceCategory) root.findPreference(KEY_IMPORTANT);
mCalls = (SwitchPreference) general.findPreference(KEY_CALLS);
mCalls = (SwitchPreference) important.findPreference(KEY_CALLS);
if (Utils.isVoiceCapable(mContext)) {
mCalls.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
@@ -178,11 +173,11 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
}
});
} else {
general.removePreference(mCalls);
important.removePreference(mCalls);
mCalls = null;
}
mMessages = (SwitchPreference) general.findPreference(KEY_MESSAGES);
mMessages = (SwitchPreference) important.findPreference(KEY_MESSAGES);
mMessages.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
@@ -216,44 +211,52 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
return setZenModeConfig(newConfig);
}
});
general.addPreference(mStarred);
important.addPreference(mStarred);
final Preference alarmInfo = new Preference(mContext) {
@Override
public View getView(View convertView, ViewGroup parent) {
final TextView tv = new TextView(mContext);
tv.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.ITALIC));
tv.setPadding(p, p, p, p);
tv.setPadding(padding, padding, padding, padding);
tv.setText(R.string.zen_mode_alarm_info);
return tv;
}
};
alarmInfo.setPersistent(false);
alarmInfo.setSelectable(false);
general.addPreference(alarmInfo);
important.addPreference(alarmInfo);
final PreferenceCategory auto = (PreferenceCategory) root.findPreference(KEY_AUTOMATIC);
final PreferenceCategory downtime = (PreferenceCategory) root.findPreference(KEY_DOWNTIME);
mWhen = new DropDownPreference(mContext);
mWhen.setKey(KEY_WHEN);
mWhen.setTitle(R.string.zen_mode_when);
mWhen.setDropDownWidth(R.dimen.zen_mode_dropdown_width);
mWhen.addItem(R.string.zen_mode_when_every_night, ZenModeConfig.SLEEP_MODE_NIGHTS);
mWhen.addItem(R.string.zen_mode_when_weeknights, ZenModeConfig.SLEEP_MODE_WEEKNIGHTS);
mWhen.addItem(R.string.zen_mode_when_never, null);
mWhen.setCallback(new DropDownPreference.Callback() {
mDays = downtime.findPreference(KEY_DAYS);
mDays.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onItemSelected(int pos, Object value) {
if (mDisableListeners) return true;
final String mode = (String) value;
if (Objects.equals(mode, mConfig.sleepMode)) return true;
if (DEBUG) Log.d(TAG, "onPrefChange sleepMode=" + mode);
final ZenModeConfig newConfig = mConfig.copy();
newConfig.sleepMode = mode;
return setZenModeConfig(newConfig);
public boolean onPreferenceClick(Preference preference) {
new AlertDialog.Builder(mContext)
.setTitle(R.string.zen_mode_downtime_days)
.setView(new ZenModeDowntimeDaysSelection(mContext, mConfig.sleepMode) {
@Override
protected void onChanged(String mode) {
if (mDisableListeners) return;
if (Objects.equals(mode, mConfig.sleepMode)) return;
if (DEBUG) Log.d(TAG, "days.onChanged sleepMode=" + mode);
final ZenModeConfig newConfig = mConfig.copy();
newConfig.sleepMode = mode;
setZenModeConfig(newConfig);
}
})
.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
updateDays();
}
})
.setPositiveButton(R.string.done_button, null)
.show();
return true;
}
});
auto.addPreference(mWhen);
final FragmentManager mgr = getFragmentManager();
@@ -276,8 +279,8 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
return setZenModeConfig(newConfig);
}
});
auto.addPreference(mStart);
mStart.setDependency(mWhen.getKey());
downtime.addPreference(mStart);
mStart.setDependency(mDays.getKey());
mEnd = new TimePickerPreference(mContext, mgr);
mEnd.setKey(KEY_END_TIME);
@@ -298,8 +301,8 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
return setZenModeConfig(newConfig);
}
});
auto.addPreference(mEnd);
mEnd.setDependency(mWhen.getKey());
downtime.addPreference(mEnd);
mEnd.setDependency(mDays.getKey());
mAutomationCategory = (PreferenceCategory) findPreference(KEY_AUTOMATION);
mEntry = findPreference(KEY_ENTRY);
@@ -322,10 +325,39 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
});
mConditionProviders = findPreference(KEY_CONDITION_PROVIDERS);
updateZenMode();
updateControls();
}
private void updateDays() {
if (mConfig != null) {
final int[] days = ZenModeConfig.tryParseDays(mConfig.sleepMode);
if (days != null && days.length != 0) {
final StringBuilder sb = new StringBuilder();
final Calendar c = Calendar.getInstance();
for (int i = 0; i < ZenModeConfig.ALL_DAYS.length; i++) {
final int day = ZenModeConfig.ALL_DAYS[i];
for (int j = 0; j < days.length; j++) {
if (day == days[j]) {
c.set(Calendar.DAY_OF_WEEK, day);
if (sb.length() > 0) {
sb.append(mContext.getString(R.string.summary_divider_text));
}
sb.append(DAY_FORMAT.format(c.getTime()));
break;
}
}
}
if (sb.length() > 0) {
mDays.setSummary(sb);
mDays.notifyDependencyChange(false);
return;
}
}
}
mDays.setSummary(R.string.zen_mode_downtime_days_none);
mDays.notifyDependencyChange(true);
}
private void updateEndSummary() {
final int startMin = 60 * mConfig.sleepStartHour + mConfig.sleepStartMinute;
final int endMin = 60 * mConfig.sleepEndHour + mConfig.sleepEndMinute;
@@ -340,7 +372,7 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
}
mMessages.setChecked(mConfig.allowMessages);
mStarred.setSelectedValue(mConfig.allowFrom);
mWhen.setSelectedValue(mConfig.sleepMode);
updateDays();
mStart.setTime(mConfig.sleepStartHour, mConfig.sleepStartMinute);
mEnd.setTime(mConfig.sleepEndHour, mConfig.sleepEndMinute);
mDisableListeners = false;
@@ -398,7 +430,6 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
public void onResume() {
super.onResume();
updateControls();
updateZenMode();
mSettingsObserver.register();
}
@@ -408,22 +439,6 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
mSettingsObserver.unregister();
}
@Override
public void onDestroyView() {
super.onDestroyView();
mSwitchBar.removeOnSwitchChangeListener(this);
mSwitchBar.hide();
}
private void updateZenMode() {
final boolean zenMode = Global.getInt(getContentResolver(),
Global.ZEN_MODE, Global.ZEN_MODE_OFF) != Global.ZEN_MODE_OFF;
if (mSwitchBar.isChecked() != zenMode) {
mSwitchBar.setChecked(zenMode);
mIgnoreNext = true;
}
}
private void updateZenModeConfig() {
final ZenModeConfig config = getZenModeConfig();
if (Objects.equals(config, mConfig)) return;
@@ -468,38 +483,6 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
return new ZenModeConditionSelection(mContext);
}
private final Runnable mHideDialog = new Runnable() {
@Override
public void run() {
if (mDialog != null) {
mDialog.dismiss();
mDialog = null;
}
}
};
private final Runnable mShowDialog = new Runnable() {
@Override
public void run() {
mDialog = new AlertDialog.Builder(mContext)
.setTitle(R.string.zen_mode_settings_title)
.setView(newConditionSelection())
.setNegativeButton(R.string.dlg_cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
putZenModeSetting(Global.ZEN_MODE_OFF);
}
})
.setPositiveButton(R.string.dlg_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// noop
}
})
.show();
}
};
// Enable indexing of searchable data
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@@ -549,7 +532,7 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
public void onChange(boolean selfChange, Uri uri) {
super.onChange(selfChange, uri);
if (ZEN_MODE_URI.equals(uri)) {
updateZenMode();
PREF_ZEN_MODE.update(mContext);
}
if (ZEN_MODE_CONFIG_ETAG_URI.equals(uri)) {
updateZenModeConfig();

View File

@@ -36,7 +36,6 @@ import com.android.settings.fuelgauge.PowerUsageSummary;
import com.android.settings.inputmethod.InputMethodAndLanguageSettings;
import com.android.settings.location.LocationSettings;
import com.android.settings.net.DataUsageMeteredSettings;
import com.android.settings.notification.NotificationDisplaySettings;
import com.android.settings.notification.NotificationSettings;
import com.android.settings.notification.OtherSoundSettings;
import com.android.settings.notification.ZenModeSettings;
@@ -108,7 +107,6 @@ public final class Ranking {
// Notifications
sRankMap.put(NotificationSettings.class.getName(), RANK_NOTIFICATIONS);
sRankMap.put(NotificationDisplaySettings.class.getName(), RANK_NOTIFICATIONS);
sRankMap.put(OtherSoundSettings.class.getName(), RANK_NOTIFICATIONS);
sRankMap.put(ZenModeSettings.class.getName(), RANK_NOTIFICATIONS);

View File

@@ -39,7 +39,6 @@ import com.android.settings.fuelgauge.PowerUsageSummary;
import com.android.settings.inputmethod.InputMethodAndLanguageSettings;
import com.android.settings.location.LocationSettings;
import com.android.settings.net.DataUsageMeteredSettings;
import com.android.settings.notification.NotificationDisplaySettings;
import com.android.settings.notification.NotificationSettings;
import com.android.settings.notification.OtherSoundSettings;
import com.android.settings.notification.ZenModeSettings;
@@ -129,13 +128,6 @@ public final class SearchIndexableResources {
NotificationSettings.class.getName(),
R.drawable.ic_settings_notifications));
sResMap.put(NotificationDisplaySettings.class.getName(),
new SearchIndexableResource(
Ranking.getRankForClassName(NotificationDisplaySettings.class.getName()),
R.xml.notification_display_settings,
NotificationDisplaySettings.class.getName(),
R.drawable.ic_settings_notifications));
sResMap.put(OtherSoundSettings.class.getName(),
new SearchIndexableResource(
Ranking.getRankForClassName(OtherSoundSettings.class.getName()),