diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 774cb45de20..df00ad16805 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -729,6 +729,26 @@ android:value="true" /> + + + + + + + + + + + + + + Sound section: Zen mode combined summary + condition line [CHAR LIMIT=60] --> %1$s: %2$s + + Visual interruptions + Phone ringtone @@ -6306,6 +6309,18 @@ Change to always interrupt + + No screen interruptions + + + Prevent notifications silenced by Do Not Disturb from peeking or appearing on the current screen + + + No notification light + + + Prevent notifications silenced by Do Not Disturb from causing the light to pulse + App notifications diff --git a/res/xml/zen_mode_settings.xml b/res/xml/zen_mode_settings.xml index 267727f69e3..d8ad10d3ee9 100644 --- a/res/xml/zen_mode_settings.xml +++ b/res/xml/zen_mode_settings.xml @@ -25,9 +25,15 @@ android:title="@string/zen_mode_priority_settings_title" android:fragment="com.android.settings.notification.ZenModePrioritySettings" /> - + + + + diff --git a/res/xml/zen_mode_visual_interruptions_settings.xml b/res/xml/zen_mode_visual_interruptions_settings.xml new file mode 100644 index 00000000000..8131650dd58 --- /dev/null +++ b/res/xml/zen_mode_visual_interruptions_settings.xml @@ -0,0 +1,31 @@ + + + + + + + + + + diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java index fdc55d7bd88..46d24ae87a8 100644 --- a/src/com/android/settings/Settings.java +++ b/src/com/android/settings/Settings.java @@ -104,6 +104,7 @@ public class Settings extends SettingsActivity { public static class ZenModeScheduleRuleSettingsActivity extends SettingsActivity { /* empty */ } public static class ZenModeEventRuleSettingsActivity extends SettingsActivity { /* empty */ } public static class ZenModeExternalRuleSettingsActivity extends SettingsActivity { /* empty */ } + public static class ZenModeVisualInterruptionSettingsActivity extends SettingsActivity { /* empty */} public static class NotificationSettingsActivity extends SettingsActivity { /* empty */ } public static class NotificationAppListActivity extends SettingsActivity { /* empty */ } public static class AppNotificationSettingsActivity extends SettingsActivity { /* empty */ } diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java index 4eaabe93ba7..b0a112077ef 100644 --- a/src/com/android/settings/SettingsActivity.java +++ b/src/com/android/settings/SettingsActivity.java @@ -92,6 +92,7 @@ import com.android.settings.notification.ZenModeEventRuleSettings; import com.android.settings.notification.ZenModePrioritySettings; import com.android.settings.notification.ZenModeScheduleRuleSettings; import com.android.settings.notification.ZenModeSettings; +import com.android.settings.notification.ZenModeVisualInterruptionSettings; import com.android.settings.print.PrintJobSettingsFragment; import com.android.settings.print.PrintSettingsFragment; import com.android.settings.search.DynamicIndexableContentMonitor; @@ -296,6 +297,7 @@ public class SettingsActivity extends SettingsDrawerActivity ZenModeAutomationSettings.class.getName(), ZenModeScheduleRuleSettings.class.getName(), ZenModeEventRuleSettings.class.getName(), + ZenModeVisualInterruptionSettings.class.getName(), ProcessStatsUi.class.getName(), PowerUsageDetail.class.getName(), ProcessStatsSummary.class.getName(), diff --git a/src/com/android/settings/notification/ZenModePrioritySettings.java b/src/com/android/settings/notification/ZenModePrioritySettings.java index 6168e57d758..e3413a789b0 100644 --- a/src/com/android/settings/notification/ZenModePrioritySettings.java +++ b/src/com/android/settings/notification/ZenModePrioritySettings.java @@ -66,7 +66,8 @@ public class ZenModePrioritySettings extends ZenModeSettingsBase implements Inde MetricsLogger.action(mContext, MetricsLogger.ACTION_ZEN_ALLOW_REMINDERS, val); if (DEBUG) Log.d(TAG, "onPrefChange allowReminders=" + val); savePolicy(getNewPriorityCategories(val, Policy.PRIORITY_CATEGORY_REMINDERS), - mPolicy.priorityCallSenders, mPolicy.priorityMessageSenders); + mPolicy.priorityCallSenders, mPolicy.priorityMessageSenders, + mPolicy.suppressedVisualEffects); return true; } }); @@ -80,7 +81,8 @@ public class ZenModePrioritySettings extends ZenModeSettingsBase implements Inde MetricsLogger.action(mContext, MetricsLogger.ACTION_ZEN_ALLOW_EVENTS, val); if (DEBUG) Log.d(TAG, "onPrefChange allowEvents=" + val); savePolicy(getNewPriorityCategories(val, Policy.PRIORITY_CATEGORY_EVENTS), - mPolicy.priorityCallSenders, mPolicy.priorityMessageSenders); + mPolicy.priorityCallSenders, mPolicy.priorityMessageSenders, + mPolicy.suppressedVisualEffects); return true; } }); @@ -100,7 +102,8 @@ public class ZenModePrioritySettings extends ZenModeSettingsBase implements Inde + " allowMessagesFrom=" + ZenModeConfig.sourceToString(allowMessagesFrom)); savePolicy( getNewPriorityCategories(allowMessages, Policy.PRIORITY_CATEGORY_MESSAGES), - mPolicy.priorityCallSenders, allowMessagesFrom); + mPolicy.priorityCallSenders, allowMessagesFrom, + mPolicy.suppressedVisualEffects); return true; } }); @@ -118,7 +121,8 @@ public class ZenModePrioritySettings extends ZenModeSettingsBase implements Inde if (DEBUG) Log.d(TAG, "onPrefChange allowCalls=" + allowCalls + " allowCallsFrom=" + ZenModeConfig.sourceToString(allowCallsFrom)); savePolicy(getNewPriorityCategories(allowCalls, Policy.PRIORITY_CATEGORY_CALLS), - allowCallsFrom, mPolicy.priorityMessageSenders); + allowCallsFrom, mPolicy.priorityMessageSenders, + mPolicy.suppressedVisualEffects); return true; } }); @@ -137,7 +141,7 @@ public class ZenModePrioritySettings extends ZenModeSettingsBase implements Inde int priorityCategories = getNewPriorityCategories(val, NotificationManager.Policy.PRIORITY_CATEGORY_REPEAT_CALLERS); savePolicy(priorityCategories, mPolicy.priorityCallSenders, - mPolicy.priorityMessageSenders); + mPolicy.priorityMessageSenders, mPolicy.suppressedVisualEffects); return true; } }); @@ -210,8 +214,9 @@ public class ZenModePrioritySettings extends ZenModeSettingsBase implements Inde } private void savePolicy(int priorityCategories, int priorityCallSenders, - int priorityMessageSenders) { - mPolicy = new Policy(priorityCategories, priorityCallSenders, priorityMessageSenders); + int priorityMessageSenders, int suppressedVisualEffects) { + mPolicy = new Policy(priorityCategories, priorityCallSenders, priorityMessageSenders, + suppressedVisualEffects); NotificationManager.from(mContext).setNotificationPolicy(mPolicy); } diff --git a/src/com/android/settings/notification/ZenModeSettings.java b/src/com/android/settings/notification/ZenModeSettings.java index 3e32abc7c52..39ec08cf5f6 100644 --- a/src/com/android/settings/notification/ZenModeSettings.java +++ b/src/com/android/settings/notification/ZenModeSettings.java @@ -37,6 +37,7 @@ import java.util.List; public class ZenModeSettings extends ZenModeSettingsBase implements Indexable { private static final String KEY_PRIORITY_SETTINGS = "priority_settings"; private static final String KEY_AUTOMATION_SETTINGS = "automation_settings"; + private static final String KEY_VISUAL_INTERRUPTIONS_SETTINGS = "visual_interruptions_settings"; private Preference mPrioritySettings; @@ -116,10 +117,12 @@ public class ZenModeSettings extends ZenModeSettingsBase implements Indexable { return s; } - private static SparseArray allKeyTitles(Context context) { + private static SparseArray allKeyTitles() { final SparseArray rt = new SparseArray(); rt.put(R.string.zen_mode_priority_settings_title, KEY_PRIORITY_SETTINGS); rt.put(R.string.zen_mode_automation_settings_title, KEY_AUTOMATION_SETTINGS); + rt.put(R.string.zen_mode_visual_interruptions_settings_title, + KEY_VISUAL_INTERRUPTIONS_SETTINGS); return rt; } @@ -134,7 +137,7 @@ public class ZenModeSettings extends ZenModeSettingsBase implements Indexable { @Override public List getRawDataToIndex(Context context, boolean enabled) { - final SparseArray keyTitles = allKeyTitles(context); + final SparseArray keyTitles = allKeyTitles(); final int N = keyTitles.size(); final List result = new ArrayList(N); final Resources res = context.getResources(); diff --git a/src/com/android/settings/notification/ZenModeVisualInterruptionSettings.java b/src/com/android/settings/notification/ZenModeVisualInterruptionSettings.java new file mode 100644 index 00000000000..ba1b3784072 --- /dev/null +++ b/src/com/android/settings/notification/ZenModeVisualInterruptionSettings.java @@ -0,0 +1,126 @@ +/** + * 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.NotificationManager; +import android.app.NotificationManager.Policy; +import android.content.Context; +import android.os.Bundle; +import android.provider.SearchIndexableResource; +import android.support.v14.preference.SwitchPreference; +import android.support.v7.preference.Preference; +import android.support.v7.preference.PreferenceScreen; +import android.util.Log; + +import com.android.internal.logging.MetricsLogger; +import com.android.settings.search.BaseSearchIndexProvider; +import com.android.settings.search.Indexable; +import com.android.settings.R; + +import java.util.Arrays; +import java.util.List; + +public class ZenModeVisualInterruptionSettings extends ZenModeSettingsBase { + + private static final String KEY_PEEK = "peek"; + private static final String KEY_LIGHTS = "lights"; + + private SwitchPreference mPeek; + private SwitchPreference mLights; + + private boolean mDisableListeners; + private NotificationManager.Policy mPolicy; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + addPreferencesFromResource(R.xml.zen_mode_visual_interruptions_settings); + final PreferenceScreen root = getPreferenceScreen(); + + mPolicy = NotificationManager.from(mContext).getNotificationPolicy(); + + mPeek = (SwitchPreference) root.findPreference(KEY_PEEK); + mPeek.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + if (mDisableListeners) return true; + final boolean val = (Boolean) newValue; + MetricsLogger.action(mContext, MetricsLogger.ACTION_ZEN_ALLOW_PEEK, val); + if (DEBUG) Log.d(TAG, "onPrefChange suppressPeek=" + val); + savePolicy(getNewSuppressedEffects(val, Policy.SUPPRESSED_EFFECT_PEEK)); + return true; + } + }); + + mLights = (SwitchPreference) root.findPreference(KEY_LIGHTS); + mLights.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + if (mDisableListeners) return true; + final boolean val = (Boolean) newValue; + MetricsLogger.action(mContext, MetricsLogger.ACTION_ZEN_ALLOW_LIGHTS, val); + if (DEBUG) Log.d(TAG, "onPrefChange suppressLights=" + val); + savePolicy(getNewSuppressedEffects(val, Policy.SUPPRESSED_EFFECT_LIGHTS)); + return true; + } + }); + } + + @Override + protected int getMetricsCategory() { + return MetricsLogger.NOTIFICATION_ZEN_MODE_VISUAL_INTERRUPTIONS; + } + + @Override + protected void onZenModeChanged() { + // Don't care + } + + @Override + protected void onZenModeConfigChanged() { + mPolicy = NotificationManager.from(mContext).getNotificationPolicy(); + updateControls(); + } + + private void updateControls() { + mDisableListeners = true; + mPeek.setChecked(isEffectSuppressed(Policy.SUPPRESSED_EFFECT_PEEK)); + mLights.setChecked(isEffectSuppressed(Policy.SUPPRESSED_EFFECT_LIGHTS)); + mDisableListeners = false; + } + + private boolean isEffectSuppressed(int effect) { + return (mPolicy.suppressedVisualEffects & effect) != 0; + } + + private int getNewSuppressedEffects(boolean suppress, int effectType) { + int effects = mPolicy.suppressedVisualEffects; + if (suppress) { + effects |= effectType; + } else { + effects &= ~effectType; + } + return effects; + } + + private void savePolicy(int suppressedVisualEffects) { + mPolicy = new Policy(mPolicy.priorityCategories, + mPolicy.priorityCallSenders, mPolicy.priorityMessageSenders, + suppressedVisualEffects); + NotificationManager.from(mContext).setNotificationPolicy(mPolicy); + } +} diff --git a/src/com/android/settings/search/Ranking.java b/src/com/android/settings/search/Ranking.java index 18ae1eca398..1f464df4a3c 100644 --- a/src/com/android/settings/search/Ranking.java +++ b/src/com/android/settings/search/Ranking.java @@ -47,6 +47,7 @@ import com.android.settings.notification.OtherSoundSettings; import com.android.settings.notification.ZenModeAutomationSettings; import com.android.settings.notification.ZenModePrioritySettings; import com.android.settings.notification.ZenModeSettings; +import com.android.settings.notification.ZenModeVisualInterruptionSettings; import com.android.settings.print.PrintSettingsFragment; import com.android.settings.sim.SimSettings; import com.android.settings.users.UserSettings; @@ -129,6 +130,7 @@ public final class Ranking { sRankMap.put(ZenModeSettings.class.getName(), RANK_NOTIFICATIONS); sRankMap.put(ZenModePrioritySettings.class.getName(), RANK_NOTIFICATIONS); sRankMap.put(ZenModeAutomationSettings.class.getName(), RANK_NOTIFICATIONS); + sRankMap.put(ZenModeVisualInterruptionSettings.class.getName(), RANK_NOTIFICATIONS); // Storage sRankMap.put(StorageSettings.class.getName(), RANK_STORAGE); diff --git a/src/com/android/settings/search/SearchIndexableResources.java b/src/com/android/settings/search/SearchIndexableResources.java index 6b4a94751e0..7e669e0a8a0 100644 --- a/src/com/android/settings/search/SearchIndexableResources.java +++ b/src/com/android/settings/search/SearchIndexableResources.java @@ -48,6 +48,7 @@ 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.notification.ZenModeVisualInterruptionSettings; import com.android.settings.print.PrintSettingsFragment; import com.android.settings.sim.SimSettings; import com.android.settings.users.UserSettings; @@ -310,6 +311,14 @@ public final class SearchIndexableResources { R.xml.wifi_calling_settings, WifiCallingSettings.class.getName(), R.drawable.ic_settings_wireless)); + + sResMap.put(ZenModeVisualInterruptionSettings.class.getName(), + new SearchIndexableResource( + Ranking.getRankForClassName( + ZenModeVisualInterruptionSettings.class.getName()), + R.xml.zen_mode_visual_interruptions_settings, + ZenModeVisualInterruptionSettings.class.getName(), + R.drawable.ic_settings_notifications)); } private SearchIndexableResources() {