From f7ad10d77c452422e20ad53dbafcbba996e4ce37 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 18 Sep 2023 22:06:59 +0200 Subject: [PATCH] Set compose action bar item color --- .../eu/faircode/email/FragmentCompose.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index e8c7df8c53..2d80fca1ae 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -118,6 +118,7 @@ import androidx.appcompat.widget.PopupMenu; import androidx.constraintlayout.widget.Group; import androidx.core.content.ContextCompat; import androidx.core.content.FileProvider; +import androidx.core.graphics.ColorUtils; import androidx.core.view.MenuCompat; import androidx.core.view.WindowInsetsCompat; import androidx.cursoradapter.widget.SimpleCursorAdapter; @@ -320,6 +321,7 @@ public class FragmentCompose extends FragmentBase { // http://regex.info/blog/lightroom-goodies/jpeg-quality private static final int MAX_QUOTE_LEVEL = 5; + private static final float LUMINANCE_THRESHOLD = 0.7f; private static final int REQUEST_CONTACT_TO = 1; private static final int REQUEST_CONTACT_CC = 2; @@ -7851,6 +7853,33 @@ public class FragmentCompose extends FragmentBase { Integer color = (identity.color == null ? identity.accountColor : identity.color); bottom_navigation.setBackgroundColor(color == null ? Helper.resolveColor(context, androidx.appcompat.R.attr.colorPrimary) : color); + + ColorStateList itemColor; + if (color == null) + itemColor = ContextCompat.getColorStateList(context, R.color.action_foreground); + else { + Integer icolor = null; + float lum = (float) ColorUtils.calculateLuminance(color); + if (lum > LUMINANCE_THRESHOLD) + icolor = Color.BLACK; + else if ((1.0f - lum) > LUMINANCE_THRESHOLD) + icolor = Color.WHITE; + if (icolor == null) + itemColor = ContextCompat.getColorStateList(context, R.color.action_foreground); + else + itemColor = new ColorStateList( + new int[][]{ + new int[]{android.R.attr.state_enabled}, + new int[]{} + }, + new int[]{ + icolor, + Color.GRAY + } + ); + } + bottom_navigation.setItemIconTintList(itemColor); + bottom_navigation.setItemTextColor(itemColor); } Spanned signature = null;