Skip to content

Commit fc90b6a

Browse files
dsandlerAndroid (Google) Code Review
authored andcommitted
Merge "Add text labels to intruder actions."
2 parents 73667fe + b2a1c23 commit fc90b6a

File tree

3 files changed

+55
-11
lines changed

3 files changed

+55
-11
lines changed

api/current.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3712,6 +3712,7 @@ package android.app {
37123712
method public android.app.Notification.Builder setDefaults(int);
37133713
method public android.app.Notification.Builder setDeleteIntent(android.app.PendingIntent);
37143714
method public android.app.Notification.Builder setFullScreenIntent(android.app.PendingIntent, boolean);
3715+
method public android.app.Notification.Builder setIntruderActionsShowText(boolean);
37153716
method public android.app.Notification.Builder setLargeIcon(android.graphics.Bitmap);
37163717
method public android.app.Notification.Builder setLights(int, int, int);
37173718
method public android.app.Notification.Builder setNumber(int);
@@ -3725,6 +3726,7 @@ package android.app {
37253726
method public android.app.Notification.Builder setSound(android.net.Uri, int);
37263727
method public android.app.Notification.Builder setTicker(java.lang.CharSequence);
37273728
method public android.app.Notification.Builder setTicker(java.lang.CharSequence, android.widget.RemoteViews);
3729+
method public android.app.Notification.Builder setUsesIntruderAlert(boolean);
37283730
method public android.app.Notification.Builder setVibrate(long[]);
37293731
method public android.app.Notification.Builder setWhen(long);
37303732
}

core/java/android/app/Notification.java

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

core/res/res/layout/notification_intruder_content.xml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
android:layout_width="match_parent"
33
android:layout_height="wrap_content"
44
android:orientation="vertical"
5-
android:background="#FF333333"
65
android:padding="4dp"
76
>
87
<ImageView android:id="@+id/icon"
@@ -39,29 +38,35 @@
3938
<LinearLayout
4039
android:id="@+id/actions"
4140
android:layout_width="match_parent"
42-
android:layout_height="40dp"
41+
android:layout_height="wrap_content"
4342
android:layout_marginTop="48dp"
4443
android:orientation="horizontal"
4544
android:visibility="gone"
4645
>
47-
<ImageView
46+
<Button
47+
style="?android:attr/buttonBarButtonStyle"
48+
android:textAppearance="@style/TextAppearance.StatusBar.EventContent.Title"
4849
android:id="@+id/action0"
4950
android:layout_width="0dp"
50-
android:layout_height="match_parent"
51+
android:layout_height="wrap_content"
5152
android:layout_weight="1"
5253
android:visibility="gone"
5354
/>
54-
<ImageView
55+
<Button
56+
style="?android:attr/buttonBarButtonStyle"
57+
android:textAppearance="@style/TextAppearance.StatusBar.EventContent.Title"
5558
android:id="@+id/action1"
5659
android:layout_width="0dp"
57-
android:layout_height="match_parent"
60+
android:layout_height="wrap_content"
5861
android:layout_weight="1"
5962
android:visibility="gone"
6063
/>
61-
<ImageView
64+
<Button
65+
style="?android:attr/buttonBarButtonStyle"
66+
android:textAppearance="@style/TextAppearance.StatusBar.EventContent.Title"
6267
android:id="@+id/action2"
6368
android:layout_width="0dp"
64-
android:layout_height="match_parent"
69+
android:layout_height="wrap_content"
6570
android:layout_weight="1"
6671
android:visibility="gone"
6772
/>

0 commit comments

Comments
 (0)