Skip to content

Commit 0424716

Browse files
dsandlerAndroid (Google) Code Review
authored andcommitted
Merge "Show action buttons in expanded notifications."
2 parents 2c93efc + 96fd7c1 commit 0424716

File tree

10 files changed

+262
-153
lines changed

10 files changed

+262
-153
lines changed

core/java/android/app/Notification.java

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import android.os.Parcelable;
2929
import android.text.TextUtils;
3030
import android.util.IntProperty;
31+
import android.util.Log;
3132
import android.view.View;
3233
import android.widget.ProgressBar;
3334
import android.widget.RemoteViews;
@@ -808,7 +809,7 @@ public Notification[] newArray(int size)
808809
public void setLatestEventInfo(Context context,
809810
CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent) {
810811
RemoteViews contentView = new RemoteViews(context.getPackageName(),
811-
R.layout.status_bar_latest_event_content);
812+
R.layout.notification_template_base);
812813
if (this.icon != 0) {
813814
contentView.setImageViewResource(R.id.icon, this.icon);
814815
}
@@ -1439,11 +1440,28 @@ private RemoteViews applyStandardTemplate(int resId) {
14391440
return contentView;
14401441
}
14411442

1443+
private RemoteViews applyStandardTemplateWithActions(int layoutId) {
1444+
RemoteViews big = applyStandardTemplate(layoutId);
1445+
1446+
int N = mActions.size();
1447+
if (N > 0) {
1448+
Log.d("Notification", "has actions: " + mContentText);
1449+
big.setViewVisibility(R.id.actions, View.VISIBLE);
1450+
if (N>3) N=3;
1451+
for (int i=0; i<N; i++) {
1452+
final RemoteViews button = generateActionButton(mActions.get(i));
1453+
Log.d("Notification", "adding action " + i + ": " + mActions.get(i).title);
1454+
big.addView(R.id.actions, button);
1455+
}
1456+
}
1457+
return big;
1458+
}
1459+
14421460
private RemoteViews makeContentView() {
14431461
if (mContentView != null) {
14441462
return mContentView;
14451463
} else {
1446-
return applyStandardTemplate(R.layout.status_bar_latest_event_content); // no more special large_icon flavor
1464+
return applyStandardTemplate(R.layout.notification_template_base); // no more special large_icon flavor
14471465
}
14481466
}
14491467

@@ -1461,6 +1479,12 @@ private RemoteViews makeTickerView() {
14611479
}
14621480
}
14631481

