Apply DND to visual effects.
Bug: 25423508
Change-Id: I00ace3da8a7fea089f4d0fc3f6161452285abb8e
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index fdc55d7..46d24ae 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -104,6 +104,7 @@
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 4eaabe9..b0a1120 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -92,6 +92,7 @@
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 @@
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 6168e57..e3413a7 100644
--- a/src/com/android/settings/notification/ZenModePrioritySettings.java
+++ b/src/com/android/settings/notification/ZenModePrioritySettings.java
@@ -66,7 +66,8 @@
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 @@
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 @@
+ " 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 @@
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 @@
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 @@
}
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 3e32abc..39ec08c 100644
--- a/src/com/android/settings/notification/ZenModeSettings.java
+++ b/src/com/android/settings/notification/ZenModeSettings.java
@@ -37,6 +37,7 @@
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 @@
return s;
}
- private static SparseArray<String> allKeyTitles(Context context) {
+ private static SparseArray<String> allKeyTitles() {
final SparseArray<String> rt = new SparseArray<String>();
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 @@
@Override
public List<SearchIndexableRaw> getRawDataToIndex(Context context, boolean enabled) {
- final SparseArray<String> keyTitles = allKeyTitles(context);
+ final SparseArray<String> keyTitles = allKeyTitles();
final int N = keyTitles.size();
final List<SearchIndexableRaw> result = new ArrayList<SearchIndexableRaw>(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 0000000..ba1b378
--- /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 18ae1ec..1f464df 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.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 @@
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 6b4a947..7e669e0 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.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 @@
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() {