From b0516fbf1d84f55e683051a994bf06bc83d0d1e8 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Sun, 24 Jul 2022 09:11:59 +0530 Subject: [PATCH] Use BitmapCompat.createScaledBitmap(). --- .../seekbarpreview/SeekbarPreviewThumbnailHelper.java | 5 +++-- .../java/org/schabi/newpipe/player/ui/VideoPlayerUi.java | 4 +++- .../main/java/org/schabi/newpipe/util/PicassoHelper.java | 9 ++++++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/seekbarpreview/SeekbarPreviewThumbnailHelper.java b/app/src/main/java/org/schabi/newpipe/player/seekbarpreview/SeekbarPreviewThumbnailHelper.java index 43d89055c..9eea89e78 100644 --- a/app/src/main/java/org/schabi/newpipe/player/seekbarpreview/SeekbarPreviewThumbnailHelper.java +++ b/app/src/main/java/org/schabi/newpipe/player/seekbarpreview/SeekbarPreviewThumbnailHelper.java @@ -8,6 +8,7 @@ import android.widget.ImageView; import androidx.annotation.IntDef; import androidx.annotation.NonNull; +import androidx.core.graphics.BitmapCompat; import androidx.core.math.MathUtils; import androidx.preference.PreferenceManager; @@ -91,8 +92,8 @@ public final class SeekbarPreviewThumbnailHelper { final float scaleFactor = (float) newWidth / srcWidth; final int newHeight = (int) (srcBitmap.getHeight() * scaleFactor); - currentSeekbarPreviewThumbnail.setImageBitmap( - Bitmap.createScaledBitmap(srcBitmap, newWidth, newHeight, true)); + currentSeekbarPreviewThumbnail.setImageBitmap(BitmapCompat.createScaledBitmap(srcBitmap, + newWidth, newHeight, null, true)); } catch (final Exception ex) { Log.e(TAG, "Failed to resize and set seekbar preview thumbnail", ex); currentSeekbarPreviewThumbnail.setVisibility(View.GONE); diff --git a/app/src/main/java/org/schabi/newpipe/player/ui/VideoPlayerUi.java b/app/src/main/java/org/schabi/newpipe/player/ui/VideoPlayerUi.java index 1709755f2..6eb97b8fa 100644 --- a/app/src/main/java/org/schabi/newpipe/player/ui/VideoPlayerUi.java +++ b/app/src/main/java/org/schabi/newpipe/player/ui/VideoPlayerUi.java @@ -42,6 +42,7 @@ import androidx.annotation.Nullable; import androidx.appcompat.content.res.AppCompatResources; import androidx.appcompat.view.ContextThemeWrapper; import androidx.appcompat.widget.PopupMenu; +import androidx.core.graphics.BitmapCompat; import androidx.core.graphics.Insets; import androidx.core.math.MathUtils; import androidx.core.view.ViewCompat; @@ -455,10 +456,11 @@ public abstract class VideoPlayerUi extends PlayerUi } final float endScreenHeight = calculateMaxEndScreenThumbnailHeight(thumbnail); - final Bitmap endScreenBitmap = Bitmap.createScaledBitmap( + final Bitmap endScreenBitmap = BitmapCompat.createScaledBitmap( thumbnail, (int) (thumbnail.getWidth() / (thumbnail.getHeight() / endScreenHeight)), (int) endScreenHeight, + null, true); if (DEBUG) { diff --git a/app/src/main/java/org/schabi/newpipe/util/PicassoHelper.java b/app/src/main/java/org/schabi/newpipe/util/PicassoHelper.java index 2e781631e..ece0c7e87 100644 --- a/app/src/main/java/org/schabi/newpipe/util/PicassoHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/PicassoHelper.java @@ -9,6 +9,7 @@ import android.graphics.Bitmap; import android.util.Log; import androidx.annotation.Nullable; +import androidx.core.graphics.BitmapCompat; import com.squareup.picasso.Cache; import com.squareup.picasso.LruCache; @@ -139,21 +140,23 @@ public final class PicassoHelper { .getDimension(R.dimen.player_notification_thumbnail_width), source.getWidth()); - final Bitmap result = Bitmap.createScaledBitmap( + final Bitmap result = BitmapCompat.createScaledBitmap( source, (int) notificationThumbnailWidth, (int) (source.getHeight() / (source.getWidth() / notificationThumbnailWidth)), + null, true); - if (result == source) { + if (result == source || !result.isMutable()) { // create a new mutable bitmap to prevent strange crashes on some // devices (see #4638) - final Bitmap copied = Bitmap.createScaledBitmap( + final Bitmap copied = BitmapCompat.createScaledBitmap( source, (int) notificationThumbnailWidth - 1, (int) (source.getHeight() / (source.getWidth() / (notificationThumbnailWidth - 1))), + null, true); source.recycle(); return copied;