1482+
private RemoteViews makeBigContentView() {
1483+
if (mActions.size() == 0) return null;
1484+
1485+
return applyStandardTemplateWithActions(R.layout.notification_template_base);
1486+
}
1487+
14641488
private RemoteViews makeIntruderView(boolean showLabels) {
14651489
RemoteViews intruderView = new RemoteViews(mContext.getPackageName(),
14661490
R.layout.notification_intruder_content);
@@ -1500,6 +1524,15 @@ private RemoteViews makeIntruderView(boolean showLabels) {
15001524
return intruderView;
15011525
}
15021526

1527+
private RemoteViews generateActionButton(Action action) {
1528+
RemoteViews button = new RemoteViews(mContext.getPackageName(), R.layout.notification_action);
1529+
button.setTextViewCompoundDrawables(R.id.action0, action.icon, 0, 0, 0);
1530+
button.setTextViewText(R.id.action0, action.title);
1531+
button.setOnClickPendingIntent(R.id.action0, action.actionIntent);
1532+
button.setContentDescription(R.id.action0, action.title);
1533+
return button;
1534+
}
1535+
15031536
/**
15041537
* Combine all of the options that have been set and return a new {@link Notification}
15051538
* object.
@@ -1528,6 +1561,7 @@ public Notification getNotification() {
15281561
if (mCanHasIntruder) {
15291562
n.intruderView = makeIntruderView(mIntruderActionsShowText);
15301563
}
1564+
n.bigContentView = makeBigContentView();
15311565
if (mLedOnMs != 0 && mLedOffMs != 0) {
15321566
n.flags |= FLAG_SHOW_LIGHTS;
15331567
}
@@ -1583,7 +1617,7 @@ public BigPictureStyle bigPicture(Bitmap b) {
15831617
}
15841618

15851619
private RemoteViews makeBigContentView() {
1586-
RemoteViews contentView = mBuilder.applyStandardTemplate(R.layout.notification_template_big_picture);
1620+
RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(R.layout.notification_template_big_picture);
15871621

15881622
contentView.setImageViewBitmap(R.id.big_picture, mPicture);
15891623

@@ -1630,7 +1664,7 @@ public BigTextStyle bigText(CharSequence cs) {
16301664
}
16311665

16321666
private RemoteViews makeBigContentView() {
1633-
RemoteViews contentView = mBuilder.applyStandardTemplate(R.layout.status_bar_latest_event_content);
1667+
RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(R.layout.notification_template_base);
16341668

16351669
contentView.setTextViewText(R.id.big_text, mBigText);
16361670
contentView.setViewVisibility(R.id.big_text, View.VISIBLE);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright (C) 2012 The Android Open Source Project
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
17+
<Button xmlns:android="http://schemas.android.com/apk/res/android"
18+
android:id="@+id/action0"
19+
android:layout_width="match_parent"
20+
android:layout_height="wrap_content"
21+
style="@android:style/Widget.Holo.Button.Small"
22+
android:gravity="left"
23+
/>
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright (C) 2012 The Android Open Source Project
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
17+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
18+
android:id="@+id/status_bar_latest_event_content"
19+
android:layout_width="match_parent"
20+
android:layout_height="wrap_content"
21+
>
22+
<ImageView android:id="@+id/icon"
23+
android:layout_width="@dimen/notification_large_icon_width"
24+
android:layout_height="@dimen/notification_large_icon_height"
25+
android:background="@android:drawable/notify_panel_notification_icon_bg_tile"
26+
android:scaleType="center"
27+
/>
28+
<LinearLayout
29+
android:layout_width="match_parent"
30+
android:layout_height="wrap_content"
31+
android:layout_gravity="center_vertical"
32+
android:layout_marginLeft="@dimen/notification_large_icon_width"
33+
android:minHeight="@dimen/notification_large_icon_height"
34+
android:orientation="vertical"
35+
android:paddingLeft="12dp"
36+
android:paddingRight="12dp"
37+
android:paddingTop="4dp"
38+
android:paddingBottom="4dp"
39+
>
40+
<LinearLayout
41+
android:id="@+id/line1"
42+
android:layout_width="match_parent"
43+
android:layout_height="wrap_content"
44+
android:orientation="horizontal"
45+
>
46+
<TextView android:id="@+id/title"
47+
android:textAppearance="@style/TextAppearance.StatusBar.EventContent.Title"
48+
android:layout_width="match_parent"
49+
android:layout_height="wrap_content"
50+
android:singleLine="true"
51+
android:ellipsize="marquee"
52+
android:fadingEdge="horizontal"
53+
android:layout_weight="1"
54+
/>
55+
<DateTimeView android:id="@+id/time"
56+
android:textAppearance="@style/TextAppearance.StatusBar.EventContent.Time"
57+
android:layout_width="wrap_content"
58+
android:layout_height="wrap_content"
59+
android:layout_gravity="center"
60+
android:layout_weight="0"
61+
android:singleLine="true"
62+
android:gravity="center"
63+
android:paddingLeft="8dp"
64+
/>
65+
</LinearLayout>
66+
<TextView android:id="@+id/text2"
67+
android:textAppearance="@style/TextAppearance.StatusBar.EventContent.Line2"
68+
android:layout_width="match_parent"
69+
android:layout_height="wrap_content"
70+
android:layout_marginTop="-2dp"
71+
android:layout_marginBottom="-2dp"
72+
android:singleLine="true"
73+
android:fadingEdge="horizontal"
74+
android:ellipsize="marquee"
75+
android:visibility="gone"
76+
/>
77+
<TextView android:id="@+id/big_text"
78+
android:textAppearance="@style/TextAppearance.StatusBar.EventContent"
79+
android:layout_width="match_parent"
80+
android:layout_height="wrap_content"
81+
android:singleLine="false"
82+
android:visibility="gone"
83+
/>
84+
<LinearLayout
85+
android:id="@+id/line3"
86+
android:layout_width="match_parent"
87+
android:layout_height="wrap_content"
88+
android:orientation="horizontal"
89+
>
90+
<TextView android:id="@+id/text"
91+
android:textAppearance="@style/TextAppearance.StatusBar.EventContent"
92+
android:layout_width="0dp"
93+
android:layout_height="wrap_content"
94+
android:layout_weight="1"
95+
android:layout_gravity="center"
96+
android:singleLine="true"
97+
android:ellipsize="marquee"
98+
android:fadingEdge="horizontal"
99+
/>
100+
<TextView android:id="@+id/info"
101+
android:textAppearance="@style/TextAppearance.StatusBar.EventContent.Info"
102+
android:layout_width="wrap_content"
103+
android:layout_height="wrap_content"
104+
android:layout_gravity="center"
105+
android:layout_weight="0"
106+
android:singleLine="true"
107+
android:gravity="center"
108+
android:paddingLeft="8dp"
109+
/>
110+
<ImageView android:id="@+id/right_icon"
111+
android:layout_width="wrap_content"
112+
android:layout_height="wrap_content"
113+
android:layout_gravity="center"
114+
android:layout_weight="0"
115+
android:scaleType="center"
116+
android:paddingLeft="8dp"
117+
android:visibility="gone"
118+
android:drawableAlpha="180"
119+
/>
120+
</LinearLayout>
121+
<ProgressBar
122+
android:id="@android:id/progress"
123+
android:layout_width="match_parent"
124+
android:layout_height="wrap_content"
125+
android:visibility="gone"
126+
style="?android:attr/progressBarStyleHorizontal"
127+
/>
128+
<LinearLayout
129+
android:id="@+id/actions"
130+
android:layout_width="match_parent"
131+
android:layout_height="wrap_content"
132+
android:visibility="gone"
133+
>
134+
<!-- actions will be added here -->
135+
</LinearLayout>
136+
</LinearLayout>
137+
</FrameLayout>

core/res/res/layout/notification_template_big_picture.xml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright (C) 2012 The Android Open Source Project
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
117
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
218
android:id="@+id/status_bar_latest_event_content"
319
android:layout_width="match_parent"
@@ -9,9 +25,9 @@
925
android:layout_height="192dp"
1026
android:scaleType="centerCrop"
1127
/>
12-
<include layout="@layout/status_bar_latest_event_content"
28+
<include layout="@layout/notification_template_base"
1329
android:layout_width="match_parent"
14-
android:layout_height="@dimen/notification_large_icon_height"
30+
android:layout_height="wrap_content"
1531
android:layout_marginTop="192dp"
1632
/>
1733
</FrameLayout>
Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
1-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright (C) 2012 The Android Open Source Project
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
17+
<!-- Nobody should be using this file directly. If you do, you will get a
18+
purple background. Have fun with that. -->
19+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
220
android:id="@+id/status_bar_latest_event_content"
321
android:layout_width="match_parent"
422
android:layout_height="wrap_content"
23+
android:background="#FFFF00FF"
524
>
6-
<ImageView android:id="@+id/icon"
7-
android:layout_width="@dimen/notification_large_icon_width"
8-
android:layout_height="@dimen/notification_large_icon_height"
9-
android:background="@android:drawable/notify_panel_notification_icon_bg_tile"
10-
android:scaleType="center"
11-
/>
12-
<include layout="@layout/status_bar_latest_event_content_large_icon"
25+
<include layout="@layout/notification_template_base"
1326
android:layout_width="match_parent"
1427
android:layout_height="wrap_content"
15-
android:layout_gravity="center"
1628
/>
17-
</LinearLayout>
29+
</FrameLayout>

0 commit comments

Comments
 (0)