Move DecoratedCustomViewStyle specific code from ImplBase
Code specific to DecoratedCustomViewStyle can be moved from
NotificationCompatImplBase into DecoratedCustomViewStyle itself.
Test: Manual inspection
BUG: 33042051
Change-Id: I19311bb8358a7ad864209cbfd38706debf68b2fa
diff --git a/v7/appcompat/src/android/support/v7/app/NotificationCompat.java b/v7/appcompat/src/android/support/v7/app/NotificationCompat.java
index 29b5340..981b1c0 100644
--- a/v7/appcompat/src/android/support/v7/app/NotificationCompat.java
+++ b/v7/appcompat/src/android/support/v7/app/NotificationCompat.java
@@ -32,6 +32,7 @@
import android.support.v4.app.NotificationBuilderWithBuilderAccessor;
import android.support.v4.media.session.MediaSessionCompat;
import android.support.v7.appcompat.R;
+import android.view.View;
import android.widget.RemoteViews;
/**
@@ -301,6 +302,8 @@
*/
public static class DecoratedCustomViewStyle extends Style {
+ private static final int MAX_ACTION_BUTTONS = 3;
+
public DecoratedCustomViewStyle() {
}
@@ -373,17 +376,50 @@
}
private RemoteViews createRemoteViews(RemoteViews innerView, boolean showActions) {
- RemoteViews remoteViews = NotificationCompatImplBase.applyStandardTemplateWithActions(
+ RemoteViews remoteViews = NotificationCompatImplBase.applyStandardTemplate(
mBuilder.mContext, mBuilder.mContentTitle, mBuilder.mContentText,
mBuilder.mContentInfo, mBuilder.mNumber, mBuilder.mNotification.icon,
mBuilder.mLargeIcon, mBuilder.mSubText, mBuilder.mUseChronometer,
mBuilder.getWhenIfShowing(), mBuilder.getPriority(), mBuilder.getColor(),
- R.layout.notification_template_custom_big,
- false /* fitIn1U */, showActions ? mBuilder.mActions : null);
+ R.layout.notification_template_custom_big, false /* fitIn1U */);
+ remoteViews.removeAllViews(R.id.actions);
+ boolean actionsVisible = false;
+ if (showActions && mBuilder.mActions != null) {
+ int numActions = Math.max(mBuilder.mActions.size(), MAX_ACTION_BUTTONS);
+ if (numActions > 0) {
+ actionsVisible = true;
+ for (int i = 0; i < numActions; i++) {
+ final RemoteViews button = generateActionButton(mBuilder.mActions.get(i));
+ remoteViews.addView(R.id.actions, button);
+ }
+ }
+ }
+ int actionVisibility = actionsVisible ? View.VISIBLE : View.GONE;
+ remoteViews.setViewVisibility(R.id.actions, actionVisibility);
+ remoteViews.setViewVisibility(R.id.action_divider, actionVisibility);
NotificationCompatImplBase.buildIntoRemoteViews(mBuilder.mContext,
remoteViews, innerView);
return remoteViews;
}
+
+ private RemoteViews generateActionButton(NotificationCompat.Action action) {
+ final boolean tombstone = (action.actionIntent == null);
+ RemoteViews button = new RemoteViews(mBuilder.mContext.getPackageName(),
+ tombstone ? R.layout.notification_action_tombstone
+ : R.layout.notification_action);
+ button.setImageViewBitmap(R.id.action_image,
+ NotificationCompatImplBase.createColoredBitmap(mBuilder.mContext,
+ action.getIcon(), mBuilder.mContext.getResources()
+ .getColor(R.color.notification_action_color_filter)));
+ button.setTextViewText(R.id.action_text, action.title);
+ if (!tombstone) {
+ button.setOnClickPendingIntent(R.id.action_container, action.actionIntent);
+ }
+ if (Build.VERSION.SDK_INT >= 15) {
+ button.setContentDescription(R.id.action_container, action.title);
+ }
+ return button;
+ }
}
/**
diff --git a/v7/appcompat/src/android/support/v7/app/NotificationCompatImplBase.java b/v7/appcompat/src/android/support/v7/app/NotificationCompatImplBase.java
index 8beca23..7389f8f 100644
--- a/v7/appcompat/src/android/support/v7/app/NotificationCompatImplBase.java
+++ b/v7/appcompat/src/android/support/v7/app/NotificationCompatImplBase.java
@@ -36,7 +36,6 @@
import android.widget.RemoteViews;
import java.text.NumberFormat;
-import java.util.ArrayList;
import java.util.List;
/**
@@ -48,7 +47,6 @@
static final int MAX_MEDIA_BUTTONS_IN_COMPACT = 3;
static final int MAX_MEDIA_BUTTONS = 5;
- private static final int MAX_ACTION_BUTTONS = 3;
@RequiresApi(11)
static <T extends NotificationCompatBase.Action> RemoteViews generateContentViewMedia(
@@ -155,53 +153,7 @@
}
}
- public static RemoteViews applyStandardTemplateWithActions(Context context,
- CharSequence contentTitle, CharSequence contentText, CharSequence contentInfo,
- int number, int smallIcon, Bitmap largeIcon, CharSequence subText,
- boolean useChronometer, long when, int priority, int color, int resId, boolean fitIn1U,
- ArrayList<NotificationCompat.Action> actions) {
- RemoteViews remoteViews = applyStandardTemplate(context, contentTitle, contentText,
- contentInfo, number, smallIcon, largeIcon, subText, useChronometer, when, priority,
- color, resId, fitIn1U);
- remoteViews.removeAllViews(R.id.actions);
- boolean actionsVisible = false;
- if (actions != null) {
- int N = actions.size();
- if (N > 0) {
- actionsVisible = true;
- if (N > MAX_ACTION_BUTTONS) N = MAX_ACTION_BUTTONS;
- for (int i = 0; i < N; i++) {
- final RemoteViews button = generateActionButton(context, actions.get(i));
- remoteViews.addView(R.id.actions, button);
- }
- }
- }
- int actionVisibility = actionsVisible ? View.VISIBLE : View.GONE;
- remoteViews.setViewVisibility(R.id.actions, actionVisibility);
- remoteViews.setViewVisibility(R.id.action_divider, actionVisibility);
- return remoteViews;
- }
-
- private static RemoteViews generateActionButton(Context context,
- NotificationCompat.Action action) {
- final boolean tombstone = (action.actionIntent == null);
- RemoteViews button = new RemoteViews(context.getPackageName(),
- tombstone ? getActionTombstoneLayoutResource()
- : getActionLayoutResource());
- button.setImageViewBitmap(R.id.action_image,
- createColoredBitmap(context, action.getIcon(),
- context.getResources().getColor(R.color.notification_action_color_filter)));
- button.setTextViewText(R.id.action_text, action.title);
- if (!tombstone) {
- button.setOnClickPendingIntent(R.id.action_container, action.actionIntent);
- }
- if (Build.VERSION.SDK_INT >= 15) {
- button.setContentDescription(R.id.action_container, action.title);
- }
- return button;
- }
-
- private static Bitmap createColoredBitmap(Context context, int iconId, int color) {
+ static Bitmap createColoredBitmap(Context context, int iconId, int color) {
return createColoredBitmap(context, iconId, color, 0);
}
@@ -220,14 +172,6 @@
return resultBitmap;
}
- private static int getActionLayoutResource() {
- return R.layout.notification_action;
- }
-
- private static int getActionTombstoneLayoutResource() {
- return R.layout.notification_action_tombstone;
- }
-
public static RemoteViews applyStandardTemplate(Context context,
CharSequence contentTitle, CharSequence contentText, CharSequence contentInfo,
int number, int smallIcon, Bitmap largeIcon, CharSequence subText,