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

Commit 3c306d8a authored by Selim Cinek's avatar Selim Cinek Committed by Android (Google) Code Review
Browse files

Merge "Added the possibility to show custom notifications decorated." into nyc-dev

parents 82c9dc95 593610c2
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -5131,6 +5131,11 @@ package android.app {
    method public android.app.PendingIntent getReplyPendingIntent();
  }
  public static class Notification.DecoratedCustomViewStyle extends android.app.Notification.Style {
    ctor public Notification.DecoratedCustomViewStyle();
    ctor public Notification.DecoratedCustomViewStyle(android.app.Notification.Builder);
  }
  public static abstract interface Notification.Extender {
    method public abstract android.app.Notification.Builder extend(android.app.Notification.Builder);
  }
+5 −0
Original line number Diff line number Diff line
@@ -5263,6 +5263,11 @@ package android.app {
    method public android.app.PendingIntent getReplyPendingIntent();
  }
  public static class Notification.DecoratedCustomViewStyle extends android.app.Notification.Style {
    ctor public Notification.DecoratedCustomViewStyle();
    ctor public Notification.DecoratedCustomViewStyle(android.app.Notification.Builder);
  }
  public static abstract interface Notification.Extender {
    method public abstract android.app.Notification.Builder extend(android.app.Notification.Builder);
  }
+5 −0
Original line number Diff line number Diff line
@@ -5131,6 +5131,11 @@ package android.app {
    method public android.app.PendingIntent getReplyPendingIntent();
  }
  public static class Notification.DecoratedCustomViewStyle extends android.app.Notification.Style {
    ctor public Notification.DecoratedCustomViewStyle();
    ctor public Notification.DecoratedCustomViewStyle(android.app.Notification.Builder);
  }
  public static abstract interface Notification.Extender {
    method public abstract android.app.Notification.Builder extend(android.app.Notification.Builder);
  }
