Skip to content

Commit 6f7298b

Browse files
authored
Crop the notification thumbnail in 1:1 mode instead of stretching it (TeamNewPipe#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.
1 parent 93b913e commit 6f7298b

2 files changed

Lines changed: 10 additions & 14 deletions

File tree

app/src/main/java/org/schabi/newpipe/player/NotificationUtil.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import android.content.Intent;
77
import android.content.pm.ServiceInfo;
88
import android.graphics.Bitmap;
9-
import android.graphics.Matrix;
109
import android.os.Build;
1110
import android.util.Log;
1211

@@ -366,16 +365,13 @@ private void setLargeIcon(final NotificationCompat.Builder builder, final Player
366365
}
367366

368367
private Bitmap getBitmapWithSquareAspectRatio(final Bitmap bitmap) {
369-
return getResizedBitmap(bitmap, bitmap.getWidth(), bitmap.getWidth());
370-
}
371-
372-
private Bitmap getResizedBitmap(final Bitmap bitmap, final int newWidth, final int newHeight) {
373-
final int width = bitmap.getWidth();
374-
final int height = bitmap.getHeight();
375-
final float scaleWidth = ((float) newWidth) / width;
376-
final float scaleHeight = ((float) newHeight) / height;
377-
final Matrix matrix = new Matrix();
378-
matrix.postScale(scaleWidth, scaleHeight);
379-
return Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, false);
368+
// Find the smaller dimension and then take a center portion of the image that
369+
// has that size.
370+
final int w = bitmap.getWidth();
371+
final int h = bitmap.getHeight();
372+
final int dstSize = Math.min(w, h);
373+
final int x = (w - dstSize) / 2;
374+
final int y = (h - dstSize) / 2;
375+
return Bitmap.createBitmap(bitmap, x, y, dstSize, dstSize);
380376
}
381377
}

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050
<string name="show_play_with_kodi_title">Show \"Play with Kodi\" option</string>
5151
<string name="show_play_with_kodi_summary">Display an option to play a video via Kodi media center</string>
5252
<string name="crash_the_player">Crash the player</string>
53-
<string name="notification_scale_to_square_image_title">Scale thumbnail to 1:1 aspect ratio</string>
54-
<string name="notification_scale_to_square_image_summary">Scale the video thumbnail shown in the notification from 16:9 to 1:1 aspect ratio (may introduce distortions)</string>
53+
<string name="notification_scale_to_square_image_title">Crop thumbnail to 1:1 aspect ratio</string>
54+
<string name="notification_scale_to_square_image_summary">Crop the video thumbnail shown in the notification from 16:9 to 1:1 aspect ratio</string>
5555
<string name="notification_action_0_title">First action button</string>
5656
<string name="notification_action_1_title">Second action button</string>
5757
<string name="notification_action_2_title">Third action button</string>

0 commit comments

Comments
 (0)