diff options
| author | Daniel Sandler <dsandler@android.com> | 2012-04-17 16:46:51 -0400 |
|---|---|---|
| committer | Daniel Sandler <dsandler@android.com> | 2012-04-17 23:41:58 -0400 |
| commit | 879c5e07c019bbcd8647e60656d0749eae0467c3 (patch) | |
| tree | 06bee678b51fc99194eced4be0d8161598fd28cc /core/java/android/app/Notification.java | |
| parent | b4bc99e847d15f04c035d676e01ff85623565e0a (diff) | |
New InboxStyle template for expanded notifications.
Bug: 6336834
Change-Id: I67b273350b984673cbfb19267451a3782d0477fc
Diffstat (limited to 'core/java/android/app/Notification.java')
| -rw-r--r-- | core/java/android/app/Notification.java | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 5cce25f0bd6b..dc796bf6351f 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -1696,4 +1696,60 @@ public class Notification implements Parcelable return wip; } } + + /** + * Helper class for generating large-format notifications that include a list of (up to 5) strings. + * + * This class is a "rebuilder": It consumes a Builder object and modifies its behavior, like so: + * <pre class="prettyprint"> + * Notification noti = new Notification.DigestStyle( + * new Notification.Builder() + * .setContentTitle("New mail from " + sender.toString()) + * .setContentText(subject) + * .setSmallIcon(R.drawable.new_mail) + * .setLargeIcon(aBitmap)) + * .addLine(str1) + * .addLine(str2) + * .build(); + * </pre> + * + * @see Notification#bigContentView + */ + public static class InboxStyle { + private Builder mBuilder; + private ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>(5); + + public InboxStyle(Builder builder) { + mBuilder = builder; + } + + public InboxStyle addLine(CharSequence cs) { + mTexts.add(cs); + return this; + } + + private RemoteViews makeBigContentView() { + RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(R.layout.notification_template_inbox); + + int[] rowIds = {R.id.inbox_text0, R.id.inbox_text1, R.id.inbox_text2, R.id.inbox_text3, R.id.inbox_text4}; + + int i=0; + while (i < mTexts.size() && i < rowIds.length) { + CharSequence str = mTexts.get(i); + if (str != null && !str.equals("")) { + contentView.setViewVisibility(rowIds[i], View.VISIBLE); + contentView.setTextViewText(rowIds[i], str); + } + i++; + } + + return contentView; + } + + public Notification build() { + Notification wip = mBuilder.getNotification(); + wip.bigContentView = makeBigContentView(); + return wip; + } + } } |
