From 2010b9a25cc51fa590b8e7d6cabf308aac7d406f Mon Sep 17 00:00:00 2001 From: Sylvia van Os Date: Fri, 14 Jan 2022 20:41:04 +0100 Subject: [PATCH] Card-related colours on view screen --- .../protect/card_locker/LoyaltyCardViewActivity.java | 11 +++++++++++ app/src/main/java/protect/card_locker/Utils.java | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java b/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java index 28a488503..10a2de4e3 100644 --- a/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java +++ b/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java @@ -2,6 +2,7 @@ package protect.card_locker; import android.content.Intent; import android.content.pm.ActivityInfo; +import android.content.res.ColorStateList; import android.content.res.Configuration; import android.database.sqlite.SQLiteDatabase; import android.graphics.Bitmap; @@ -565,6 +566,16 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements storeName.setTextColor(textColor); landscapeToolbar.setTitleTextColor(textColor); + // Also apply colours to buttons + int darkenedColor = ColorUtils.blendARGB(backgroundHeaderColor, Color.BLACK, 0.1f); + maximizeButton.setBackgroundColor(darkenedColor); + minimizeButton.setBackgroundColor(darkenedColor); + bottomSheetButton.setBackgroundColor(darkenedColor); + maximizeButton.setColorFilter(textColor); + minimizeButton.setColorFilter(textColor); + bottomSheetButton.setColorFilter(textColor); + editButton.setBackgroundTintList(ColorStateList.valueOf(Utils.getComplementaryColor(darkenedColor))); + Bitmap icon = Utils.retrieveCardImage(this, loyaltyCard.id, ImageLocationType.icon); if (icon != null) { int backgroundAlphaColor = Utils.needsDarkForeground(backgroundHeaderColor) ? Color.WHITE : Color.BLACK; diff --git a/app/src/main/java/protect/card_locker/Utils.java b/app/src/main/java/protect/card_locker/Utils.java index 0094bddd0..6173706ed 100644 --- a/app/src/main/java/protect/card_locker/Utils.java +++ b/app/src/main/java/protect/card_locker/Utils.java @@ -448,4 +448,15 @@ public class Utils { return loadImage(context.getCacheDir() + "/" + name); } + // https://stackoverflow.com/a/59324801/8378787 + public static int getComplementaryColor(int color) { + int R = color & 255; + int G = (color >> 8) & 255; + int B = (color >> 16) & 255; + int A = (color >> 24) & 255; + R = 255 - R; + G = 255 - G; + B = 255 - B; + return R + (G << 8) + ( B << 16) + ( A << 24); + } }