Skip to content

Commit b9a6d4d

Browse files
dsandlerAndroid (Google) Code Review
authored andcommitted
Merge "New InboxStyle template for expanded notifications."
2 parents e1e8748 + 879c5e0 commit b9a6d4d

File tree

4 files changed

+245
-0
lines changed

4 files changed

+245
-0
lines changed

api/current.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3775,6 +3775,12 @@ package android.app {
37753775
method public android.app.Notification.Builder setWhen(long);
37763776
}
37773777

3778+
public static class Notification.InboxStyle {
3779+
ctor public Notification.InboxStyle(android.app.Notification.Builder);
3780+
method public android.app.Notification.InboxStyle addLine(java.lang.CharSequence);
3781+
method public android.app.Notification build();
3782+
}
3783+
37783784
public class NotificationManager {
37793785
method public void cancel(int);
37803786
method public void cancel(java.lang.String, int);

core/java/android/app/Notification.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,4 +1696,60 @@ public Notification build() {
16961696
return wip;
16971697
}
16981698
}
1699+
1700+
/**
1701+
* Helper class for generating large-format notifications that include a list of (up to 5) strings.
1702+
*
1703+
* This class is a "rebuilder": It consumes a Builder object and modifies its behavior, like so:
1704+
* <pre class="prettyprint">
1705+
* Notification noti = new Notification.DigestStyle(
1706+
* new Notification.Builder()
1707+
* .setContentTitle(&quot;New mail from &quot; + sender.toString())
1708+
* .setContentText(subject)
1709+
* .setSmallIcon(R.drawable.new_mail)
1710+
* .setLargeIcon(aBitmap))
1711+
* .addLine(str1)
1712+
* .addLine(str2)
1713+
* .build();
1714+
* </pre>
1715+
*
1716+
* @see Notification#bigContentView
1717+
*/
1718+
public static class InboxStyle {
1719+
private Builder mBuilder;
1720+
private ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>(5);
1721+
1722+
public InboxStyle(Builder builder) {
1723+
mBuilder = builder;
1724+
}
1725+
1726+
public InboxStyle addLine(CharSequence cs) {
1727+
mTexts.add(cs);
1728+
return this;
1729+
}
1730+
1731+
private RemoteViews makeBigContentView() {
1732+
RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(R.layout.notification_template_inbox);
1733+
1734+
int[] rowIds = {R.id.inbox_text0, R.id.inbox_text1, R.id.inbox_text2, R.id.inbox_text3, R.id.inbox_text4};
1735+
1736+
int i=0;
1737+
while (i < mTexts.size() && i < rowIds.length) {
1738+
CharSequence str = mTexts.get(i);
1739+
if (str != null && !str.equals("")) {
1740+
contentView.setViewVisibility(rowIds[i], View.VISIBLE);
1741+
contentView.setTextViewText(rowIds[i], str);
1742+
}
1743+
i++;
1744+
}
1745+
1746+
return contentView;
1747+
}
1748+
1749+
public Notification build() {
1750+
Notification wip = mBuilder.getNotification();
1751+
wip.bigContentView = makeBigContentView();
1752+
return wip;
1753+
}
1754+
}
16991755
}
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
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="fill_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+
android:gravity="center_vertical"
40+
>
41+
<LinearLayout
42+
android:id="@+id/line1"
43+
android:layout_width="match_parent"
44+
android:layout_height="wrap_content"
45+
android:orientation="horizontal"
46+
>
47+
<TextView android:id="@+id/title"
48+
android:textAppearance="@style/TextAppearance.StatusBar.EventContent.Title"
49+
android:layout_width="match_parent"
50+
android:layout_height="wrap_content"
51+
android:singleLine="true"
52+
android:ellipsize="marquee"
53+
android:fadingEdge="horizontal"
54+
android:layout_weight="1"
55+
/>
56+
<ViewStub android:id="@+id/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:visibility="gone"
62+
android:layout="@layout/notification_template_part_time"
63+
/>
64+
<ViewStub android:id="@+id/chronometer"
65+
android:layout_width="wrap_content"
66+
android:layout_height="wrap_content"
67+
android:layout_gravity="center"
68+
android:layout_weight="0"
69+
android:visibility="gone"
70+
android:layout="@layout/notification_template_part_chronometer"
71+
/>
72+
</LinearLayout>
73+
<TextView android:id="@+id/text2"
74+
android:textAppearance="@style/TextAppearance.StatusBar.EventContent.Line2"
75+
android:layout_width="match_parent"
76+
android:layout_height="wrap_content"
77+
android:layout_marginTop="-2dp"
78+
android:layout_marginBottom="-2dp"
79+
android:singleLine="true"
80+
android:fadingEdge="horizontal"
81+
android:ellipsize="marquee"
82+
android:visibility="gone"
83+
/>
84+
<TextView android:id="@+id/inbox_text0"
85+
android:textAppearance="@style/TextAppearance.StatusBar.EventContent"
86+
android:layout_width="match_parent"
87+
android:layout_height="wrap_content"
88+
android:singleLine="true"
89+
android:ellipsize="end"
90+
android:visibility="gone"
91+
/>
92+
<TextView android:id="@+id/inbox_text1"
93+
android:textAppearance="@style/TextAppearance.StatusBar.EventContent"
94+
android:layout_width="match_parent"
95+
android:layout_height="wrap_content"
96+
android:singleLine="true"
97+
android:ellipsize="end"
98+
android:visibility="gone"
99+
/>
100+
<TextView android:id="@+id/inbox_text2"
101+
android:textAppearance="@style/TextAppearance.StatusBar.EventContent"
102+
android:layout_width="match_parent"
103+
android:layout_height="wrap_content"
104+
android:singleLine="true"
105+
android:ellipsize="end"
106+
android:visibility="gone"
107+
/>
108+
<TextView android:id="@+id/inbox_text3"
109+
android:textAppearance="@style/TextAppearance.StatusBar.EventContent"
110+
android:layout_width="match_parent"
111+
android:layout_height="wrap_content"
112+
android:singleLine="true"
113+
android:ellipsize="end"
114+
android:visibility="gone"
115+
/>
116+
<TextView android:id="@+id/inbox_text4"
117+
android:textAppearance="@style/TextAppearance.StatusBar.EventContent"
118+
android:layout_width="match_parent"
119+
android:layout_height="wrap_content"
120+
android:singleLine="true"
121+
android:ellipsize="end"
122+
android:visibility="gone"
123+
/>
124+
<LinearLayout
125+
android:id="@+id/line3"
126+
android:layout_width="match_parent"
127+
android:layout_height="wrap_content"
128+
android:orientation="horizontal"
129+
>
130+
<TextView android:id="@+id/text"
131+
android:textAppearance="@style/TextAppearance.StatusBar.EventContent"
132+
android:layout_width="0dp"
133+
android:layout_height="wrap_content"
134+
android:layout_weight="1"
135+
android:layout_gravity="center"
136+
android:singleLine="true"
137+
android:ellipsize="marquee"
138+
android:fadingEdge="horizontal"
139+
/>
140+
<TextView android:id="@+id/info"
141+
android:textAppearance="@style/TextAppearance.StatusBar.EventContent.Info"
142+
android:layout_width="wrap_content"
143+
android:layout_height="wrap_content"
144+
android:layout_gravity="center"
145+
android:layout_weight="0"
146+
android:singleLine="true"
147+
android:gravity="center"
148+
android:paddingLeft="8dp"
149+
/>
150+
<ImageView android:id="@+id/right_icon"
151+
android:layout_width="wrap_content"
152+
android:layout_height="wrap_content"
153+
android:layout_gravity="center"
154+
android:layout_weight="0"
155+
android:scaleType="center"
156+
android:paddingLeft="8dp"
157+
android:visibility="gone"
158+
android:drawableAlpha="180"
159+
/>
160+
</LinearLayout>
161+
<ProgressBar
162+
android:id="@android:id/progress"
163+
android:layout_width="match_parent"
164+
android:layout_height="wrap_content"
165+
android:visibility="gone"
166+
style="?android:attr/progressBarStyleHorizontal"
167+
/>
168+
<LinearLayout
169+
android:id="@+id/actions"
170+
android:layout_width="match_parent"
171+
android:layout_height="wrap_content"
172+
android:visibility="gone"
173+
>
174+
<!-- actions will be added here -->
175+
</LinearLayout>
176+
</LinearLayout>
177+
</FrameLayout>

core/res/res/values/public.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,11 @@
205205
<java-symbol type="id" name="big_picture" />
206206
<java-symbol type="id" name="big_text" />
207207
<java-symbol type="id" name="chronometer" />
208+
<java-symbol type="id" name="inbox_text0" />
209+
<java-symbol type="id" name="inbox_text1" />
210+
<java-symbol type="id" name="inbox_text2" />
211+
<java-symbol type="id" name="inbox_text3" />
212+
<java-symbol type="id" name="inbox_text4" />
208213

209214
<java-symbol type="attr" name="actionModeShareDrawable" />
210215
<java-symbol type="attr" name="alertDialogCenterButtons" />
@@ -1085,6 +1090,7 @@
10851090
<java-symbol type="layout" name="notification_template_big_picture" />
10861091
<java-symbol type="layout" name="notification_template_part_time" />
10871092
<java-symbol type="layout" name="notification_template_part_chronometer" />
1093+
<java-symbol type="layout" name="notification_template_inbox" />
10881094

10891095
<java-symbol type="anim" name="slide_in_child_bottom" />
10901096
<java-symbol type="anim" name="slide_in_right" />

0 commit comments

Comments
 (0)