@@ -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("New mail from " + sender.toString())
1759+ * .setContentTitle("5 New mails from " + sender.toString())
16821760 * .setContentText(subject)
16831761 * .setSmallIcon(R.drawable.new_mail)
16841762 * .setLargeIcon(aBitmap))
16851763 * .addLine(str1)
16861764 * .addLine(str2)
1765+ * .setContentTitle("")
1766+ * .setSummaryText("+3 more")
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 ;
0 commit comments