Move MediaStyle big content view code from ImplBase
Move v7 MediaStyle and DecoratedMediaCustomViewStyle
code from NotificationCompatImplBase into the styles
themselves.
Test: Manual inspection
BUG: 33042051
Change-Id: I825b6644f676c4aaa097936eed0a847dc0fee992
diff --git a/v7/appcompat/src/android/support/v7/app/NotificationCompat.java b/v7/appcompat/src/android/support/v7/app/NotificationCompat.java
index c4b3d4f..450248c 100644
--- a/v7/appcompat/src/android/support/v7/app/NotificationCompat.java
+++ b/v7/appcompat/src/android/support/v7/app/NotificationCompat.java
@@ -127,6 +127,7 @@
public static class MediaStyle extends android.support.v4.app.NotificationCompat.Style {
private static final int MAX_MEDIA_BUTTONS_IN_COMPACT = 3;
+ private static final int MAX_MEDIA_BUTTONS = 5;
int[] mActionsToShowInCompact = null;
MediaSessionCompat.Token mToken;
@@ -309,17 +310,41 @@
// No custom content view required
return null;
}
- return generateBigContentView(false);
+ return generateBigContentView();
}
- RemoteViews generateBigContentView(boolean isDecorated) {
- return NotificationCompatImplBase.generateMediaBigView(
+ RemoteViews generateBigContentView() {
+ final int actionCount = Math.min(mBuilder.mActions.size(), MAX_MEDIA_BUTTONS);
+ RemoteViews big = NotificationCompatImplBase.applyStandardTemplate(
mBuilder.mContext, mBuilder.mContentTitle, mBuilder.mContentText,
- mBuilder.mContentInfo, mBuilder.mNumber, mBuilder.mLargeIcon,
- mBuilder.mSubText, mBuilder.mUseChronometer,
- mBuilder.getWhenIfShowing(), mBuilder.getPriority(), 0,
- mBuilder.mActions, mShowCancelButton, mCancelButtonIntent,
- isDecorated);
+ mBuilder.mContentInfo, mBuilder.mNumber, 0 /* smallIcon */,
+ mBuilder.mLargeIcon, mBuilder.mSubText, mBuilder.mUseChronometer,
+ mBuilder.getWhenIfShowing(), mBuilder.getPriority(),
+ 0 /* color is unused on media */,
+ getBigContentViewLayoutResource(actionCount), false /* fitIn1U */);
+
+ big.removeAllViews(R.id.media_actions);
+ if (actionCount > 0) {
+ for (int i = 0; i < actionCount; i++) {
+ final RemoteViews button = generateMediaActionButton(mBuilder.mActions.get(i));
+ big.addView(R.id.media_actions, button);
+ }
+ }
+ if (mShowCancelButton) {
+ big.setViewVisibility(R.id.cancel_action, View.VISIBLE);
+ big.setInt(R.id.cancel_action, "setAlpha", mBuilder.mContext
+ .getResources().getInteger(R.integer.cancel_button_image_alpha));
+ big.setOnClickPendingIntent(R.id.cancel_action, mCancelButtonIntent);
+ } else {
+ big.setViewVisibility(R.id.cancel_action, View.GONE);
+ }
+ return big;
+ }
+
+ int getBigContentViewLayoutResource(int actionCount) {
+ return actionCount <= 3
+ ? R.layout.notification_template_big_media_narrow
+ : R.layout.notification_template_big_media;
}
}
@@ -589,7 +614,7 @@
// No expandable notification
return null;
}
- RemoteViews bigContentView = generateBigContentView(true);
+ RemoteViews bigContentView = generateBigContentView();
NotificationCompatImplBase.buildIntoRemoteViews(mBuilder.mContext,
bigContentView,
innerView);
@@ -599,6 +624,13 @@
return bigContentView;
}
+ @Override
+ int getBigContentViewLayoutResource(int actionCount) {
+ return actionCount <= 3
+ ? R.layout.notification_template_big_media_narrow_custom
+ : R.layout.notification_template_big_media_custom;
+ }
+
/**
* @hide
*/
@@ -616,7 +648,7 @@
// No expandable notification
return null;
}
- RemoteViews headsUpContentView = generateBigContentView(true);
+ RemoteViews headsUpContentView = generateBigContentView();
NotificationCompatImplBase.buildIntoRemoteViews(mBuilder.mContext,
headsUpContentView,
innerView);
diff --git a/v7/appcompat/src/android/support/v7/app/NotificationCompatImplBase.java b/v7/appcompat/src/android/support/v7/app/NotificationCompatImplBase.java
index f22e6d4..8df0315 100644
--- a/v7/appcompat/src/android/support/v7/app/NotificationCompatImplBase.java
+++ b/v7/appcompat/src/android/support/v7/app/NotificationCompatImplBase.java
@@ -16,7 +16,6 @@
package android.support.v7.app;
-import android.app.PendingIntent;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
@@ -29,14 +28,12 @@
import android.os.SystemClock;
import android.support.annotation.RequiresApi;
import android.support.v4.app.NotificationCompat;
-import android.support.v4.app.NotificationCompatBase;
import android.support.v7.appcompat.R;
import android.util.TypedValue;
import android.view.View;
import android.widget.RemoteViews;
import java.text.NumberFormat;
-import java.util.List;
/**
* Helper class to generate MediaStyle notifications for pre-Lollipop platforms. Overrides
@@ -45,68 +42,6 @@
@RequiresApi(9)
class NotificationCompatImplBase {
- static final int MAX_MEDIA_BUTTONS = 5;
-
- @RequiresApi(11)
- public static <T extends NotificationCompatBase.Action> RemoteViews generateMediaBigView(
- Context context, CharSequence contentTitle, CharSequence contentText,
- CharSequence contentInfo, int number, Bitmap largeIcon, CharSequence subText,
- boolean useChronometer, long when, int priority, int color, List<T> actions,
- boolean showCancelButton, PendingIntent cancelButtonIntent,
- boolean decoratedCustomView) {
- final int actionCount = Math.min(actions.size(), MAX_MEDIA_BUTTONS);
- RemoteViews big = applyStandardTemplate(context, contentTitle, contentText, contentInfo,
- number, 0 /* smallIcon */, largeIcon, subText, useChronometer, when, priority,
- color, /* fitIn1U */getBigMediaLayoutResource(decoratedCustomView, actionCount),
- false);
-
- big.removeAllViews(R.id.media_actions);
- if (actionCount > 0) {
- for (int i = 0; i < actionCount; i++) {
- final RemoteViews button = generateMediaActionButton(context, actions.get(i));
- big.addView(R.id.media_actions, button);
- }
- }
- if (showCancelButton) {
- big.setViewVisibility(R.id.cancel_action, View.VISIBLE);
- big.setInt(R.id.cancel_action, "setAlpha",
- context.getResources().getInteger(R.integer.cancel_button_image_alpha));
- big.setOnClickPendingIntent(R.id.cancel_action, cancelButtonIntent);
- } else {
- big.setViewVisibility(R.id.cancel_action, View.GONE);
- }
- return big;
- }
-
- @RequiresApi(11)
- private static RemoteViews generateMediaActionButton(Context context,
- NotificationCompatBase.Action action) {
- final boolean tombstone = (action.getActionIntent() == null);
- RemoteViews button = new RemoteViews(context.getPackageName(),
- R.layout.notification_media_action);
- button.setImageViewResource(R.id.action0, action.getIcon());
- if (!tombstone) {
- button.setOnClickPendingIntent(R.id.action0, action.getActionIntent());
- }
- if (Build.VERSION.SDK_INT >= 15) {
- button.setContentDescription(R.id.action0, action.getTitle());
- }
- return button;
- }
-
- @RequiresApi(11)
- private static int getBigMediaLayoutResource(boolean decoratedCustomView, int actionCount) {
- if (actionCount <= 3) {
- return decoratedCustomView
- ? R.layout.notification_template_big_media_narrow_custom
- : R.layout.notification_template_big_media_narrow;
- } else {
- return decoratedCustomView
- ? R.layout.notification_template_big_media_custom
- : R.layout.notification_template_big_media;
- }
- }
-
static Bitmap createColoredBitmap(Context context, int iconId, int color) {
return createColoredBitmap(context, iconId, color, 0);
}