Apply DND to visual effects.

Bug: 25423508
Change-Id: I00ace3da8a7fea089f4d0fc3f6161452285abb8e
This commit is contained in:
Julia Reynolds
2015-11-09 10:52:17 -05:00
parent 8d249e839c
commit 5555d26b20
11 changed files with 230 additions and 10 deletions

View File

@@ -729,6 +729,26 @@
android:value="true" />
</activity>
<activity android:name="Settings$ZenModeVisualInterruptionSettingsActivity"
android:label="@string/zen_mode_visual_interruptions_settings_title"
android:icon="@drawable/ic_settings_notifications"
android:exported="true"
android:taskAffinity="">
<intent-filter android:priority="1">
<action android:name="android.settings.ZEN_MODE_PRIORITY_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="com.android.settings.SHORTCUT" />
</intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.notification.ZenModeVisualInterruptionSettings" />
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" />
</activity>
<activity android:name="Settings$ZenModePrioritySettingsActivity"
android:label="@string/zen_mode_priority_settings_title"
android:icon="@drawable/ic_settings_notifications"

View File

@@ -5964,6 +5964,9 @@
<!-- Sound & notification > Sound section: Zen mode combined summary + condition line [CHAR LIMIT=60] -->
<string name="zen_mode_summary_combination"><xliff:g id="mode" example="Priority only">%1$s</xliff:g>: <xliff:g id="exit condition" example="Until you turn this off">%2$s</xliff:g></string>
<!-- Sound & notification > Do not disturb section: Title for the Visual interruptions option and associated settings page. [CHAR LIMIT=30] -->
<string name="zen_mode_visual_interruptions_settings_title">Visual interruptions</string>
<!-- Sound & notification > Sound section: Title for the option defining the phone ringtone. [CHAR LIMIT=30] -->
<string name="ringtone_title">Phone ringtone</string>
@@ -6306,6 +6309,18 @@
<!-- [CHAR LIMIT=NONE] Zen mode summary spoken when changing mode by voice: Turn on all notifications. -->
<string name="zen_mode_summary_always">Change to always interrupt</string>
<!-- [CHAR LIMIT=20] Zen mode settings: No screen interruptions option -->
<string name="zen_mode_peek">No screen interruptions</string>
<!-- [CHAR LIMIT=20] Zen mode settings: No screen interruptions summary -->
<string name="zen_mode_peek_summary">Prevent notifications silenced by Do Not Disturb from peeking or appearing on the current screen</string>
<!-- [CHAR LIMIT=20] Zen mode settings: No notification light option -->
<string name="zen_mode_lights">No notification light</string>
<!-- [CHAR LIMIT=20] Zen mode settings: No notification light summary -->
<string name="zen_mode_lights_summary">Prevent notifications silenced by Do Not Disturb from causing the light to pulse</string>
<!-- [CHAR LIMIT=20] Notifications settings: Apps section header -->
<string name="notification_settings_apps_title">App notifications</string>

View File

@@ -25,9 +25,15 @@
android:title="@string/zen_mode_priority_settings_title"
android:fragment="com.android.settings.notification.ZenModePrioritySettings" />
<!-- Downtime -->
<!-- Automated rules -->
<PreferenceScreen
android:key="automation_settings"
android:title="@string/zen_mode_automation_settings_title"
android:fragment="com.android.settings.notification.ZenModeAutomationSettings" />
<!-- Visual interruptions -->
<PreferenceScreen
android:key="visual_interruptions_settings"
android:title="@string/zen_mode_visual_interruptions_settings_title"
android:fragment="com.android.settings.notification.ZenModeVisualInterruptionSettings" />
</PreferenceScreen>

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
android:title="@string/zen_mode_visual_interruptions_settings_title" >
<SwitchPreference android:key="peek"
android:title="@string/zen_mode_peek"
android:summary="@string/zen_mode_peek_summary"
android:persistent="false" />
<SwitchPreference android:key="lights"
android:title="@string/zen_mode_lights"
android:summary="@string/zen_mode_lights_summary"
android:persistent="false" />
</PreferenceScreen>

View File

@@ -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 */ }

View File

@@ -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(),

View File

@@ -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);
}

View File

@@ -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<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 @@ public class ZenModeSettings extends ZenModeSettingsBase implements Indexable {
@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();

View File

@@ -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);
}
}

View File

@@ -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);

View File

@@ -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() {