Skip to content

Commit d6297db

Browse files
cwrenAndroid (Google) Code Review
authored andcommitted
Add an alternate title that can be used in the overflow of a InboxStyle.
Always hide contentText for BigTextStyle and InboxStyle. Style cannot be used without specialization, it should be abstract. Bug: 6428978 Bug: 6274137 Bug: 6317471 Change-Id: I21531a94494f891a058a477805b177e736b921cf
1 parent a2c2130 commit d6297db

File tree

7 files changed

+191
-46
lines changed

7 files changed

+191
-46
lines changed

api/current.txt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3770,12 +3770,18 @@ package android.app {
37703770
ctor public Notification.BigPictureStyle();
37713771
ctor public Notification.BigPictureStyle(android.app.Notification.Builder);
37723772
method public android.app.Notification.BigPictureStyle bigPicture(android.graphics.Bitmap);
3773+
method public android.app.Notification build();
3774+
method public android.app.Notification.BigPictureStyle setBigContentTitle(java.lang.CharSequence);
3775+
method public android.app.Notification.BigPictureStyle setSummaryText(java.lang.CharSequence);
37733776
}
37743777

37753778
public static class Notification.BigTextStyle extends android.app.Notification.Style {
37763779
ctor public Notification.BigTextStyle();
37773780
ctor public Notification.BigTextStyle(android.app.Notification.Builder);
37783781
method public android.app.Notification.BigTextStyle bigText(java.lang.CharSequence);
3782+
method public android.app.Notification build();
3783+
method public android.app.Notification.BigTextStyle setBigContentTitle(java.lang.CharSequence);
3784+
method public android.app.Notification.BigTextStyle setSummaryText(java.lang.CharSequence);
37793785
}
37803786

