Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crop the notification thumbnail in 1:1 mode instead of stretching it #8533

Merged
merged 6 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions app/src/main/java/org/schabi/newpipe/player/NotificationUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
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;

Expand Down Expand Up @@ -366,16 +365,13 @@ private void setLargeIcon(final NotificationCompat.Builder builder, final Player
}

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);
}
}
4 changes: 2 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
<string name="show_play_with_kodi_title">Show \"Play with Kodi\" option</string>
<string name="show_play_with_kodi_summary">Display an option to play a video via Kodi media center</string>
<string name="crash_the_player">Crash the player</string>
<string name="notification_scale_to_square_image_title">Scale thumbnail to 1:1 aspect ratio</string>
<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>
<string name="notification_scale_to_square_image_title">Crop thumbnail to 1:1 aspect ratio</string>
<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>
<string name="notification_action_0_title">First action button</string>
<string name="notification_action_1_title">Second action button</string>
<string name="notification_action_2_title">Third action button</string>
Expand Down