From ce6ff6403428069004e53651ea3b870a6bc67bb4 Mon Sep 17 00:00:00 2001 From: Daniel Sandler Date: Fri, 18 Feb 2011 12:51:08 -0500 Subject: [PATCH] Visual indication of do-not-disturb mode in system bar. Bug: 3408005 Change-Id: I934a6684bb3e90e2ada848872b5670f6b6e3e055 --- .../res/drawable-mdpi/ic_notification_dnd.png | Bin 0 -> 1075 bytes packages/SystemUI/res/values-xlarge/strings.xml | 7 ++ .../systemui/statusbar/tablet/TabletStatusBar.java | 96 ++++++++++++++++----- 3 files changed, 81 insertions(+), 22 deletions(-) create mode 100644 packages/SystemUI/res/drawable-mdpi/ic_notification_dnd.png diff --git a/packages/SystemUI/res/drawable-mdpi/ic_notification_dnd.png b/packages/SystemUI/res/drawable-mdpi/ic_notification_dnd.png new file mode 100644 index 0000000000000000000000000000000000000000..6d4da7f1233de80d8a2a662d6e07bb154c0ca8e0 GIT binary patch literal 1075 zcmV-31kC%1P)1p(Ha(C737;;YjXMmt6`Mgs<)C5#NlB*sKR$p=v~6^+Qeq{R0;$gA*F6hLyUI$ocXRuCW1 zT6(a-hp?dC5YqyJ1pXEypv1>~5x;#wz)}Exsg#UE$m?uOW)O|#N+JRUl*sF{(jE~x z0`VuY(>)N;@&46==2y?|)u-P)4lT@oGV5yEx>Gv#pDr9cdNJE|@LUGuX%RJ!k5BR< zV=MJCSxE%&%N}Ov|230VFGlag+V>uBN;dClP)ZfxG`pf@_RNrEhll%}d~gA=dS*Klj(g6qbLE3K zF2u7-bAj7cE`aZ}r4N1AwyuYmMQpc*I0AUi%~3znasR80O>vli1|2ebxma{H$;+GB9XI$Xb}~ws9?U zgTZ49Ok$G*$@pVC*9E|W<&_l<$H<&>9<^FXZ6AZdnt{SaY;xG&op6}ij^YA+aY&4o z&bjSS?c87#3swV5H)^6Iz z1;B!r3HEbLCvZ|yY%Hklj^b)W(3cp*A||oPVPiM~c$48}g8dw)fGstR#*C5FKQW)a)HH$q(5 zgLruZ63geM4W`HOb;EXSBQWe-xgl5TDF_~-u8c+^GUZ+3;#>hvAu>QT@U)-pk{Mh` z#%O?+y4140yQlB!quMSc#aoeIPENj`BVbhEUa*;0vNa7x#HL+JOCs30HtkyeLj)%f tvN`{lI4ag&ASUSNpd<^l`~RaAf$x(xC5B}Q2bBN-002ovPDHLkV1g^K_^1E? literal 0 HcmV?d00001 diff --git a/packages/SystemUI/res/values-xlarge/strings.xml b/packages/SystemUI/res/values-xlarge/strings.xml index dfd5851c6ae8..35be53208008 100644 --- a/packages/SystemUI/res/values-xlarge/strings.xml +++ b/packages/SystemUI/res/values-xlarge/strings.xml @@ -43,4 +43,11 @@ Location set by GPS + + + Notifications off + + + Tap here to turn notifications back on. diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBar.java index 7a13fded41b9..afb73a9033d8 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBar.java @@ -28,6 +28,7 @@ import android.app.Notification; import android.app.StatusBarManager; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; import android.inputmethodservice.InputMethodService; @@ -67,6 +68,7 @@ import com.android.systemui.statusbar.policy.BatteryController; import com.android.systemui.statusbar.policy.BluetoothController; import com.android.systemui.statusbar.policy.LocationController; import com.android.systemui.statusbar.policy.NetworkController; +import com.android.systemui.statusbar.policy.Prefs; import com.android.systemui.recent.RecentApplicationsActivity; public class TabletStatusBar extends StatusBar implements @@ -105,7 +107,7 @@ public class TabletStatusBar extends StatusBar implements IWindowManager mWindowManager; // tracking all current notifications - private NotificationData mNotns = new NotificationData(); + private NotificationData mNotificationData = new NotificationData(); TabletStatusBarView mStatusBarView; View mNotificationArea; @@ -113,6 +115,9 @@ public class TabletStatusBar extends StatusBar implements NotificationIconArea mNotificationIconArea; View mNavigationArea; + boolean mNotificationDNDMode; + NotificationData.Entry mNotificationDNDDummyEntry; + ImageView mBackButton; View mHomeButton; View mMenuButton; @@ -489,25 +494,43 @@ public class TabletStatusBar extends StatusBar implements switch (m.what) { case MSG_OPEN_NOTIFICATION_PEEK: if (DEBUG) Slog.d(TAG, "opening notification peek window; arg=" + m.arg1); + if (m.arg1 >= 0) { - final int N = mNotns.size(); - if (mNotificationPeekIndex >= 0 && mNotificationPeekIndex < N) { - NotificationData.Entry entry = mNotns.get(N-1-mNotificationPeekIndex); - entry.icon.setBackgroundColor(0); - mNotificationPeekIndex = -1; - mNotificationPeekKey = null; + final int N = mNotificationData.size(); + + if (!mNotificationDNDMode) { + if (mNotificationPeekIndex >= 0 && mNotificationPeekIndex < N) { + NotificationData.Entry entry = mNotificationData.get(N-1-mNotificationPeekIndex); + entry.icon.setBackgroundColor(0); + mNotificationPeekIndex = -1; + mNotificationPeekKey = null; + } } final int peekIndex = m.arg1; if (peekIndex < N) { //Slog.d(TAG, "loading peek: " + peekIndex); - NotificationData.Entry entry = mNotns.get(N-1-peekIndex); + NotificationData.Entry entry = + mNotificationDNDMode + ? mNotificationDNDDummyEntry + : mNotificationData.get(N-1-peekIndex); NotificationData.Entry copy = new NotificationData.Entry( entry.key, entry.notification, entry.icon); inflateViews(copy, mNotificationPeekRow); + if (mNotificationDNDMode) { + copy.content.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + SharedPreferences.Editor editor = Prefs.edit(mContext); + editor.putBoolean(Prefs.DO_NOT_DISTURB_PREF, false); + editor.apply(); + animateCollapse(); + } + }); + } + entry.icon.setBackgroundColor(0x20FFFFFF); // mNotificationPeekRow.setLayoutTransition( @@ -530,9 +553,13 @@ public class TabletStatusBar extends StatusBar implements if (DEBUG) Slog.d(TAG, "closing notification peek window"); mNotificationPeekWindow.setVisibility(View.GONE); mNotificationPeekRow.removeAllViews(); - final int N = mNotns.size(); + + final int N = mNotificationData.size(); if (mNotificationPeekIndex >= 0 && mNotificationPeekIndex < N) { - NotificationData.Entry entry = mNotns.get(N-1-mNotificationPeekIndex); + NotificationData.Entry entry = + mNotificationDNDMode + ? mNotificationDNDDummyEntry + : mNotificationData.get(N-1-mNotificationPeekIndex); entry.icon.setBackgroundColor(0); } @@ -643,7 +670,7 @@ public class TabletStatusBar extends StatusBar implements public void updateNotification(IBinder key, StatusBarNotification notification) { if (DEBUG) Slog.d(TAG, "updateNotification(" + key + " -> " + notification + ") // TODO"); - final NotificationData.Entry oldEntry = mNotns.findByKey(key); + final NotificationData.Entry oldEntry = mNotificationData.findByKey(key); if (oldEntry == null) { Slog.w(TAG, "updateNotification for unknown key: " + key); return; @@ -781,14 +808,15 @@ public class TabletStatusBar extends StatusBar implements if ((diff & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) { if ((state & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) { Slog.i(TAG, "DISABLE_NOTIFICATION_ICONS: yes"); - // synchronize with current shadow state - mNotificationIconArea.setVisibility(View.GONE); mTicker.halt(); } else { Slog.i(TAG, "DISABLE_NOTIFICATION_ICONS: no"); - // synchronize with current shadow state - mNotificationIconArea.setVisibility(View.VISIBLE); } + // refresh icons to show either notifications or the DND message + mNotificationDNDMode = Prefs.read(mContext) + .getBoolean(Prefs.DO_NOT_DISTURB_PREF, Prefs.DO_NOT_DISTURB_DEFAULT); + Slog.d(TAG, "DND: " + mNotificationDNDMode); + reloadAllNotificationIcons(); } else if ((diff & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) { if ((state & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) { mTicker.halt(); @@ -947,7 +975,7 @@ public class TabletStatusBar extends StatusBar implements } private void setAreThereNotifications() { - final boolean hasClearable = mNotns.hasClearableItems(); + final boolean hasClearable = mNotificationData.hasClearableItems(); } /** @@ -1081,7 +1109,7 @@ public class TabletStatusBar extends StatusBar implements } StatusBarNotification removeNotificationViews(IBinder key) { - NotificationData.Entry entry = mNotns.remove(key); + NotificationData.Entry entry = mNotificationData.remove(key); if (entry == null) { Slog.w(TAG, "removeNotification for unknown key: " + key); return null; @@ -1192,7 +1220,7 @@ public class TabletStatusBar extends StatusBar implements } // Add the icon. - int pos = mNotns.add(entry); + int pos = mNotificationData.add(entry); if (DEBUG) { Slog.d(TAG, "addNotificationViews: added at " + pos); } @@ -1216,7 +1244,31 @@ public class TabletStatusBar extends StatusBar implements final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(mIconSize + 2*mIconHPadding, mNaturalBarHeight); - int N = mNotns.size(); + // alternate behavior in DND mode + if (mNotificationDNDMode && mIconLayout.getChildCount() == 0) { + final StatusBarIconView iconView = new StatusBarIconView(mContext, "_dnd"); + iconView.setImageResource(R.drawable.ic_notification_dnd); + iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); + iconView.setPadding(mIconHPadding, 0, mIconHPadding, 0); + + final Notification dndNotification = new Notification.Builder(mContext) + .setContentTitle(mContext.getText(R.string.notifications_off_title)) + .setContentText(mContext.getText(R.string.notifications_off_text)) + .setSmallIcon(R.drawable.ic_notification_dnd) + .setOngoing(true) + .getNotification(); + + mNotificationDNDDummyEntry = new NotificationData.Entry( + null, + new StatusBarNotification("", 0, "", 0, 0, dndNotification), + iconView); + + mIconLayout.addView(iconView, params); + + return; + } + + int N = mNotificationData.size(); if (DEBUG) { Slog.d(TAG, "refreshing icons: " + N + " notifications, mIconLayout=" + mIconLayout); @@ -1231,7 +1283,7 @@ public class TabletStatusBar extends StatusBar implements MAX_NOTIFICATION_ICONS_IME_BUTTON_VISIBLE : MAX_NOTIFICATION_ICONS; for (int i=0; i< maxNotificationIconsCount; i++) { if (i>=N) break; - toShow.add(mNotns.get(N-i-1).icon); + toShow.add(mNotificationData.get(N-i-1).icon); } ArrayList toRemove = new ArrayList(); @@ -1258,12 +1310,12 @@ public class TabletStatusBar extends StatusBar implements } private void loadNotificationPanel() { - int N = mNotns.size(); + int N = mNotificationData.size(); ArrayList toShow = new ArrayList(); for (int i=0; i