37813787
public static class Notification.Builder {
@@ -3817,11 +3823,18 @@ package android.app {
38173823
ctor public Notification.InboxStyle();
38183824
ctor public Notification.InboxStyle(android.app.Notification.Builder);
38193825
method public android.app.Notification.InboxStyle addLine(java.lang.CharSequence);
3826+
method public android.app.Notification build();
3827+
method public android.app.Notification.InboxStyle setBigContentTitle(java.lang.CharSequence);
3828+
method public android.app.Notification.InboxStyle setSummaryText(java.lang.CharSequence);
38203829
}
38213830

3822-
public static class Notification.Style {
3831+
public static abstract class Notification.Style {
38233832
ctor public Notification.Style();
3824-
method public android.app.Notification build();
3833+
method public abstract android.app.Notification build();
3834+
method protected void checkBuilder();
3835+
method protected android.widget.RemoteViews getStandardView(int);
3836+
method protected void internalSetBigContentTitle(java.lang.CharSequence);
3837+
method protected void internalSetSummaryText(java.lang.CharSequence);
38253838
method public void setBuilder(android.app.Notification.Builder);
38263839
field protected android.app.Notification.Builder mBuilder;
38273840
}

core/java/android/app/Notification.java

Lines changed: 120 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,8 @@ private RemoteViews applyStandardTemplate(int resId) {
13971397

13981398
if (mSubText != null) {
13991399
contentView.setTextViewText(R.id.text, mSubText);
1400-
contentView.setViewVisibility(R.id.text2, View.VISIBLE);
1400+
contentView.setViewVisibility(R.id.text2,
1401+
mContentText != null ? View.VISIBLE : View.GONE);
14011402
} else {
14021403
contentView.setViewVisibility(R.id.text2, View.GONE);
14031404
if (mProgressMax != 0 || mProgressIndeterminate) {
@@ -1428,12 +1429,12 @@ private RemoteViews applyStandardTemplateWithActions(int layoutId) {
14281429

14291430
int N = mActions.size();
14301431
if (N > 0) {
1431-
Log.d("Notification", "has actions: " + mContentText);
1432+
// Log.d("Notification", "has actions: " + mContentText);
14321433
big.setViewVisibility(R.id.actions, View.VISIBLE);
14331434
if (N>3) N=3;
14341435
for (int i=0; i<N; i++) {
14351436
final RemoteViews button = generateActionButton(mActions.get(i));
1436-
Log.d("Notification", "adding action " + i + ": " + mActions.get(i).title);
1437+
//Log.d("Notification", "adding action " + i + ": " + mActions.get(i).title);
14371438
big.addView(R.id.actions, button);
14381439
}
14391440
}
@@ -1549,22 +1550,71 @@ public Notification build() {
15491550
* An object that can apply a rich notification style to a {@link Notification.Builder}
15501551
* object.
15511552
*/
1552-
public static class Style {
1553+
public static abstract class Style
1554+
{
1555+
private CharSequence mBigContentTitle;
1556+
private CharSequence mSummaryText = null;
1557+
15531558
protected Builder mBuilder;
15541559

1560+
/**
1561+
* Overrides ContentTitle in the big form of the template.
1562+
* This defaults to the value passed to setContentTitle().
1563+
*/
1564+
protected void internalSetBigContentTitle(CharSequence title) {
1565+
mBigContentTitle = title;
1566+
}
1567+
1568+
/**
1569+
* Set the first line of text after the detail section in the big form of the template.
1570+
*/
1571+
protected void internalSetSummaryText(CharSequence cs) {
1572+
mSummaryText = cs;
1573+
}
1574+
15551575
public void setBuilder(Builder builder) {
15561576
if (mBuilder != builder) {
15571577
mBuilder = builder;
15581578
mBuilder.setStyle(this);
15591579
}
15601580
}
15611581

1562-
public Notification build() {
1582+
protected void checkBuilder() {
15631583
if (mBuilder == null) {
15641584
throw new IllegalArgumentException("Style requires a valid Builder object");
15651585
}
1566-
return mBuilder.buildUnstyled();
15671586
}
1587+
1588+
protected RemoteViews getStandardView(int layoutId) {
1589+
checkBuilder();
1590+
1591+
if (mBigContentTitle != null) {
1592+
mBuilder.setContentTitle(mBigContentTitle);
1593+
}
1594+
1595+
if (mBuilder.mSubText == null) {
1596+
mBuilder.setContentText(null);
1597+
}
1598+
1599+
RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(layoutId);
1600+
1601+
if (mBuilder.mSubText == null) {
1602+
contentView.setViewVisibility(R.id.line3, View.GONE);
1603+
}
1604+
1605+
if (mBigContentTitle != null && mBigContentTitle.equals("")) {
1606+
contentView.setViewVisibility(R.id.line1, View.GONE);
1607+
}
1608+
1609+
if (mSummaryText != null && !mSummaryText.equals("")) {
1610+
contentView.setViewVisibility(R.id.overflow_title, View.VISIBLE);
1611+
contentView.setTextViewText(R.id.overflow_title, mSummaryText);
1612+
}
1613+
1614+
return contentView;
1615+
}
1616+
1617+
public abstract Notification build();
15681618
}
15691619

15701620
/**
@@ -1594,13 +1644,30 @@ public BigPictureStyle(Builder builder) {
15941644
setBuilder(builder);
15951645
}
15961646

1647+
/**
1648+
* Overrides ContentTitle in the big form of the template.
1649+
* This defaults to the value passed to setContentTitle().
1650+
*/
1651+
public BigPictureStyle setBigContentTitle(CharSequence title) {
1652+
internalSetBigContentTitle(title);
1653+
return this;
1654+
}
1655+
1656+
/**
1657+
* Set the first line of text after the detail section in the big form of the template.
1658+
*/
1659+
public BigPictureStyle setSummaryText(CharSequence cs) {
1660+
internalSetSummaryText(cs);
1661+
return this;
1662+
}
1663+
15971664
public BigPictureStyle bigPicture(Bitmap b) {
15981665
mPicture = b;
15991666
return this;
16001667
}
16011668

16021669
private RemoteViews makeBigContentView() {
1603-
RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(R.layout.notification_template_big_picture);
1670+
RemoteViews contentView = getStandardView(R.layout.notification_template_big_picture);
16041671

16051672
contentView.setImageViewBitmap(R.id.big_picture, mPicture);
16061673

@@ -1609,9 +1676,7 @@ private RemoteViews makeBigContentView() {
16091676

16101677
@Override
16111678
public Notification build() {
1612-
if (mBuilder == null) {
1613-
throw new IllegalArgumentException("Style requires a valid Builder object");
1614-
}
1679+
checkBuilder();
16151680
Notification wip = mBuilder.buildUnstyled();
16161681
wip.bigContentView = makeBigContentView();
16171682
return wip;
@@ -1645,26 +1710,39 @@ public BigTextStyle(Builder builder) {
16451710
setBuilder(builder);
16461711
}
16471712

1713+
/**
1714+
* Overrides ContentTitle in the big form of the template.
1715+
* This defaults to the value passed to setContentTitle().
1716+
*/
1717+
public BigTextStyle setBigContentTitle(CharSequence title) {
1718+
internalSetBigContentTitle(title);
1719+
return this;
1720+
}
1721+
1722+
/**
1723+
* Set the first line of text after the detail section in the big form of the template.
1724+
*/
1725+
public BigTextStyle setSummaryText(CharSequence cs) {
1726+
internalSetSummaryText(cs);
1727+
return this;
1728+
}
1729+
16481730
public BigTextStyle bigText(CharSequence cs) {
16491731
mBigText = cs;
16501732
return this;
16511733
}
16521734

16531735
private RemoteViews makeBigContentView() {
1654-
int bigTextId = R.layout.notification_template_big_text;
1655-
RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(bigTextId);
1736+
RemoteViews contentView = getStandardView(R.layout.notification_template_big_text);
16561737
contentView.setTextViewText(R.id.big_text, mBigText);
16571738
contentView.setViewVisibility(R.id.big_text, View.VISIBLE);
1658-
contentView.setViewVisibility(R.id.text2, View.GONE);
16591739

16601740
return contentView;
16611741
}
16621742

16631743
@Override
16641744
public Notification build() {
1665-
if (mBuilder == null) {
1666-
throw new IllegalArgumentException("Style requires a valid Builder object");
1667-
}
1745+
checkBuilder();
16681746
Notification wip = mBuilder.buildUnstyled();
16691747
wip.bigContentView = makeBigContentView();
16701748
return wip;
@@ -1678,12 +1756,14 @@ public Notification build() {
16781756
* <pre class="prettyprint">
16791757
* Notification noti = new Notification.InboxStyle(
16801758
* new Notification.Builder()
1681-
* .setContentTitle(&quot;New mail from &quot; + sender.toString())
1759+
* .setContentTitle(&quot;5 New mails from &quot; + sender.toString())
16821760
* .setContentText(subject)
16831761
* .setSmallIcon(R.drawable.new_mail)
16841762
* .setLargeIcon(aBitmap))
16851763
* .addLine(str1)
16861764
* .addLine(str2)
1765+
* .setContentTitle("")
1766+
* .setSummaryText(&quot;+3 more&quot;)
16871767
* .build();
16881768
* </pre>
16891769
*
@@ -1699,16 +1779,35 @@ public InboxStyle(Builder builder) {
16991779
setBuilder(builder);
17001780
}
17011781

1782+
/**
1783+
* Overrides ContentTitle in the big form of the template.
1784+
* This defaults to the value passed to setContentTitle().
1785+
*/
1786+
public InboxStyle setBigContentTitle(CharSequence title) {
1787+
internalSetBigContentTitle(title);
1788+
return this;
1789+
}
1790+
1791+
/**
1792+
* Set the first line of text after the detail section in the big form of the template.
1793+
*/
1794+
public InboxStyle setSummaryText(CharSequence cs) {
1795+
internalSetSummaryText(cs);
1796+
return this;
1797+
}
1798+
17021799
public InboxStyle addLine(CharSequence cs) {
17031800
mTexts.add(cs);
17041801
return this;
17051802
}
17061803

17071804
private RemoteViews makeBigContentView() {
1708-
RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(R.layout.notification_template_inbox);
1805+
RemoteViews contentView = getStandardView(R.layout.notification_template_inbox);
1806+
contentView.setViewVisibility(R.id.text2, View.GONE);
1807+
1808+
int[] rowIds = {R.id.inbox_text0, R.id.inbox_text1, R.id.inbox_text2, R.id.inbox_text3,
1809+
R.id.inbox_text4};
17091810

1710-
int[] rowIds = {R.id.inbox_text0, R.id.inbox_text1, R.id.inbox_text2, R.id.inbox_text3, R.id.inbox_text4};
1711-
17121811
int i=0;
17131812
while (i < mTexts.size() && i < rowIds.length) {
17141813
CharSequence str = mTexts.get(i);
@@ -1724,9 +1823,7 @@ private RemoteViews makeBigContentView() {
17241823

17251824
@Override
17261825
public Notification build() {
1727-
if (mBuilder == null) {
1728-
throw new IllegalArgumentException("Style requires a valid Builder object");
1729-
}
1826+
checkBuilder();
17301827
Notification wip = mBuilder.buildUnstyled();
17311828
wip.bigContentView = makeBigContentView();
17321829
return wip;

core/res/res/layout/notification_template_base.xml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@
8585
android:ellipsize="marquee"
8686
android:visibility="gone"
8787
/>
88+
<TextView android:id="@+id/overflow_title"
89+
android:textAppearance="@style/TextAppearance.StatusBar.EventContent.Title"
90+
android:layout_width="match_parent"
91+
android:layout_height="wrap_content"
92+
android:singleLine="true"
93+
android:ellipsize="marquee"
94+
android:fadingEdge="horizontal"
95+
android:visibility="gone"
96+
android:layout_weight="1"
97+
/>
8898
<LinearLayout
8999
android:id="@+id/line3"
90100
android:layout_width="match_parent"
@@ -129,14 +139,5 @@
129139
android:visibility="gone"
130140
style="?android:attr/progressBarStyleHorizontal"
131141
/>
132-
<LinearLayout
133-
android:id="@+id/actions"
134-
android:layout_width="match_parent"
135-
android:layout_height="wrap_content"
136-
android:orientation="vertical"
137-
android:visibility="gone"
138-
>
139-
<!-- actions will be added here -->
140-
</LinearLayout>
141142
</LinearLayout>
142143
</FrameLayout>

core/res/res/layout/notification_template_big_base.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,13 @@
137137
style="?android:attr/progressBarStyleHorizontal"
138138
/>
139139
<LinearLayout
140-
android:id="@+id/actions"
140+
android:id="@+id/actions"
141141
android:layout_width="match_parent"
142142
android:layout_height="wrap_content"
143+
android:orientation="vertical"
143144
android:visibility="gone"
144-
>
145-
<!-- actions will be added here -->
145+
>
146+
<!-- actions will be added here -->
146147
</LinearLayout>
147148
</LinearLayout>
148149
</FrameLayout>

core/res/res/layout/notification_template_big_text.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,24 @@
100100
/>
101101
</LinearLayout>
102102
<LinearLayout
103-
android:id="@+id/actions"
103+
android:id="@+id/actions"
104104
android:layout_width="match_parent"
105105
android:layout_height="wrap_content"
106106
android:orientation="vertical"
107107
android:visibility="gone"
108108
>
109109
<!-- actions will be added here -->
110110
</LinearLayout>
111+
<TextView android:id="@+id/overflow_title"
112+
android:textAppearance="@style/TextAppearance.StatusBar.EventContent.Title"
113+
android:layout_width="match_parent"
114+
android:layout_height="wrap_content"
115+
android:singleLine="true"
116+
android:ellipsize="marquee"
117+
android:fadingEdge="horizontal"
118+
android:visibility="gone"
119+
android:layout_weight="1"
120+
/>
111121
<LinearLayout
112122
android:id="@+id/line3"
113123
android:layout_width="match_parent"

0 commit comments

Comments
 (0)