diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index c83002a1ef2..212aeaeb02d 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -2673,5 +2673,13 @@
+
+
+
+
+
+
diff --git a/res/drawable/ic_zen.xml b/res/drawable/ic_zen.xml
new file mode 100644
index 00000000000..17ecf217b86
--- /dev/null
+++ b/res/drawable/ic_zen.xml
@@ -0,0 +1,26 @@
+
+
+
+
+
+
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 8d1f69a36a8..cd152b6ee75 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -6707,4 +6707,7 @@
Wi-Fi, Bluetooth, and cellular network are turned off. You can\'t make phone calls or connect to the Internet.
+
+ Do not disturb is on (%1$s)
+
diff --git a/src/com/android/settings/dashboard/conditional/ConditionManager.java b/src/com/android/settings/dashboard/conditional/ConditionManager.java
index 3ef4f5bf4b4..d710da201f0 100644
--- a/src/com/android/settings/dashboard/conditional/ConditionManager.java
+++ b/src/com/android/settings/dashboard/conditional/ConditionManager.java
@@ -130,6 +130,7 @@ public class ConditionManager {
private void addMissingConditions() {
addIfMissing(AirplaneModeCondition.class);
addIfMissing(HotspotCondition.class);
+ addIfMissing(DndCondition.class);
}
private void addIfMissing(Class extends Condition> clz) {
@@ -144,6 +145,8 @@ public class ConditionManager {
return new AirplaneModeCondition(this);
} else if (HotspotCondition.class == clz) {
return new HotspotCondition(this);
+ } else if (DndCondition.class == clz) {
+ return new DndCondition(this);
}
try {
Constructor> constructor = clz.getConstructor(ConditionManager.class);
diff --git a/src/com/android/settings/dashboard/conditional/DndCondition.java b/src/com/android/settings/dashboard/conditional/DndCondition.java
new file mode 100644
index 00000000000..3cc3cf04b18
--- /dev/null
+++ b/src/com/android/settings/dashboard/conditional/DndCondition.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.dashboard.conditional;
+
+import android.app.ActivityManager;
+import android.app.NotificationManager;
+import android.app.StatusBarManager;
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.graphics.drawable.Icon;
+import android.provider.Settings;
+
+import android.service.notification.ZenModeConfig;
+import com.android.settings.R;
+
+public class DndCondition extends Condition {
+
+ private static final String TAG = "DndCondition";
+
+ private int mZen;
+ private ZenModeConfig mConfig;
+
+ public DndCondition(ConditionManager manager) {
+ super(manager);
+ }
+
+ @Override
+ public void refreshState() {
+ NotificationManager notificationManager =
+ mManager.getContext().getSystemService(NotificationManager.class);
+ mZen = notificationManager.getZenMode();
+ boolean zenModeEnabled = mZen != Settings.Global.ZEN_MODE_OFF;
+ if (zenModeEnabled) {
+ mConfig = notificationManager.getZenModeConfig();
+ } else {
+ mConfig = null;
+ }
+ setActive(zenModeEnabled);
+ }
+
+ @Override
+ protected void onSilenceChanged(boolean silenced) {
+ // Only need to listen for dnd mode changes when its been silenced.
+ PackageManager pm = mManager.getContext().getPackageManager();
+ pm.setComponentEnabledSetting(new ComponentName(mManager.getContext(), Receiver.class),
+ silenced ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
+ : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
+ PackageManager.DONT_KILL_APP);
+ }
+
+ private CharSequence getZenState() {
+ switch (mZen) {
+ case Settings.Global.ZEN_MODE_ALARMS:
+ return mManager.getContext().getString(R.string.zen_mode_option_alarms);
+ case Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS:
+ return mManager.getContext().getString(
+ R.string.zen_mode_option_important_interruptions);
+ case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
+ return mManager.getContext().getString(R.string.zen_mode_option_no_interruptions);
+ }
+ return null;
+ }
+
+ @Override
+ public Icon getIcon() {
+ return Icon.createWithResource(mManager.getContext(), R.drawable.ic_zen);
+ }
+
+ @Override
+ public CharSequence getTitle() {
+ return mManager.getContext().getString(R.string.condition_zen_title, getZenState());
+ }
+
+ @Override
+ public CharSequence getSummary() {
+ final boolean isForever = mConfig != null && mConfig.manualRule != null
+ && mConfig.manualRule.conditionId == null;
+ return isForever ? mManager.getContext().getString(com.android.internal.R.string.zen_mode_forever_dnd)
+ : ZenModeConfig.getConditionSummary(mManager.getContext(), mConfig,
+ ActivityManager.getCurrentUser(),
+ false);
+ }
+
+ @Override
+ public CharSequence[] getActions() {
+ return new CharSequence[] { mManager.getContext().getString(R.string.condition_turn_off) };
+ }
+
+ @Override
+ public void onPrimaryClick() {
+ StatusBarManager statusBar = mManager.getContext().getSystemService(StatusBarManager.class);
+ statusBar.expandSettingsPanel("dnd");
+ }
+
+ @Override
+ public void onActionClick(int index) {
+ if (index == 0) {
+ NotificationManager notificationManager = mManager.getContext().getSystemService(
+ NotificationManager.class);
+ notificationManager.setZenMode(Settings.Global.ZEN_MODE_OFF, null, TAG);
+ setActive(false);
+ } else {
+ throw new IllegalArgumentException("Unexpected index " + index);
+ }
+ }
+
+ public static class Receiver extends BroadcastReceiver {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED_INTERNAL
+ .equals(intent.getAction())) {
+ ConditionManager.get(context).getCondition(DndCondition.class)
+ .refreshState();
+ }
+ }
+ }
+}