From b2a1c23a553254b71f25f0ed0773d4d3126656f8 Mon Sep 17 00:00:00 2001 From: Daniel Sandler Date: Sat, 24 Mar 2012 10:37:28 -0500 Subject: Add text labels to intruder actions. Change-Id: I544bed7b37c043639ee0e6a11bf757c0a191c1fc --- core/java/android/app/Notification.java | 43 ++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) (limited to 'core/java') diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 04ab407..bbb6a4e 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -918,6 +918,8 @@ public class Notification implements Parcelable private Bundle mExtras; private int mPriority; private ArrayList mActions = new ArrayList(3); + private boolean mCanHasIntruder; + private boolean mIntruderActionsShowText; /** * Constructs a new Builder with the defaults: @@ -1313,6 +1315,38 @@ public class Notification implements Parcelable return this; } + /** + * Specify whether this notification should pop up as an + * "intruder alert" (a small window that shares the screen with the + * current activity). This sort of notification is (as the name implies) + * very intrusive, so use it sparingly for notifications that require + * the user's attention. + * + * Notes: + *
    + *
  • Intruder alerts only show when the screen is on.
  • + *
  • Intruder alerts take precedence over fullScreenIntents.
  • + *
+ * + * @param intrude Whether to pop up an intruder alert (default false). + */ + public Builder setUsesIntruderAlert(boolean intrude) { + mCanHasIntruder = intrude; + return this; + } + + /** + * Control text on intruder alert action buttons. By default, action + * buttons in intruders do not show textual labels. + * + * @param showActionText Whether to show text labels beneath action + * icons (default false). + */ + public Builder setIntruderActionsShowText(boolean showActionText) { + mIntruderActionsShowText = showActionText; + return this; + } + private void setFlag(int mask, boolean value) { if (value) { mFlags |= mask; @@ -1394,7 +1428,7 @@ public class Notification implements Parcelable } } - private RemoteViews makeIntruderView() { + private RemoteViews makeIntruderView(boolean showLabels) { RemoteViews intruderView = new RemoteViews(mContext.getPackageName(), R.layout.notification_intruder_content); if (mLargeIcon != null) { @@ -1422,7 +1456,8 @@ public class Notification implements Parcelable final int buttonId = BUTTONS[i]; intruderView.setViewVisibility(buttonId, View.VISIBLE); - intruderView.setImageViewResource(buttonId, action.icon); + intruderView.setTextViewText(buttonId, showLabels ? action.title : null); + intruderView.setTextViewCompoundDrawables(buttonId, 0, action.icon, 0, 0); intruderView.setContentDescription(buttonId, action.title); intruderView.setOnClickPendingIntent(buttonId, action.actionIntent); } @@ -1457,7 +1492,9 @@ public class Notification implements Parcelable n.ledOffMS = mLedOffMs; n.defaults = mDefaults; n.flags = mFlags; - n.intruderView = makeIntruderView(); + if (mCanHasIntruder) { + n.intruderView = makeIntruderView(mIntruderActionsShowText); + } if (mLedOnMs != 0 && mLedOffMs != 0) { n.flags |= FLAG_SHOW_LIGHTS; } -- cgit v1.1