244 lines
11 KiB
Java
244 lines
11 KiB
Java
package androidx.media.app;
|
|
|
|
import android.app.Notification;
|
|
import android.app.PendingIntent;
|
|
import android.media.session.MediaSession;
|
|
import android.os.Build;
|
|
import android.os.Bundle;
|
|
import android.os.Parcelable;
|
|
import android.support.v4.media.session.MediaSessionCompat;
|
|
import android.widget.RemoteViews;
|
|
import androidx.annotation.RequiresApi;
|
|
import androidx.annotation.RestrictTo;
|
|
import androidx.core.app.NotificationBuilderWithBuilderAccessor;
|
|
import androidx.core.app.NotificationCompat;
|
|
import androidx.media.R;
|
|
public class NotificationCompat {
|
|
|
|
public static class DecoratedMediaCustomViewStyle extends MediaStyle {
|
|
private void setBackgroundColor(RemoteViews remoteViews) {
|
|
remoteViews.setInt(R.id.status_bar_latest_event_content, "setBackgroundColor", this.mBuilder.getColor() != 0 ? this.mBuilder.getColor() : this.mBuilder.mContext.getResources().getColor(R.color.notification_material_background_media_default_color));
|
|
}
|
|
|
|
@Override // androidx.media.app.NotificationCompat.MediaStyle, androidx.core.app.NotificationCompat.Style
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY})
|
|
public void apply(NotificationBuilderWithBuilderAccessor notificationBuilderWithBuilderAccessor) {
|
|
if (Build.VERSION.SDK_INT >= 24) {
|
|
notificationBuilderWithBuilderAccessor.getBuilder().setStyle(fillInMediaStyle(new Notification.DecoratedMediaCustomViewStyle()));
|
|
} else {
|
|
super.apply(notificationBuilderWithBuilderAccessor);
|
|
}
|
|
}
|
|
|
|
@Override // androidx.media.app.NotificationCompat.MediaStyle
|
|
public int getBigContentViewLayoutResource(int i) {
|
|
return i <= 3 ? R.layout.notification_template_big_media_narrow_custom : R.layout.notification_template_big_media_custom;
|
|
}
|
|
|
|
@Override // androidx.media.app.NotificationCompat.MediaStyle
|
|
public int getContentViewLayoutResource() {
|
|
return this.mBuilder.getContentView() != null ? R.layout.notification_template_media_custom : super.getContentViewLayoutResource();
|
|
}
|
|
|
|
@Override // androidx.media.app.NotificationCompat.MediaStyle, androidx.core.app.NotificationCompat.Style
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY})
|
|
public RemoteViews makeBigContentView(NotificationBuilderWithBuilderAccessor notificationBuilderWithBuilderAccessor) {
|
|
if (Build.VERSION.SDK_INT >= 24) {
|
|
return null;
|
|
}
|
|
RemoteViews bigContentView = this.mBuilder.getBigContentView() != null ? this.mBuilder.getBigContentView() : this.mBuilder.getContentView();
|
|
if (bigContentView == null) {
|
|
return null;
|
|
}
|
|
RemoteViews generateBigContentView = generateBigContentView();
|
|
buildIntoRemoteViews(generateBigContentView, bigContentView);
|
|
setBackgroundColor(generateBigContentView);
|
|
return generateBigContentView;
|
|
}
|
|
|
|
@Override // androidx.media.app.NotificationCompat.MediaStyle, androidx.core.app.NotificationCompat.Style
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY})
|
|
public RemoteViews makeContentView(NotificationBuilderWithBuilderAccessor notificationBuilderWithBuilderAccessor) {
|
|
RemoteViews remoteViews = null;
|
|
if (Build.VERSION.SDK_INT >= 24) {
|
|
return null;
|
|
}
|
|
boolean z2 = true;
|
|
boolean z3 = this.mBuilder.getContentView() != null;
|
|
if (!z3 && this.mBuilder.getBigContentView() == null) {
|
|
z2 = false;
|
|
}
|
|
if (z2) {
|
|
remoteViews = generateContentView();
|
|
if (z3) {
|
|
buildIntoRemoteViews(remoteViews, this.mBuilder.getContentView());
|
|
}
|
|
setBackgroundColor(remoteViews);
|
|
}
|
|
return remoteViews;
|
|
}
|
|
|
|
@Override // androidx.core.app.NotificationCompat.Style
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY})
|
|
public RemoteViews makeHeadsUpContentView(NotificationBuilderWithBuilderAccessor notificationBuilderWithBuilderAccessor) {
|
|
if (Build.VERSION.SDK_INT >= 24) {
|
|
return null;
|
|
}
|
|
RemoteViews headsUpContentView = this.mBuilder.getHeadsUpContentView() != null ? this.mBuilder.getHeadsUpContentView() : this.mBuilder.getContentView();
|
|
if (headsUpContentView == null) {
|
|
return null;
|
|
}
|
|
RemoteViews generateBigContentView = generateBigContentView();
|
|
buildIntoRemoteViews(generateBigContentView, headsUpContentView);
|
|
setBackgroundColor(generateBigContentView);
|
|
return generateBigContentView;
|
|
}
|
|
}
|
|
|
|
public static class MediaStyle extends NotificationCompat.Style {
|
|
private static final int MAX_MEDIA_BUTTONS = 5;
|
|
private static final int MAX_MEDIA_BUTTONS_IN_COMPACT = 3;
|
|
public int[] mActionsToShowInCompact = null;
|
|
public PendingIntent mCancelButtonIntent;
|
|
public boolean mShowCancelButton;
|
|
public MediaSessionCompat.Token mToken;
|
|
|
|
public MediaStyle() {
|
|
}
|
|
|
|
public MediaStyle(NotificationCompat.Builder builder) {
|
|
setBuilder(builder);
|
|
}
|
|
|
|
private RemoteViews generateMediaActionButton(NotificationCompat.Action action) {
|
|
boolean z2 = action.getActionIntent() == null;
|
|
RemoteViews remoteViews = new RemoteViews(this.mBuilder.mContext.getPackageName(), R.layout.notification_media_action);
|
|
int i = R.id.action0;
|
|
remoteViews.setImageViewResource(i, action.getIcon());
|
|
if (!z2) {
|
|
remoteViews.setOnClickPendingIntent(i, action.getActionIntent());
|
|
}
|
|
remoteViews.setContentDescription(i, action.getTitle());
|
|
return remoteViews;
|
|
}
|
|
|
|
public static MediaSessionCompat.Token getMediaSession(Notification notification) {
|
|
Parcelable parcelable;
|
|
Bundle extras = androidx.core.app.NotificationCompat.getExtras(notification);
|
|
if (extras == null || (parcelable = extras.getParcelable("android.mediaSession")) == null) {
|
|
return null;
|
|
}
|
|
return MediaSessionCompat.Token.a(parcelable, null);
|
|
}
|
|
|
|
@Override // androidx.core.app.NotificationCompat.Style
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY})
|
|
public void apply(NotificationBuilderWithBuilderAccessor notificationBuilderWithBuilderAccessor) {
|
|
notificationBuilderWithBuilderAccessor.getBuilder().setStyle(fillInMediaStyle(new Notification.MediaStyle()));
|
|
}
|
|
|
|
@RequiresApi(21)
|
|
public Notification.MediaStyle fillInMediaStyle(Notification.MediaStyle mediaStyle) {
|
|
int[] iArr = this.mActionsToShowInCompact;
|
|
if (iArr != null) {
|
|
mediaStyle.setShowActionsInCompactView(iArr);
|
|
}
|
|
MediaSessionCompat.Token token = this.mToken;
|
|
if (token != null) {
|
|
mediaStyle.setMediaSession((MediaSession.Token) token.j);
|
|
}
|
|
return mediaStyle;
|
|
}
|
|
|
|
public RemoteViews generateBigContentView() {
|
|
int min = Math.min(this.mBuilder.mActions.size(), 5);
|
|
RemoteViews applyStandardTemplate = applyStandardTemplate(false, getBigContentViewLayoutResource(min), false);
|
|
applyStandardTemplate.removeAllViews(R.id.media_actions);
|
|
if (min > 0) {
|
|
for (int i = 0; i < min; i++) {
|
|
applyStandardTemplate.addView(R.id.media_actions, generateMediaActionButton(this.mBuilder.mActions.get(i)));
|
|
}
|
|
}
|
|
if (this.mShowCancelButton) {
|
|
int i2 = R.id.cancel_action;
|
|
applyStandardTemplate.setViewVisibility(i2, 0);
|
|
applyStandardTemplate.setInt(i2, "setAlpha", this.mBuilder.mContext.getResources().getInteger(R.integer.cancel_button_image_alpha));
|
|
applyStandardTemplate.setOnClickPendingIntent(i2, this.mCancelButtonIntent);
|
|
} else {
|
|
applyStandardTemplate.setViewVisibility(R.id.cancel_action, 8);
|
|
}
|
|
return applyStandardTemplate;
|
|
}
|
|
|
|
public RemoteViews generateContentView() {
|
|
RemoteViews applyStandardTemplate = applyStandardTemplate(false, getContentViewLayoutResource(), true);
|
|
int size = this.mBuilder.mActions.size();
|
|
int[] iArr = this.mActionsToShowInCompact;
|
|
int min = iArr == null ? 0 : Math.min(iArr.length, 3);
|
|
applyStandardTemplate.removeAllViews(R.id.media_actions);
|
|
if (min > 0) {
|
|
for (int i = 0; i < min; i++) {
|
|
if (i < size) {
|
|
applyStandardTemplate.addView(R.id.media_actions, generateMediaActionButton(this.mBuilder.mActions.get(this.mActionsToShowInCompact[i])));
|
|
} else {
|
|
throw new IllegalArgumentException(String.format("setShowActionsInCompactView: action %d out of bounds (max %d)", Integer.valueOf(i), Integer.valueOf(size - 1)));
|
|
}
|
|
}
|
|
}
|
|
if (this.mShowCancelButton) {
|
|
applyStandardTemplate.setViewVisibility(R.id.end_padder, 8);
|
|
int i2 = R.id.cancel_action;
|
|
applyStandardTemplate.setViewVisibility(i2, 0);
|
|
applyStandardTemplate.setOnClickPendingIntent(i2, this.mCancelButtonIntent);
|
|
applyStandardTemplate.setInt(i2, "setAlpha", this.mBuilder.mContext.getResources().getInteger(R.integer.cancel_button_image_alpha));
|
|
} else {
|
|
applyStandardTemplate.setViewVisibility(R.id.end_padder, 0);
|
|
applyStandardTemplate.setViewVisibility(R.id.cancel_action, 8);
|
|
}
|
|
return applyStandardTemplate;
|
|
}
|
|
|
|
public int getBigContentViewLayoutResource(int i) {
|
|
return i <= 3 ? R.layout.notification_template_big_media_narrow : R.layout.notification_template_big_media;
|
|
}
|
|
|
|
public int getContentViewLayoutResource() {
|
|
return R.layout.notification_template_media;
|
|
}
|
|
|
|
@Override // androidx.core.app.NotificationCompat.Style
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY})
|
|
public RemoteViews makeBigContentView(NotificationBuilderWithBuilderAccessor notificationBuilderWithBuilderAccessor) {
|
|
return null;
|
|
}
|
|
|
|
@Override // androidx.core.app.NotificationCompat.Style
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY})
|
|
public RemoteViews makeContentView(NotificationBuilderWithBuilderAccessor notificationBuilderWithBuilderAccessor) {
|
|
return null;
|
|
}
|
|
|
|
public MediaStyle setCancelButtonIntent(PendingIntent pendingIntent) {
|
|
this.mCancelButtonIntent = pendingIntent;
|
|
return this;
|
|
}
|
|
|
|
public MediaStyle setMediaSession(MediaSessionCompat.Token token) {
|
|
this.mToken = token;
|
|
return this;
|
|
}
|
|
|
|
public MediaStyle setShowActionsInCompactView(int... iArr) {
|
|
this.mActionsToShowInCompact = iArr;
|
|
return this;
|
|
}
|
|
|
|
public MediaStyle setShowCancelButton(boolean z2) {
|
|
return this;
|
|
}
|
|
}
|
|
|
|
private NotificationCompat() {
|
|
}
|
|
}
|