Skip to content

Commit 18a2c3d

Browse files
Merge pull request #2471 from CatimaLoyalty/fix/iconWhiteLine
Fix icons having white/black lines
2 parents 8f94432 + e3e1e0c commit 18a2c3d

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

app/src/main/java/protect/card_locker/Utils.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)