Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 71964645 authored by Chris Wren's avatar Chris Wren Committed by Android (Google) Code Review
Browse files

Merge "Allow the Notification.Builder to carry around a Style to apply at build" into jb-dev

parents 115f48a2 fbd96ba9
Loading
Loading
Loading
Loading
+15 −6
Original line number Diff line number Diff line
@@ -3748,23 +3748,24 @@ package android.app {
    field public long when;
  }
  public static class Notification.BigPictureStyle {
  public static class Notification.BigPictureStyle extends android.app.Notification.Style {
    ctor public Notification.BigPictureStyle();
    ctor public Notification.BigPictureStyle(android.app.Notification.Builder);
    method public android.app.Notification.BigPictureStyle bigPicture(android.graphics.Bitmap);
    method public android.app.Notification build();
  }
  public static class Notification.BigTextStyle {
  public static class Notification.BigTextStyle extends android.app.Notification.Style {
    ctor public Notification.BigTextStyle();
    ctor public Notification.BigTextStyle(android.app.Notification.Builder);
    method public android.app.Notification.BigTextStyle bigText(java.lang.CharSequence);
    method public android.app.Notification build();
  }
  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 build();
    method public deprecated android.app.Notification getNotification();
    method public android.app.Notification.Builder setAutoCancel(boolean);
    method public android.app.Notification.Builder setContent(android.widget.RemoteViews);
    method public android.app.Notification.Builder setContentInfo(java.lang.CharSequence);
@@ -3785,6 +3786,7 @@ package android.app {
    method public android.app.Notification.Builder setSmallIcon(int, int);
    method public android.app.Notification.Builder setSound(android.net.Uri);
    method public android.app.Notification.Builder setSound(android.net.Uri, int);
    method public android.app.Notification.Builder setStyle(android.app.Notification.Style);
    method public android.app.Notification.Builder setSubText(java.lang.CharSequence);
    method public android.app.Notification.Builder setTicker(java.lang.CharSequence);
    method public android.app.Notification.Builder setTicker(java.lang.CharSequence, android.widget.RemoteViews);
@@ -3793,10 +3795,17 @@ package android.app {
    method public android.app.Notification.Builder setWhen(long);
  }
  public static class Notification.InboxStyle {
  public static class Notification.InboxStyle extends android.app.Notification.Style {
    ctor public Notification.InboxStyle();
    ctor public Notification.InboxStyle(android.app.Notification.Builder);
    method public android.app.Notification.InboxStyle addLine(java.lang.CharSequence);
  }
  public static class Notification.Style {
    ctor public Notification.Style();
    method public android.app.Notification build();
    method public void setBuilder(android.app.Notification.Builder);
    field protected android.app.Notification.Builder mBuilder;
  }
  public class NotificationManager {
+93 −18
Original line number Diff line number Diff line
@@ -888,7 +888,7 @@ public class Notification implements Parcelable
     *         .setContentText(subject)
     *         .setSmallIcon(R.drawable.new_mail)
     *         .setLargeIcon(aBitmap)
     *         .getNotification();
     *         .build();
     * </pre>
     */
    public static class Builder {
@@ -925,6 +925,7 @@ public class Notification implements Parcelable
        private int mPriority;
        private ArrayList<Action> mActions = new ArrayList<Action>(3);
        private boolean mUseChronometer;
        private Style mStyle;

        /**
         * Constructs a new Builder with the defaults:
@@ -1305,7 +1306,7 @@ public class Notification implements Parcelable
         * Add metadata to this notification.
         *
         * A reference to the Bundle is held for the lifetime of this Builder, and the Bundle's
         * current contents are copied into the Notification each time {@link #getNotification()} is
         * current contents are copied into the Notification each time {@link #build()} is
         * called.
         *
         * @see Notification#extras
@@ -1329,6 +1330,19 @@ public class Notification implements Parcelable
            return this;
        }

        /**
         * Add a rich notification style to be applied at build time.
         *
         * @param style Object responsible for modifying the notification style.
         */
        public Builder setStyle(Style style) {
            if (mStyle != style) {
                mStyle = style;
                mStyle.setBuilder(this);
            }
            return this;
        }

        private void setFlag(int mask, boolean value) {
            if (value) {
                mFlags |= mask;
@@ -1464,10 +1478,9 @@ public class Notification implements Parcelable
        }

        /**
         * Combine all of the options that have been set and return a new {@link Notification}
         * object.
         * Apply the unstyled operations and return a new {@link Notification} object.
         */
        public Notification getNotification() {
        private Notification buildUnstyled() {
            Notification n = new Notification();
            n.when = mWhen;
            n.icon = mSmallIcon;
@@ -1509,6 +1522,49 @@ public class Notification implements Parcelable
            }
            return n;
        }

        /**
         * @deprecated Use {@link #build()} instead.
         */
        @Deprecated
        public Notification getNotification() {
            return build();
        }

        /**
         * Combine all of the options that have been set and return a new {@link Notification}
         * object.
         */
        public Notification build() {
            if (mStyle != null) {
                return mStyle.build();
            } else {
                return buildUnstyled();
            }
        }
    }


    /**
     * An object that can apply a rich notification style to a {@link Notification.Builder}
     * object.
     */
    public static class Style {
        protected Builder mBuilder;

        public void setBuilder(Builder builder) {
            if (mBuilder != builder) {
                mBuilder = builder;
                mBuilder.setStyle(this);
            }
        }

        public Notification build() {
            if (mBuilder == null) {
                throw new IllegalArgumentException("Style requires a valid Builder object");
            }
            return mBuilder.buildUnstyled();
        }
    }

    /**
@@ -1528,12 +1584,14 @@ public class Notification implements Parcelable
     * 
     * @see Notification#bigContentView
     */
    public static class BigPictureStyle {
        private Builder mBuilder;
    public static class BigPictureStyle extends Style {
        private Bitmap mPicture;

        public BigPictureStyle() {
        }

        public BigPictureStyle(Builder builder) {
            mBuilder = builder;
            setBuilder(builder);
        }

        public BigPictureStyle bigPicture(Bitmap b) {
@@ -1549,8 +1607,12 @@ public class Notification implements Parcelable
            return contentView;
        }

        @Override
        public Notification build() {
            Notification wip = mBuilder.getNotification();
            if (mBuilder == null) {
                throw new IllegalArgumentException("Style requires a valid Builder object");
            }
            Notification wip = mBuilder.buildUnstyled();
            wip.bigContentView = makeBigContentView();
            return wip;
        }
@@ -1573,12 +1635,14 @@ public class Notification implements Parcelable
     * 
     * @see Notification#bigContentView
     */
    public static class BigTextStyle {
        private Builder mBuilder;
    public static class BigTextStyle extends Style {
        private CharSequence mBigText;

        public BigTextStyle() {
        }

        public BigTextStyle(Builder builder) {
            mBuilder = builder;
            setBuilder(builder);
        }

        public BigTextStyle bigText(CharSequence cs) {
@@ -1596,8 +1660,13 @@ public class Notification implements Parcelable
            return contentView;
        }

        @Override
        public Notification build() {
            Notification wip = mBuilder.getNotification();
            if (mBuilder == null) {
                throw new IllegalArgumentException("Style requires a valid Builder object");
            }
            mBuilder.mSubText = null;
            Notification wip = mBuilder.buildUnstyled();
            wip.bigContentView = makeBigContentView();
            return wip;
        }
@@ -1608,7 +1677,7 @@ public class Notification implements Parcelable
     * 
     * This class is a "rebuilder": It consumes a Builder object and modifies its behavior, like so:
     * <pre class="prettyprint">
     * Notification noti = new Notification.DigestStyle(
     * Notification noti = new Notification.InboxStyle(
     *      new Notification.Builder()
     *         .setContentTitle(&quot;New mail from &quot; + sender.toString())
     *         .setContentText(subject)
@@ -1621,12 +1690,14 @@ public class Notification implements Parcelable
     * 
     * @see Notification#bigContentView
     */
    public static class InboxStyle {
        private Builder mBuilder;
    public static class InboxStyle extends Style {
        private ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>(5);

        public InboxStyle() {
        }

        public InboxStyle(Builder builder) {
            mBuilder = builder;
            setBuilder(builder);
        }

        public InboxStyle addLine(CharSequence cs) {
@@ -1652,8 +1723,12 @@ public class Notification implements Parcelable
            return contentView;
        }

        @Override
        public Notification build() {
            Notification wip = mBuilder.getNotification();
            if (mBuilder == null) {
                throw new IllegalArgumentException("Style requires a valid Builder object");
            }
            Notification wip = mBuilder.buildUnstyled();
            wip.bigContentView = makeBigContentView();
            return wip;
        }