From 6f7298b9db728517179dff432f7641e92ae47608 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 13 Jul 2022 15:19:44 +0000 Subject: [PATCH] Crop the notification thumbnail in 1:1 mode instead of stretching it (#8533) Change square bitmap transformation strategy: change the bitmap transformation strategy when a 1:1 aspect ratio is enabled to not stretch the bitmap but rather crop it. On Android 11/12, the way the whole thumbnail was used for the notification icon was not ideal, however the setting to toggle a 1:1 (as it states in settings) resulted in distortions. Fix this by simply cropping the bitmap. Also update the 1:1 mode strings to remove mentions of scaling or distortions, as those no longer apply. --- .../newpipe/player/NotificationUtil.java | 20 ++++++++----------- app/src/main/res/values/strings.xml | 4 ++-- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/NotificationUtil.java b/app/src/main/java/org/schabi/newpipe/player/NotificationUtil.java index 948343be2..2060d67c4 100644 --- a/app/src/main/java/org/schabi/newpipe/player/NotificationUtil.java +++ b/app/src/main/java/org/schabi/newpipe/player/NotificationUtil.java @@ -6,7 +6,6 @@ import android.app.Service; import android.content.Intent; import android.content.pm.ServiceInfo; import android.graphics.Bitmap; -import android.graphics.Matrix; import android.os.Build; import android.util.Log; @@ -366,16 +365,13 @@ public final class NotificationUtil { } private Bitmap getBitmapWithSquareAspectRatio(final Bitmap bitmap) { - return getResizedBitmap(bitmap, bitmap.getWidth(), bitmap.getWidth()); - } - - private Bitmap getResizedBitmap(final Bitmap bitmap, final int newWidth, final int newHeight) { - final int width = bitmap.getWidth(); - final int height = bitmap.getHeight(); - final float scaleWidth = ((float) newWidth) / width; - final float scaleHeight = ((float) newHeight) / height; - final Matrix matrix = new Matrix(); - matrix.postScale(scaleWidth, scaleHeight); - return Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, false); + // Find the smaller dimension and then take a center portion of the image that + // has that size. + final int w = bitmap.getWidth(); + final int h = bitmap.getHeight(); + final int dstSize = Math.min(w, h); + final int x = (w - dstSize) / 2; + final int y = (h - dstSize) / 2; + return Bitmap.createBitmap(bitmap, x, y, dstSize, dstSize); } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1d65b6fba..cedb01b20 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -50,8 +50,8 @@ Show \"Play with Kodi\" option Display an option to play a video via Kodi media center Crash the player - Scale thumbnail to 1:1 aspect ratio - Scale the video thumbnail shown in the notification from 16:9 to 1:1 aspect ratio (may introduce distortions) + Crop thumbnail to 1:1 aspect ratio + Crop the video thumbnail shown in the notification from 16:9 to 1:1 aspect ratio First action button Second action button Third action button