diff --git a/api/current.txt b/api/current.txt index 1393eb038500a..20b0be69749aa 100644 --- a/api/current.txt +++ b/api/current.txt @@ -3694,6 +3694,7 @@ package android.app { public static class Notification.Builder { ctor public Notification.Builder(android.content.Context); + method public android.app.Notification.Builder addAction(int, java.lang.CharSequence, android.app.PendingIntent); method public android.app.Notification.Builder addKind(java.lang.String); method public android.app.Notification getNotification(); method public android.app.Notification.Builder setAutoCancel(boolean); diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 5325af044083b..04ab4070f84ee 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -23,9 +23,11 @@ import android.content.Intent; import android.graphics.Bitmap; import android.net.Uri; import android.os.Bundle; +import android.os.IBinder; import android.os.Parcel; import android.os.Parcelable; import android.text.TextUtils; +import android.util.IntProperty; import android.view.View; import android.widget.ProgressBar; import android.widget.RemoteViews; @@ -185,6 +187,13 @@ public class Notification implements Parcelable */ public RemoteViews contentView; + + /** + * The view that will represent this notification in the pop-up "intruder alert" dialog. + * @hide + */ + public RemoteViews intruderView; + /** * The bitmap that may escape the bounds of the panel and bar. */ @@ -417,6 +426,64 @@ public class Notification implements Parcelable private Bundle extras; + /** + * Structure to encapsulate an "action", including title and icon, that can be attached to a Notification. + * @hide + */ + private static class Action implements Parcelable { + public int icon; + public CharSequence title; + public PendingIntent actionIntent; + @SuppressWarnings("unused") + public Action() { } + private Action(Parcel in) { + icon = in.readInt(); + title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); + if (in.readInt() == 1) { + actionIntent = PendingIntent.CREATOR.createFromParcel(in); + } + } + public Action(int icon_, CharSequence title_, PendingIntent intent_) { + this.icon = icon_; + this.title = title_; + this.actionIntent = intent_; + } + @Override + public Action clone() { + return new Action( + this.icon, + this.title.toString(), + this.actionIntent // safe to alias + ); + } + @Override + public int describeContents() { + return 0; + } + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeInt(icon); + TextUtils.writeToParcel(title, out, flags); + if (actionIntent != null) { + out.writeInt(1); + actionIntent.writeToParcel(out, flags); + } else { + out.writeInt(0); + } + } + public static final Parcelable.Creator CREATOR + = new Parcelable.Creator() { + public Action createFromParcel(Parcel in) { + return new Action(in); + } + public Action[] newArray(int size) { + return new Action[size]; + } + }; + } + + private Action[] actions; + /** * Constructs a Notification object with default values. * You might want to consider using {@link Builder} instead. @@ -506,12 +573,17 @@ public class Notification implements Parcelable } priority = parcel.readInt(); - + kind = parcel.createStringArray(); // may set kind to null if (parcel.readInt() != 0) { extras = parcel.readBundle(); } + + actions = parcel.createTypedArray(Action.CREATOR); + if (parcel.readInt() != 0) { + intruderView = RemoteViews.CREATOR.createFromParcel(parcel); + } } @Override @@ -571,6 +643,14 @@ public class Notification implements Parcelable } + that.actions = new Action[this.actions.length]; + for(int i=0; i 1) sb.append("s"); + } + sb.append(")"); return sb.toString(); } @@ -821,6 +917,7 @@ public class Notification implements Parcelable private ArrayList mKindList = new ArrayList(1); private Bundle mExtras; private int mPriority; + private ArrayList mActions = new ArrayList(3); /** * Constructs a new Builder with the defaults: @@ -1203,6 +1300,19 @@ public class Notification implements Parcelable return this; } + /** + * Add an action to this notification. Actions are typically displayed by + * the system as a button adjacent to the notification content. + * + * @param icon Resource ID of a drawable that represents the action. + * @param title Text describing the action. + * @param intent PendingIntent to be fired when the action is invoked. + */ + public Builder addAction(int icon, CharSequence title, PendingIntent intent) { + mActions.add(new Action(icon, title, intent)); + return this; + } + private void setFlag(int mask, boolean value) { if (value) { mFlags |= mask; @@ -1284,6 +1394,44 @@ public class Notification implements Parcelable } } + private RemoteViews makeIntruderView() { + RemoteViews intruderView = new RemoteViews(mContext.getPackageName(), + R.layout.notification_intruder_content); + if (mLargeIcon != null) { + intruderView.setImageViewBitmap(R.id.icon, mLargeIcon); + intruderView.setViewVisibility(R.id.icon, View.VISIBLE); + } else if (mSmallIcon != 0) { + intruderView.setImageViewResource(R.id.icon, mSmallIcon); + intruderView.setViewVisibility(R.id.icon, View.VISIBLE); + } else { + intruderView.setViewVisibility(R.id.icon, View.GONE); + } + if (mContentTitle != null) { + intruderView.setTextViewText(R.id.title, mContentTitle); + } + if (mContentText != null) { + intruderView.setTextViewText(R.id.text, mContentText); + } + if (mActions.size() > 0) { + intruderView.setViewVisibility(R.id.actions, View.VISIBLE); + int N = mActions.size(); + if (N>3) N=3; + final int[] BUTTONS = { R.id.action0, R.id.action1, R.id.action2 }; + for (int i=0; i 0) { + n.actions = new Action[mActions.size()]; + mActions.toArray(n.actions); + } return n; } } diff --git a/core/res/res/layout/notification_intruder_content.xml b/core/res/res/layout/notification_intruder_content.xml new file mode 100644 index 0000000000000..61be5f5a63127 --- /dev/null +++ b/core/res/res/layout/notification_intruder_content.xml @@ -0,0 +1,69 @@ + + + + + + + + + + + + diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml index ea1a70a4d477c..047e6ed1c526f 100644 --- a/core/res/res/values/public.xml +++ b/core/res/res/values/public.xml @@ -194,6 +194,10 @@ + + + + @@ -1062,6 +1066,7 @@ +