diff --git a/api/current.txt b/api/current.txt index 2b6481c654845..c270f94f40f5f 100644 --- a/api/current.txt +++ b/api/current.txt @@ -5136,6 +5136,11 @@ package android.app { ctor public Notification.DecoratedCustomViewStyle(android.app.Notification.Builder); } + public static class Notification.DecoratedMediaCustomViewStyle extends android.app.Notification.MediaStyle { + ctor public Notification.DecoratedMediaCustomViewStyle(); + ctor public Notification.DecoratedMediaCustomViewStyle(android.app.Notification.Builder); + } + public static abstract interface Notification.Extender { method public abstract android.app.Notification.Builder extend(android.app.Notification.Builder); } diff --git a/api/system-current.txt b/api/system-current.txt index 5a234672a0bea..c9b519ad5fee6 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -5268,6 +5268,11 @@ package android.app { ctor public Notification.DecoratedCustomViewStyle(android.app.Notification.Builder); } + public static class Notification.DecoratedMediaCustomViewStyle extends android.app.Notification.MediaStyle { + ctor public Notification.DecoratedMediaCustomViewStyle(); + ctor public Notification.DecoratedMediaCustomViewStyle(android.app.Notification.Builder); + } + public static abstract interface Notification.Extender { method public abstract android.app.Notification.Builder extend(android.app.Notification.Builder); } diff --git a/api/test-current.txt b/api/test-current.txt index ed366df36a0c0..240cb4d37df58 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -5136,6 +5136,11 @@ package android.app { ctor public Notification.DecoratedCustomViewStyle(android.app.Notification.Builder); } + public static class Notification.DecoratedMediaCustomViewStyle extends android.app.Notification.MediaStyle { + ctor public Notification.DecoratedMediaCustomViewStyle(); + ctor public Notification.DecoratedMediaCustomViewStyle(android.app.Notification.Builder); + } + public static abstract interface Notification.Extender { method public abstract android.app.Notification.Builder extend(android.app.Notification.Builder); } diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index c143d9fb48ac1..402c112fdb636 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -3460,7 +3460,7 @@ public class Notification implements Parcelable private static Class getNotificationStyleClass(String templateClass) { Class[] classes = new Class[] { BigTextStyle.class, BigPictureStyle.class, InboxStyle.class, MediaStyle.class, - DecoratedCustomViewStyle.class }; + DecoratedCustomViewStyle.class, DecoratedMediaCustomViewStyle.class }; for (Class innerClass : classes) { if (templateClass.equals(innerClass.getName())) { return innerClass; @@ -4522,6 +4522,103 @@ public class Notification implements Parcelable } } + /** + * Notification style for media custom views that are decorated by the system + * + *

Instead of providing a media 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. + * + *

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: + *

+     * Notification noti = new Notification.Builder()
+     *     .setSmallIcon(R.drawable.ic_stat_player)
+     *     .setLargeIcon(albumArtBitmap))
+     *     .setCustomContentView(contentView);
+     *     .setStyle(new Notification.DecoratedMediaCustomViewStyle()
+     *          .setMediaSession(mySession))
+     *     .build();
+     * 
+ * + * @see android.app.Notification.DecoratedCustomViewStyle + * @see android.app.Notification.MediaStyle + */ + public static class DecoratedMediaCustomViewStyle extends MediaStyle { + + public DecoratedMediaCustomViewStyle() { + } + + public DecoratedMediaCustomViewStyle(Builder builder) { + setBuilder(builder); + } + + /** + * @hide + */ + public boolean displayCustomViewInline() { + return true; + } + + /** + * @hide + */ + @Override + public RemoteViews makeContentView() { + RemoteViews remoteViews = super.makeContentView(); + return buildIntoRemoteView(remoteViews, R.id.notification_content_container, + mBuilder.mN.contentView); + } + + /** + * @hide + */ + @Override + public RemoteViews makeBigContentView() { + RemoteViews customRemoteView = mBuilder.mN.bigContentView != null + ? mBuilder.mN.bigContentView + : mBuilder.mN.contentView; + return makeBigContentViewWithCustomContent(customRemoteView); + } + + private RemoteViews makeBigContentViewWithCustomContent(RemoteViews customRemoteView) { + RemoteViews remoteViews = super.makeBigContentView(); + if (remoteViews != null) { + return buildIntoRemoteView(remoteViews, R.id.notification_main_column, + customRemoteView); + } else if (customRemoteView != mBuilder.mN.contentView){ + remoteViews = super.makeContentView(); + return buildIntoRemoteView(remoteViews, R.id.notification_content_container, + customRemoteView); + } else { + return null; + } + } + + /** + * @hide + */ + @Override + public RemoteViews makeHeadsUpContentView() { + RemoteViews customRemoteView = mBuilder.mN.headsUpContentView != null + ? mBuilder.mN.headsUpContentView + : mBuilder.mN.contentView; + return makeBigContentViewWithCustomContent(customRemoteView); + } + + private RemoteViews buildIntoRemoteView(RemoteViews remoteViews, int id, + RemoteViews customContent) { + remoteViews.removeAllViews(id); + remoteViews.addView(id, customContent); + return remoteViews; + } + } + // When adding a new Style subclass here, don't forget to update // Builder.getNotificationStyleClass. diff --git a/core/res/res/layout/notification_template_material_media.xml b/core/res/res/layout/notification_template_material_media.xml index aea9b44622c4f..cda063627dc5d 100644 --- a/core/res/res/layout/notification_template_material_media.xml +++ b/core/res/res/layout/notification_template_material_media.xml @@ -36,6 +36,7 @@ android:tag="media" > - + +