Calculate toolbar text contrast

pull/935/head
Alex Baker 6 years ago
parent 50f0c5bedd
commit 573cbca918

@ -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<ThemeAccent> getAccents() {
return copyOf(accents);
}

@ -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) {

@ -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"/>
</LinearLayout>

@ -7,7 +7,6 @@
<!-- theme attributes -->
<attr format="reference" name="overlay_theme"/>
<attr format="boolean" name="dark_status_bar"/>
<attr format="dimension" name="card_elevation"/>
<attr format="integer" name="horizontal_divider"/>
<attr format="color" name="colorOnPrimaryHint"/>

@ -27,7 +27,6 @@
</style>
<style name="WhiteToolbarTheme">
<item name="dark_status_bar">false</item>
<item name="overlay_theme">@style/WhiteToolbarOverlay</item>
<item name="colorOnPrimary">@color/white_100</item>
<item name="colorOnPrimaryHint">@color/white_70</item>
@ -35,7 +34,6 @@
</style>
<style name="BlackToolbarTheme">
<item name="dark_status_bar">true</item>
<item name="overlay_theme">@style/BlackToolbarOverlay</item>
<item name="colorOnPrimary">@color/black_87</item>
<item name="colorOnPrimaryHint">@color/black_54</item>

Loading…
Cancel
Save