Skip to content

Commit d997759

Browse files
Merge pull request #2201 from CatimaLoyalty/fix/transparentThumbnails
Use black/white background colour instead of dominant colour for images
2 parents 5e710ba + 88c1dd1 commit d997759

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,11 +945,16 @@ public static String linkify(final String input) {
945945
public static int setIconOrTextWithBackground(Context context, LoyaltyCard loyaltyCard, Bitmap icon, ImageView backgroundOrIcon, TextView textWhenNoImage, int columnCount) {
946946
int headerColor = getHeaderColor(context, loyaltyCard);
947947
backgroundOrIcon.setImageBitmap(icon);
948-
backgroundOrIcon.setBackgroundColor(headerColor);
949948

950949
if (icon != null) {
950+
// Use header colour to decide if this image will need a white or black background
951+
backgroundOrIcon.setBackgroundColor(needsDarkForeground(headerColor) ? Color.BLACK : Color.WHITE);
952+
951953
textWhenNoImage.setVisibility(View.GONE);
952954
} else {
955+
// Use header colour as background colour
956+
backgroundOrIcon.setBackgroundColor(headerColor);
957+
953958
// Manually calculate how many lines will be needed
954959
// This is necessary because Android's auto sizing will split over lines way before reaching the minimum font size and store names split over multiple lines are harder to scan with a quick glance so we should try to prevent it
955960
// Because we have to write the text before we can actually know the exact laid out size (trying to delay this causes bugs where the autosize fails) we have to take some... weird shortcuts

0 commit comments

Comments
 (0)