From 88c1dd1bc6cbc87a340693d5e5c7b86369f0b99d Mon Sep 17 00:00:00 2001 From: Sylvia van Os Date: Fri, 29 Nov 2024 17:37:03 +0100 Subject: [PATCH] Use black/white background colour instead of dominant colour for images This severely reduces the risk of a transparent PNG being put on a background which is the same colour as the logo --- app/src/main/java/protect/card_locker/Utils.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/protect/card_locker/Utils.java b/app/src/main/java/protect/card_locker/Utils.java index 4c27f6637..feee1cc68 100644 --- a/app/src/main/java/protect/card_locker/Utils.java +++ b/app/src/main/java/protect/card_locker/Utils.java @@ -945,11 +945,16 @@ public class Utils { public static int setIconOrTextWithBackground(Context context, LoyaltyCard loyaltyCard, Bitmap icon, ImageView backgroundOrIcon, TextView textWhenNoImage, int columnCount) { int headerColor = getHeaderColor(context, loyaltyCard); backgroundOrIcon.setImageBitmap(icon); - backgroundOrIcon.setBackgroundColor(headerColor); if (icon != null) { + // Use header colour to decide if this image will need a white or black background + backgroundOrIcon.setBackgroundColor(needsDarkForeground(headerColor) ? Color.BLACK : Color.WHITE); + textWhenNoImage.setVisibility(View.GONE); } else { + // Use header colour as background colour + backgroundOrIcon.setBackgroundColor(headerColor); + // Manually calculate how many lines will be needed // 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 // 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