File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
app/src/main/java/protect/card_locker Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -1018,6 +1018,9 @@ public static int setIconOrTextWithBackground(Context context, LoyaltyCard loyal
10181018 // Use header colour to decide if this image will need a white or black background
10191019 backgroundOrIcon .setBackgroundColor (needsDarkForeground (headerColor ) ? Color .BLACK : Color .WHITE );
10201020
1021+ // Ensure correct cropping style
1022+ backgroundOrIcon .setScaleType (Utils .getRecommendedScaleTypeForThumbnailImage (icon ));
1023+
10211024 textWhenNoImage .setVisibility (View .GONE );
10221025 } else {
10231026 // Use header colour as background colour
@@ -1126,4 +1129,19 @@ public static void applyWindowInsets(View root) {
11261129 return WindowInsetsCompat .CONSUMED ;
11271130 });
11281131 }
1132+
1133+ public static ImageView .ScaleType getRecommendedScaleTypeForThumbnailImage (@ Nullable Bitmap image ) {
1134+ // Return something sensible if no image
1135+ if (image == null ) {
1136+ return ImageView .ScaleType .FIT_CENTER ;
1137+ }
1138+
1139+ // If the image is relatively close to 85.6:53.98 (width = 1.58577250834 * height), allow cropping it to fit it
1140+ double ratio = (double ) image .getWidth () / image .getHeight ();
1141+ if (ratio >= 1.55 && ratio <= 1.60 ) {
1142+ return ImageView .ScaleType .CENTER_CROP ;
1143+ }
1144+
1145+ return ImageView .ScaleType .FIT_CENTER ;
1146+ }
11291147}
You can’t perform that action at this time.
0 commit comments