diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 35e679d08b0..297053d78f0 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -666,6 +666,27 @@ android:value="true" /> + + + + + + + + + + + + + + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 734cf7d614c..307f3b8b3c6 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -5678,7 +5678,10 @@ Notification volume - Interruptions + Block interruptions + + + Priority only allows When calls and notifications arrive @@ -5866,9 +5869,6 @@ Until you turn this off - - Priority interruptions - Downtime @@ -5917,11 +5917,14 @@ Starred contacts only - - Events and reminders + + Alarms - - Alarms are always priority interruptions + + Reminders + + + Events Automatically turn on diff --git a/res/xml/zen_mode_priority_settings.xml b/res/xml/zen_mode_priority_settings.xml new file mode 100644 index 00000000000..e8bab669a3c --- /dev/null +++ b/res/xml/zen_mode_priority_settings.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/xml/zen_mode_settings.xml b/res/xml/zen_mode_settings.xml index 3ac4eef7014..7c8dc7a2a06 100644 --- a/res/xml/zen_mode_settings.xml +++ b/res/xml/zen_mode_settings.xml @@ -25,45 +25,11 @@ android:title="@string/zen_mode_option_title" android:persistent="false" /> - - - - - - - - - - - - - + + allKeyTitles(Context context) { final SparseArray rt = new SparseArray(); - rt.put(R.string.zen_mode_important_category, KEY_IMPORTANT); - rt.put(R.string.zen_mode_calls, KEY_CALLS); rt.put(R.string.zen_mode_option_title, 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_events, KEY_EVENTS); - rt.put(R.string.zen_mode_alarm_info, KEY_ALARM_INFO); + rt.put(R.string.zen_mode_priority_settings_title, KEY_PRIORITY_SETTINGS); 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); @@ -125,18 +106,10 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index return rt; } - private final Handler mHandler = new Handler(); - private final SettingsObserver mSettingsObserver = new SettingsObserver(); - - private Context mContext; private PackageManager mPM; - private ZenModeConfig mConfig; private boolean mDisableListeners; - private SwitchPreference mCalls; - private SwitchPreference mMessages; - private DropDownPreference mStarred; - private SwitchPreference mEvents; private boolean mDowntimeSupported; + private Preference mPrioritySettings; private Preference mDays; private TimePickerPreference mStart; private TimePickerPreference mEnd; @@ -151,18 +124,19 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index return MetricsLogger.NOTIFICATION_ZEN_MODE; } + @Override + protected void onZenModeChanged() { + PREF_ZEN_MODE.update(mContext); + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - mContext = getActivity(); mPM = mContext.getPackageManager(); addPreferencesFromResource(R.xml.zen_mode_settings); final PreferenceScreen root = getPreferenceScreen(); - mConfig = getZenModeConfig(); - if (DEBUG) Log.d(TAG, "Loaded mConfig=" + mConfig); - PREF_ZEN_MODE.init(this); PREF_ZEN_MODE.setCallback(new SettingPrefWithCallback.Callback() { @Override @@ -173,69 +147,7 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index } }); - final PreferenceCategory important = - (PreferenceCategory) root.findPreference(KEY_IMPORTANT); - - mCalls = (SwitchPreference) important.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); - } - }); - - mMessages = (SwitchPreference) important.findPreference(KEY_MESSAGES); - mMessages.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - if (mDisableListeners) return true; - final boolean val = (Boolean) newValue; - if (val == mConfig.allowMessages) return true; - if (DEBUG) Log.d(TAG, "onPrefChange allowMessages=" + val); - final ZenModeConfig newConfig = mConfig.copy(); - newConfig.allowMessages = val; - return setZenModeConfig(newConfig); - } - }); - - mStarred = (DropDownPreference) important.findPreference(KEY_STARRED); - mStarred.addItem(R.string.zen_mode_from_anyone, ZenModeConfig.SOURCE_ANYONE); - mStarred.addItem(R.string.zen_mode_from_contacts, ZenModeConfig.SOURCE_CONTACT); - mStarred.addItem(R.string.zen_mode_from_starred, ZenModeConfig.SOURCE_STAR); - mStarred.setCallback(new DropDownPreference.Callback() { - @Override - public boolean onItemSelected(int pos, Object newValue) { - if (mDisableListeners) return true; - final int val = (Integer) newValue; - if (val == mConfig.allowFrom) return true; - if (DEBUG) Log.d(TAG, "onPrefChange allowFrom=" + - ZenModeConfig.sourceToString(val)); - final ZenModeConfig newConfig = mConfig.copy(); - newConfig.allowFrom = val; - return setZenModeConfig(newConfig); - } - }); - important.addPreference(mStarred); - - mEvents = (SwitchPreference) important.findPreference(KEY_EVENTS); - mEvents.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - if (mDisableListeners) return true; - final boolean val = (Boolean) newValue; - if (val == mConfig.allowEvents) return true; - if (DEBUG) Log.d(TAG, "onPrefChange allowEvents=" + val); - final ZenModeConfig newConfig = mConfig.copy(); - newConfig.allowEvents = val; - return setZenModeConfig(newConfig); - } - }); + mPrioritySettings = root.findPreference(KEY_PRIORITY_SETTINGS); final PreferenceCategory downtime = (PreferenceCategory) root.findPreference(KEY_DOWNTIME); mDowntimeSupported = isDowntimeSupported(mContext); @@ -406,15 +318,9 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index mEnd.setSummaryFormat(summaryFormat); } - private void updateControls() { + @Override + protected void updateControls() { mDisableListeners = true; - if (mCalls != null) { - mCalls.setChecked(mConfig.allowCalls); - } - mMessages.setChecked(mConfig.allowMessages); - mStarred.setSelectedValue(mConfig.allowFrom); - mEvents.setChecked(mConfig.allowEvents); - updateStarredEnabled(); if (mDowntimeSupported) { updateDays(); mStart.setTime(mConfig.sleepStartHour, mConfig.sleepStartMinute); @@ -424,10 +330,24 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index mDisableListeners = false; refreshAutomationSection(); updateEndSummary(); + updatePrioritySettingsSummary(); } - private void updateStarredEnabled() { - mStarred.setEnabled(mConfig.allowCalls || mConfig.allowMessages); + private void updatePrioritySettingsSummary() { + String s = getResources().getString(R.string.zen_mode_alarms); + s = appendLowercase(s, mConfig.allowReminders, R.string.zen_mode_reminders); + s = appendLowercase(s, mConfig.allowEvents, R.string.zen_mode_events); + s = appendLowercase(s, mConfig.allowCalls, R.string.zen_mode_calls); + s = appendLowercase(s, mConfig.allowMessages, R.string.zen_mode_messages); + mPrioritySettings.setSummary(s); + } + + private String appendLowercase(String s, boolean condition, int resId) { + if (condition) { + return getResources().getString(R.string.join_many_items_middle, s, + getResources().getString(resId).toLowerCase()); + } + return s; } private void refreshAutomationSection() { @@ -476,56 +396,6 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index } } - @Override - public void onResume() { - super.onResume(); - updateControls(); - mSettingsObserver.register(); - } - - @Override - public void onPause() { - super.onPause(); - mSettingsObserver.unregister(); - } - - private void updateZenModeConfig() { - final ZenModeConfig config = getZenModeConfig(); - if (Objects.equals(config, mConfig)) return; - mConfig = config; - if (DEBUG) Log.d(TAG, "updateZenModeConfig mConfig=" + mConfig); - updateControls(); - } - - private ZenModeConfig getZenModeConfig() { - final INotificationManager nm = INotificationManager.Stub.asInterface( - ServiceManager.getService(Context.NOTIFICATION_SERVICE)); - try { - return nm.getZenModeConfig(); - } catch (Exception e) { - Log.w(TAG, "Error calling NoMan", e); - return new ZenModeConfig(); - } - } - - private boolean setZenModeConfig(ZenModeConfig config) { - final INotificationManager nm = INotificationManager.Stub.asInterface( - ServiceManager.getService(Context.NOTIFICATION_SERVICE)); - try { - final boolean success = nm.setZenModeConfig(config); - if (success) { - mConfig = config; - if (DEBUG) Log.d(TAG, "Saved mConfig=" + mConfig); - updateEndSummary(); - updateStarredEnabled(); - } - return success; - } catch (Exception e) { - Log.w(TAG, "Error calling NoMan", e); - return false; - } - } - protected void putZenModeSetting(int value) { Global.putInt(getContentResolver(), Global.ZEN_MODE, value); } @@ -663,35 +533,6 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index } } - private final class SettingsObserver extends ContentObserver { - private final Uri ZEN_MODE_URI = Global.getUriFor(Global.ZEN_MODE); - private final Uri ZEN_MODE_CONFIG_ETAG_URI = Global.getUriFor(Global.ZEN_MODE_CONFIG_ETAG); - - public SettingsObserver() { - super(mHandler); - } - - public void register() { - getContentResolver().registerContentObserver(ZEN_MODE_URI, false, this); - getContentResolver().registerContentObserver(ZEN_MODE_CONFIG_ETAG_URI, false, this); - } - - public void unregister() { - getContentResolver().unregisterContentObserver(this); - } - - @Override - public void onChange(boolean selfChange, Uri uri) { - super.onChange(selfChange, uri); - if (ZEN_MODE_URI.equals(uri)) { - PREF_ZEN_MODE.update(mContext); - } - if (ZEN_MODE_CONFIG_ETAG_URI.equals(uri)) { - updateZenModeConfig(); - } - } - } - private static class TimePickerPreference extends Preference { private final Context mContext; diff --git a/src/com/android/settings/notification/ZenModeSettingsBase.java b/src/com/android/settings/notification/ZenModeSettingsBase.java new file mode 100644 index 00000000000..d4369650e45 --- /dev/null +++ b/src/com/android/settings/notification/ZenModeSettingsBase.java @@ -0,0 +1,133 @@ +/* + * Copyright (C) 2015 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.app.INotificationManager; +import android.content.Context; +import android.database.ContentObserver; +import android.net.Uri; +import android.os.Bundle; +import android.os.Handler; +import android.os.ServiceManager; +import android.provider.Settings.Global; +import android.service.notification.ZenModeConfig; +import android.util.Log; + +import com.android.settings.SettingsPreferenceFragment; + +import java.util.Objects; + +abstract public class ZenModeSettingsBase extends SettingsPreferenceFragment { + protected static final String TAG = "ZenModeSettings"; + protected static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); + + private final Handler mHandler = new Handler(); + private final SettingsObserver mSettingsObserver = new SettingsObserver(); + + protected Context mContext; + protected ZenModeConfig mConfig; + + abstract protected void onZenModeChanged(); + abstract protected void updateControls(); + + @Override + public void onCreate(Bundle icicle) { + super.onCreate(icicle); + mContext = getActivity(); + mConfig = getZenModeConfig(); + if (DEBUG) Log.d(TAG, "Loaded mConfig=" + mConfig); + } + + @Override + public void onResume() { + super.onResume(); + mConfig = getZenModeConfig(); + updateControls(); + mSettingsObserver.register(); + } + + @Override + public void onPause() { + super.onPause(); + mSettingsObserver.unregister(); + } + + protected boolean setZenModeConfig(ZenModeConfig config) { + final INotificationManager nm = INotificationManager.Stub.asInterface( + ServiceManager.getService(Context.NOTIFICATION_SERVICE)); + try { + final boolean success = nm.setZenModeConfig(config); + if (success) { + mConfig = config; + if (DEBUG) Log.d(TAG, "Saved mConfig=" + mConfig); + updateControls(); + } + return success; + } catch (Exception e) { + Log.w(TAG, "Error calling NoMan", e); + return false; + } + } + + private void updateZenModeConfig() { + final ZenModeConfig config = getZenModeConfig(); + if (Objects.equals(config, mConfig)) return; + mConfig = config; + if (DEBUG) Log.d(TAG, "updateZenModeConfig mConfig=" + mConfig); + updateControls(); + } + + private ZenModeConfig getZenModeConfig() { + final INotificationManager nm = INotificationManager.Stub.asInterface( + ServiceManager.getService(Context.NOTIFICATION_SERVICE)); + try { + return nm.getZenModeConfig(); + } catch (Exception e) { + Log.w(TAG, "Error calling NoMan", e); + return new ZenModeConfig(); + } + } + + private final class SettingsObserver extends ContentObserver { + private final Uri ZEN_MODE_URI = Global.getUriFor(Global.ZEN_MODE); + private final Uri ZEN_MODE_CONFIG_ETAG_URI = Global.getUriFor(Global.ZEN_MODE_CONFIG_ETAG); + + private SettingsObserver() { + super(mHandler); + } + + public void register() { + getContentResolver().registerContentObserver(ZEN_MODE_URI, false, this); + getContentResolver().registerContentObserver(ZEN_MODE_CONFIG_ETAG_URI, false, this); + } + + public void unregister() { + getContentResolver().unregisterContentObserver(this); + } + + @Override + public void onChange(boolean selfChange, Uri uri) { + super.onChange(selfChange, uri); + if (ZEN_MODE_URI.equals(uri)) { + onZenModeChanged(); + } + if (ZEN_MODE_CONFIG_ETAG_URI.equals(uri)) { + updateZenModeConfig(); + } + } + } +} diff --git a/src/com/android/settings/search/Ranking.java b/src/com/android/settings/search/Ranking.java index c96ce09fec3..e4e5d129a96 100644 --- a/src/com/android/settings/search/Ranking.java +++ b/src/com/android/settings/search/Ranking.java @@ -42,6 +42,7 @@ import com.android.settings.location.ScanningSettings; import com.android.settings.net.DataUsageMeteredSettings; import com.android.settings.notification.NotificationSettings; import com.android.settings.notification.OtherSoundSettings; +import com.android.settings.notification.ZenModePrioritySettings; import com.android.settings.notification.ZenModeSettings; import com.android.settings.print.PrintSettingsFragment; import com.android.settings.sim.SimSettings; @@ -123,6 +124,7 @@ public final class Ranking { sRankMap.put(NotificationSettings.class.getName(), RANK_NOTIFICATIONS); sRankMap.put(OtherSoundSettings.class.getName(), RANK_NOTIFICATIONS); sRankMap.put(ZenModeSettings.class.getName(), RANK_NOTIFICATIONS); + sRankMap.put(ZenModePrioritySettings.class.getName(), RANK_NOTIFICATIONS); // Storage sRankMap.put(Memory.class.getName(), RANK_STORAGE); diff --git a/src/com/android/settings/search/SearchIndexableResources.java b/src/com/android/settings/search/SearchIndexableResources.java index 102e0bf2a69..d57a1f149af 100644 --- a/src/com/android/settings/search/SearchIndexableResources.java +++ b/src/com/android/settings/search/SearchIndexableResources.java @@ -43,6 +43,7 @@ import com.android.settings.location.ScanningSettings; import com.android.settings.net.DataUsageMeteredSettings; import com.android.settings.notification.NotificationSettings; import com.android.settings.notification.OtherSoundSettings; +import com.android.settings.notification.ZenModePrioritySettings; import com.android.settings.notification.ZenModeSettings; import com.android.settings.print.PrintSettingsFragment; import com.android.settings.sim.SimSettings; @@ -162,6 +163,13 @@ public final class SearchIndexableResources { ZenModeSettings.class.getName(), R.drawable.ic_settings_notifications)); + sResMap.put(ZenModePrioritySettings.class.getName(), + new SearchIndexableResource( + Ranking.getRankForClassName(ZenModePrioritySettings.class.getName()), + R.xml.zen_mode_priority_settings, + ZenModePrioritySettings.class.getName(), + R.drawable.ic_settings_notifications)); + sResMap.put(Memory.class.getName(), new SearchIndexableResource( Ranking.getRankForClassName(Memory.class.getName()),