From 963529fd0852e9a4bb5b6628f9ec0f8bf092241b Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 1 Jul 2020 18:26:07 +0200 Subject: [PATCH] Colored message bottom action bar contrast --- .../java/eu/faircode/email/FragmentMessages.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index a2e7008b4c..6396ede86e 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -32,6 +32,7 @@ import android.content.IntentFilter; import android.content.IntentSender; import android.content.SharedPreferences; import android.content.pm.PackageManager; +import android.content.res.ColorStateList; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.PorterDuff; @@ -97,6 +98,7 @@ import androidx.appcompat.widget.PopupMenu; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.constraintlayout.widget.Group; import androidx.core.content.ContextCompat; +import androidx.core.graphics.ColorUtils; import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentTransaction; @@ -307,6 +309,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. private static final int MAX_MORE = 100; // messages private static final int UNDO_TIMEOUT = 5000; // milliseconds private static final int SWIPE_DISABLE_SELECT_DURATION = 1500; // milliseconds + private static final float LUMINANCE_THRESHOLD = 0.7f; private static final int REQUEST_RAW = 1; private static final int REQUEST_OPENPGP = 4; @@ -4355,8 +4358,16 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. @Override protected void onExecuted(Bundle args, Boolean[] data) { - if (actionbar_color && args.containsKey("color")) - bottom_navigation.setBackgroundColor(args.getInt("color")); + if (actionbar_color && args.containsKey("color")) { + int color = args.getInt("color"); + bottom_navigation.setBackgroundColor(color); + + float lum = (float) ColorUtils.calculateLuminance(color); + if (lum > LUMINANCE_THRESHOLD) + bottom_navigation.setItemIconTintList(ColorStateList.valueOf(Color.BLACK)); + else if ((1.0f - lum) > LUMINANCE_THRESHOLD) + bottom_navigation.setItemIconTintList(ColorStateList.valueOf(Color.WHITE)); + } bottom_navigation.setTag(data[0]); bottom_navigation.getMenu().findItem(R.id.action_delete).setVisible(data[1]);