From 573cbca918a844bab6554a6b8943eb42144614cb Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Sun, 23 Feb 2020 08:55:38 -0600 Subject: [PATCH] Calculate toolbar text contrast --- app/src/main/java/org/tasks/themes/ThemeCache.java | 14 ++++---------- app/src/main/java/org/tasks/themes/ThemeColor.java | 11 ++++++++--- .../main/res/layout/control_set_repeat_display.xml | 2 +- app/src/main/res/values/attrs.xml | 1 - app/src/main/res/values/styles.xml | 2 -- 5 files changed, 13 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/org/tasks/themes/ThemeCache.java b/app/src/main/java/org/tasks/themes/ThemeCache.java index 2696f7a79..1376cb001 100644 --- a/app/src/main/java/org/tasks/themes/ThemeCache.java +++ b/app/src/main/java/org/tasks/themes/ThemeCache.java @@ -64,12 +64,12 @@ public class ThemeCache { Resources.Theme theme = new ContextThemeWrapper(context, ThemeColor.COLORS[i]).getTheme(); colors.add( new ThemeColor( + context, colorNames[i], i, resolveAttribute(theme, R.attr.colorPrimary), resolveAttribute(theme, R.attr.colorPrimaryVariant), - resolveAttribute(theme, R.attr.colorOnPrimary), - resolveBoolean(theme, R.attr.dark_status_bar))); + resolveAttribute(theme, R.attr.colorOnPrimary))); } String[] accentNames = resources.getStringArray(R.array.accents); for (int i = 0; i < ThemeAccent.ACCENTS.length; i++) { @@ -88,12 +88,12 @@ public class ThemeCache { } untaggedColor = new ThemeColor( + context, null, 19, getColor(context, R.color.tag_color_none_background), 0, - getColor(context, R.color.black_87), - false); + getColor(context, R.color.black_87)); } private static int resolveAttribute(Resources.Theme theme, int attribute) { @@ -122,12 +122,6 @@ public class ThemeCache { return untaggedColor; } - private boolean resolveBoolean(Resources.Theme theme, int attribute) { - TypedValue typedValue = new TypedValue(); - theme.resolveAttribute(attribute, typedValue, false); - return typedValue.data != 0; - } - public List getAccents() { return copyOf(accents); } diff --git a/app/src/main/java/org/tasks/themes/ThemeColor.java b/app/src/main/java/org/tasks/themes/ThemeColor.java index 72ea9bf9d..a832820b9 100644 --- a/app/src/main/java/org/tasks/themes/ThemeColor.java +++ b/app/src/main/java/org/tasks/themes/ThemeColor.java @@ -6,6 +6,7 @@ import static com.todoroo.andlib.utility.AndroidUtilities.atLeastOreo; import android.app.Activity; import android.app.ActivityManager; +import android.content.Context; import android.content.res.Resources; import android.os.Build.VERSION_CODES; import android.os.Parcel; @@ -13,6 +14,7 @@ import android.os.Parcelable; import android.view.View; import androidx.annotation.RequiresApi; import androidx.appcompat.widget.Toolbar; +import androidx.core.graphics.ColorUtils; import androidx.drawerlayout.widget.DrawerLayout; import org.tasks.R; import org.tasks.dialogs.ColorPickerDialog; @@ -114,19 +116,22 @@ public class ThemeColor implements ColorPickerDialog.Pickable { private final boolean isDark; public ThemeColor( + Context context, String name, int index, int colorPrimary, int colorPrimaryVariant, - int actionBarTint, - boolean isDark) { + int actionBarTint) { this.name = name; this.index = index; this.actionBarTint = actionBarTint; this.style = COLORS[index]; this.colorPrimary = colorPrimary; this.colorPrimaryVariant = colorPrimaryVariant; - this.isDark = isDark; + double contrast = + ColorUtils.calculateContrast( + context.getResources().getColor(R.color.white_100), colorPrimary); + this.isDark = contrast < 3; } private ThemeColor(Parcel source) { diff --git a/app/src/main/res/layout/control_set_repeat_display.xml b/app/src/main/res/layout/control_set_repeat_display.xml index 52d114fc3..5afc3f82b 100644 --- a/app/src/main/res/layout/control_set_repeat_display.xml +++ b/app/src/main/res/layout/control_set_repeat_display.xml @@ -42,7 +42,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@null" - android:textColor="?attr/colorPrimary"/> + android:textColor="@color/text_primary"/> diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index cebc15995..42f8317c8 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -7,7 +7,6 @@ - diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 6be5ce3bb..7f9a5eb25 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -27,7 +27,6 @@