From be6e7e0f73bb886bd0423e44f2914793beed27b9 Mon Sep 17 00:00:00 2001 From: Daniel Sandler Date: Fri, 1 Feb 2013 17:49:11 -0500 Subject: [PATCH] Capture semantic Notification.Builder data in extras. This is an important step toward being able to reason about Notifications after they've been built and sent to the NoMan; right now most of that information is baked into the contentView and bigContentView before being thrown away. TODO: more stuff. Right now we're just grabbing the basics: title, text, subtext, and small icon res ID. Change-Id: Ief725bb38d160d340b0e3c46f83bc02d5a283d13 --- core/java/android/app/Notification.java | 122 +++++++++++++++--------- 1 file changed, 75 insertions(+), 47 deletions(-) diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 3f8e16c9dbd8e..4a0ee480ce038 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -25,15 +25,11 @@ import android.graphics.Bitmap; import android.media.AudioManager; import android.net.Uri; import android.os.Bundle; -import android.os.IBinder; import android.os.Parcel; import android.os.Parcelable; import android.os.SystemClock; import android.os.UserHandle; import android.text.TextUtils; -import android.util.IntProperty; -import android.util.Log; -import android.util.Slog; import android.util.TypedValue; import android.view.View; import android.widget.ProgressBar; @@ -436,8 +432,17 @@ public class Notification implements Parcelable * @hide */ public static final String EXTRA_PEOPLE = "android.people"; + /** @hide */ + public static final String EXTRA_TITLE = "android.title"; + /** @hide */ + public static final String EXTRA_TEXT = "android.text"; + /** @hide */ + public static final String EXTRA_SUBTEXT = "android.subtext"; + /** @hide */ + public static final String EXTRA_SMALL_ICON = "android.icon"; - private Bundle extras; + /** @hide */ + public Bundle extras = new Bundle(); /** * Structure to encapsulate an "action", including title and icon, that can be attached to a Notification. @@ -589,11 +594,10 @@ public class Notification implements Parcelable kind = parcel.createStringArray(); // may set kind to null - if (parcel.readInt() != 0) { - extras = parcel.readBundle(); - } + extras = parcel.readBundle(); // may be null + + actions = parcel.createTypedArray(Action.CREATOR); // may be null - actions = parcel.createTypedArray(Action.CREATOR); if (parcel.readInt() != 0) { bigContentView = RemoteViews.CREATOR.createFromParcel(parcel); } @@ -602,7 +606,11 @@ public class Notification implements Parcelable @Override public Notification clone() { Notification that = new Notification(); + cloneInto(that); + return that; + } + private void cloneInto(Notification that) { that.when = this.when; that.icon = this.icon; that.number = this.number; @@ -656,15 +664,16 @@ public class Notification implements Parcelable } - that.actions = new Action[this.actions.length]; - for(int i=0; i 0) { n.actions = new Action[mActions.size()]; mActions.toArray(n.actions); } + + n.extras = mExtras != null ? new Bundle(mExtras) : new Bundle(); + + // Store original information used in the construction of this object + n.extras.putCharSequence(EXTRA_TITLE, mContentTitle); + n.extras.putCharSequence(EXTRA_TEXT, mContentText); + n.extras.putCharSequence(EXTRA_SUBTEXT, mSubText); + n.extras.putInt(EXTRA_SMALL_ICON, mSmallIcon); + //n.extras.putByteArray(EXTRA_LARGE_ICON, ... + return n; } @@ -1642,6 +1649,16 @@ public class Notification implements Parcelable return buildUnstyled(); } } + + /** + * Apply this Builder to an existing {@link Notification} object. + * + * @hide + */ + public Notification buildInto(Notification n) { + build().cloneInto(n); + return n; + } } @@ -1882,6 +1899,9 @@ public class Notification implements Parcelable checkBuilder(); Notification wip = mBuilder.buildUnstyled(); wip.bigContentView = makeBigContentView(); + + wip.extras.putCharSequence(EXTRA_TEXT, mBigText); + return wip; } } @@ -1981,6 +2001,14 @@ public class Notification implements Parcelable checkBuilder(); Notification wip = mBuilder.buildUnstyled(); wip.bigContentView = makeBigContentView(); + + StringBuilder builder = new StringBuilder(); + for (CharSequence str : mTexts) { + builder.append(str); + builder.append("\n"); + } + wip.extras.putCharSequence(EXTRA_TEXT, builder); + return wip; } }