From dcc6642f3395dbbc186fa735d2da2e43577c5567 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Tue, 3 Sep 2019 15:55:09 +0200 Subject: [PATCH] Updated default notification icon --- .../PlaybackServiceNotificationBuilder.java | 32 +++++++++++++++++-- .../notification_default_large_icon.xml | 15 +++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 core/src/main/res/drawable/notification_default_large_icon.xml diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceNotificationBuilder.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceNotificationBuilder.java index 9a1e8e7ef..d9595e987 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceNotificationBuilder.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceNotificationBuilder.java @@ -1,12 +1,18 @@ package de.danoeh.antennapod.core.service.playback; +import android.annotation.TargetApi; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; -import android.graphics.BitmapFactory; +import android.graphics.Canvas; +import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; +import android.graphics.drawable.VectorDrawable; +import android.os.Build; import android.support.annotation.NonNull; import android.support.v4.app.NotificationCompat; +import android.support.v4.content.ContextCompat; import android.support.v4.media.session.MediaSessionCompat; import android.util.Log; import android.view.KeyEvent; @@ -98,12 +104,32 @@ public class PlaybackServiceNotificationBuilder extends NotificationCompat.Build public void loadDefaultIcon() { if (defaultIcon == null) { - defaultIcon = BitmapFactory.decodeResource(context.getResources(), - ClientConfig.playbackServiceCallbacks.getNotificationIconResource(context)); + defaultIcon = getBitmap(context, R.drawable.notification_default_large_icon); } setLargeIcon(defaultIcon); } + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + private static Bitmap getBitmap(VectorDrawable vectorDrawable) { + Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(), + vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); + Canvas canvas = new Canvas(bitmap); + vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); + vectorDrawable.draw(canvas); + return bitmap; + } + + private static Bitmap getBitmap(Context context, int drawableId) { + Drawable drawable = ContextCompat.getDrawable(context, drawableId); + if (drawable instanceof BitmapDrawable) { + return ((BitmapDrawable) drawable).getBitmap(); + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && drawable instanceof VectorDrawable) { + return getBitmap((VectorDrawable) drawable); + } else { + return null; + } + } + private void addActions(MediaSessionCompat.Token mediaSessionToken, PlayerStatus playerStatus, boolean isCasting) { IntList compactActionList = new IntList(); diff --git a/core/src/main/res/drawable/notification_default_large_icon.xml b/core/src/main/res/drawable/notification_default_large_icon.xml new file mode 100644 index 000000000..6e0c1e369 --- /dev/null +++ b/core/src/main/res/drawable/notification_default_large_icon.xml @@ -0,0 +1,15 @@ + + + + + + +