+125 −5
Original line number Diff line number Diff line
@@ -3229,7 +3229,7 @@ public class Notification implements Parcelable
         *   3. Standard template view
         */
        public RemoteViews makeContentView() {
            if (mN.contentView != null) {
            if (mN.contentView != null && (mStyle == null || !mStyle.displayCustomViewInline())) {
                return mN.contentView;
            } else if (mStyle != null) {
                final RemoteViews styleView = mStyle.makeContentView();
@@ -3245,7 +3245,8 @@ public class Notification implements Parcelable
         */
        public RemoteViews makeBigContentView() {
            RemoteViews result = null;
            if (mN.bigContentView != null) {
            if (mN.bigContentView != null
                    && (mStyle == null || !mStyle.displayCustomViewInline())) {
                return mN.bigContentView;
            } else if (mStyle != null) {
                result = mStyle.makeBigContentView();
@@ -3286,7 +3287,8 @@ public class Notification implements Parcelable
         * Construct a RemoteViews for the final heads-up notification layout.
         */
        public RemoteViews makeHeadsUpContentView() {
            if (mN.headsUpContentView != null) {
            if (mN.headsUpContentView != null
                    && (mStyle == null ||  !mStyle.displayCustomViewInline())) {
                return mN.headsUpContentView;
            } else if (mStyle != null) {
                    final RemoteViews styleView = mStyle.makeHeadsUpContentView();
@@ -3448,7 +3450,8 @@ public class Notification implements Parcelable

        private static Class<? extends Style> getNotificationStyleClass(String templateClass) {
            Class<? extends Style>[] classes = new Class[] {
                    BigTextStyle.class, BigPictureStyle.class, InboxStyle.class, MediaStyle.class};
                    BigTextStyle.class, BigPictureStyle.class, InboxStyle.class, MediaStyle.class,
                    DecoratedCustomViewStyle.class };
            for (Class<? extends Style> innerClass : classes) {
                if (templateClass.equals(innerClass.getName())) {
                    return innerClass;
@@ -3753,6 +3756,14 @@ public class Notification implements Parcelable
        public boolean hasSummaryInHeader() {
            return true;
        }

        /**
         * @hide
         * @return Whether custom content views are displayed inline in the style
         */
        public boolean displayCustomViewInline() {
            return false;
        }
    }

    /**
@@ -4389,6 +4400,115 @@ public class Notification implements Parcelable
        }
    }

    /**
     * Notification style for custom views that are decorated by the system
     *
     * <p>Instead of providing a notification that is completely custom, a developer can set this
     * style and still obtain system decorations like the notification header with the expand
     * affordance and actions.
     *
     * <p>Use {@link android.app.Notification.Builder#setCustomContentView(RemoteViews)},
     * {@link android.app.Notification.Builder#setCustomBigContentView(RemoteViews)} and
     * {@link android.app.Notification.Builder#setCustomHeadsUpContentView(RemoteViews)} to set the
     * corresponding custom views to display.
     *
     * To use this style with your Notification, feed it to
     * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so:
     * <pre class="prettyprint">
     * Notification noti = new Notification.Builder()
     *     .setSmallIcon(R.drawable.ic_stat_player)
     *     .setLargeIcon(albumArtBitmap))
     *     .setCustomContentView(contentView);
     *     .setStyle(<b>new Notification.DecoratedCustomViewStyle()</b>)
     *     .build();
     * </pre>
     */
    public static class DecoratedCustomViewStyle extends Style {

        public DecoratedCustomViewStyle() {
        }

        public DecoratedCustomViewStyle(Builder builder) {
            setBuilder(builder);
        }

        /**
         * @hide
         */
        public boolean displayCustomViewInline() {
            return true;
        }

        /**
         * @hide
         */
        @Override
        public RemoteViews makeContentView() {
            return makeStandardTemplateWithCustomContent(mBuilder.mN.contentView);
        }

        /**
         * @hide
         */
        @Override
        public RemoteViews makeBigContentView() {
            return makeDecoratedBigContentView();
        }

        /**
         * @hide
         */
        @Override
        public RemoteViews makeHeadsUpContentView() {
            return makeDecoratedHeadsUpContentView();
        }

        /**
         * @hide
         */
        private RemoteViews makeDecoratedHeadsUpContentView() {
            RemoteViews headsUpContentView = mBuilder.mN.headsUpContentView == null
                    ? mBuilder.mN.contentView
                    : mBuilder.mN.headsUpContentView;
            if (mBuilder.mActions.size() == 0) {
               return makeStandardTemplateWithCustomContent(headsUpContentView);
            }
            RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions(
                        mBuilder.getBigBaseLayoutResource());
            remoteViews.removeAllViews(R.id.notification_main_column);
            remoteViews.addView(R.id.notification_main_column, headsUpContentView);
            return remoteViews;
        }

        /**
         * @hide
         */
        private RemoteViews makeStandardTemplateWithCustomContent(RemoteViews customContent) {
            RemoteViews remoteViews = mBuilder.applyStandardTemplate(
                    mBuilder.getBaseLayoutResource());
            remoteViews.removeAllViews(R.id.notification_main_column);
            remoteViews.addView(R.id.notification_main_column, customContent);
            return remoteViews;
        }

        /**
         * @hide
         */
        private RemoteViews makeDecoratedBigContentView() {
            RemoteViews bigContentView = mBuilder.mN.bigContentView == null
                    ? mBuilder.mN.contentView
                    : mBuilder.mN.bigContentView;
            if (mBuilder.mActions.size() == 0) {
                return makeStandardTemplateWithCustomContent(bigContentView);
            }
            RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions(
                    mBuilder.getBigBaseLayoutResource());
            remoteViews.removeAllViews(R.id.notification_main_column);
            remoteViews.addView(R.id.notification_main_column, bigContentView);
            return remoteViews;
        }
    }

    // When adding a new Style subclass here, don't forget to update
    // Builder.getNotificationStyleClass.