@@ -918,6 +918,8 @@ public static class Builder {
918918 private Bundle mExtras ;
919919 private int mPriority ;
920920 private ArrayList <Action > mActions = new ArrayList <Action >(3 );
921+ private boolean mCanHasIntruder ;
922+ private boolean mIntruderActionsShowText ;
921923
922924 /**
923925 * Constructs a new Builder with the defaults:
@@ -1313,6 +1315,38 @@ public Builder addAction(int icon, CharSequence title, PendingIntent intent) {
13131315 return this ;
13141316 }
13151317
1318+ /**
1319+ * Specify whether this notification should pop up as an
1320+ * "intruder alert" (a small window that shares the screen with the
1321+ * current activity). This sort of notification is (as the name implies)
1322+ * very intrusive, so use it sparingly for notifications that require
1323+ * the user's attention.
1324+ *
1325+ * Notes:
1326+ * <ul>
1327+ * <li>Intruder alerts only show when the screen is on.</li>
1328+ * <li>Intruder alerts take precedence over fullScreenIntents.</li>
1329+ * </ul>
1330+ *
1331+ * @param intrude Whether to pop up an intruder alert (default false).
1332+ */
1333+ public Builder setUsesIntruderAlert (boolean intrude ) {
1334+ mCanHasIntruder = intrude ;
1335+ return this ;
1336+ }
1337+
1338+ /**
1339+ * Control text on intruder alert action buttons. By default, action
1340+ * buttons in intruders do not show textual labels.
1341+ *
1342+ * @param showActionText Whether to show text labels beneath action
1343+ * icons (default false).
1344+ */
1345+ public Builder setIntruderActionsShowText (boolean showActionText ) {
1346+ mIntruderActionsShowText = showActionText ;
1347+ return this ;
1348+ }
1349+
13161350 private void setFlag (int mask , boolean value ) {
13171351 if (value ) {
13181352 mFlags |= mask ;
@@ -1394,7 +1428,7 @@ private RemoteViews makeTickerView() {
13941428 }
13951429 }
13961430
1397- private RemoteViews makeIntruderView () {
1431+ private RemoteViews makeIntruderView (boolean showLabels ) {
13981432 RemoteViews intruderView = new RemoteViews (mContext .getPackageName (),
13991433 R .layout .notification_intruder_content );
14001434 if (mLargeIcon != null ) {
@@ -1422,7 +1456,8 @@ private RemoteViews makeIntruderView() {
14221456 final int buttonId = BUTTONS [i ];
14231457
14241458 intruderView .setViewVisibility (buttonId , View .VISIBLE );
1425- intruderView .setImageViewResource (buttonId , action .icon );
1459+ intruderView .setTextViewText (buttonId , showLabels ? action .title : null );
1460+ intruderView .setTextViewCompoundDrawables (buttonId , 0 , action .icon , 0 , 0 );
14261461 intruderView .setContentDescription (buttonId , action .title );
14271462 intruderView .setOnClickPendingIntent (buttonId , action .actionIntent );
14281463 }
@@ -1457,7 +1492,9 @@ public Notification getNotification() {
14571492 n .ledOffMS = mLedOffMs ;
14581493 n .defaults = mDefaults ;
14591494 n .flags = mFlags ;
1460- n .intruderView = makeIntruderView ();
1495+ if (mCanHasIntruder ) {
1496+ n .intruderView = makeIntruderView (mIntruderActionsShowText );
1497+ }
14611498 if (mLedOnMs != 0 && mLedOffMs != 0 ) {
14621499 n .flags |= FLAG_SHOW_LIGHTS ;
14631500 }
0 commit comments