Use primary color for status bar

pull/1496/head
Alex Baker 3 years ago
parent 233a122ae0
commit 46e4842f25

@ -1,89 +0,0 @@
package org.tasks.themes;
import android.graphics.Color;
class ColorUtil {
/**
* https://stackoverflow.com/a/40964456
* Darkens a given color
* @param base base color
* @param amount amount between 0 and 100
* @return darken color
*/
static int darken(int base, int amount) {
if (base == Color.WHITE) {
return Color.WHITE;
} else if (base == Color.BLACK) {
return Color.BLACK;
}
float[] hsv = new float[3];
Color.colorToHSV(base, hsv);
float[] hsl = hsv2hsl(hsv);
hsl[2] -= amount / 100f;
if (hsl[2] < 0)
hsl[2] = 0f;
hsv = hsl2hsv(hsl);
return Color.HSVToColor(hsv);
}
/**
* Converts HSV (Hue, Saturation, Value) color to HSL (Hue, Saturation, Lightness)
* Credit goes to xpansive
* https://gist.github.com/xpansive/1337890
* @param hsv HSV color array
* @return hsl
*/
private static float[] hsv2hsl(float[] hsv) {
float hue = hsv[0];
float sat = hsv[1];
float val = hsv[2];
//Saturation is very different between the two color spaces
//If (2-sat)*val < 1 set it to sat*val/((2-sat)*val)
//Otherwise sat*val/(2-(2-sat)*val)
//Conditional is not operating with hue, it is reassigned!
// sat*val/((hue=(2-sat)*val)<1?hue:2-hue)
float nhue = (2f - sat) * val;
float nsat = sat * val / (nhue < 1f ? nhue : 2f - nhue);
if (nsat > 1f)
nsat = 1f;
return new float[]{
//[hue, saturation, lightness]
//Range should be between 0 - 1
hue, //Hue stays the same
// check nhue and nsat logic
nsat,
nhue / 2f //Lightness is (2-sat)*val/2
//See reassignment of hue above
};
}
/**
* Reverses hsv2hsl
* Credit goes to xpansive
* https://gist.github.com/xpansive/1337890
* @param hsl HSL color array
* @return hsv color array
*/
private static float[] hsl2hsv(float[] hsl) {
float hue = hsl[0];
float sat = hsl[1];
float light = hsl[2];
sat *= light < .5 ? light : 1 - light;
return new float[]{
//[hue, saturation, value]
//Range should be between 0 - 1
hue, //Hue stays the same
2f * sat / (light + sat), //Saturation
light + sat //Value
};
}
}

@ -165,7 +165,6 @@ public class ThemeColor implements Pickable {
private final int colorOnPrimary;
private final int hintOnPrimary;
private final int colorPrimary;
private final int colorPrimaryVariant;
private final boolean isDark;
public ThemeColor(Context context, int color) {
@ -180,7 +179,6 @@ public class ThemeColor implements Pickable {
color |= 0xFF000000; // remove alpha
}
colorPrimary = color;
colorPrimaryVariant = ColorUtil.darken(colorPrimary, 6);
double contrast = ColorUtils.calculateContrast(WHITE, colorPrimary);
isDark = contrast < 3;
@ -196,7 +194,6 @@ public class ThemeColor implements Pickable {
private ThemeColor(Parcel source) {
colorOnPrimary = source.readInt();
colorPrimary = source.readInt();
colorPrimaryVariant = source.readInt();
isDark = ParcelCompat.readBoolean(source);
original = source.readInt();
hintOnPrimary = source.readInt();
@ -240,18 +237,18 @@ public class ThemeColor implements Pickable {
}
public void setStatusBarColor(Activity activity) {
activity.getWindow().setStatusBarColor(colorPrimaryVariant);
activity.getWindow().setStatusBarColor(colorPrimary);
}
public void setStatusBarColor(DrawerLayout drawerLayout) {
drawerLayout.setStatusBarBackgroundColor(colorPrimaryVariant);
drawerLayout.setStatusBarBackgroundColor(colorPrimary);
int systemUiVisibility = applyLightStatusBarFlag(drawerLayout.getSystemUiVisibility());
drawerLayout.setSystemUiVisibility(systemUiVisibility);
}
public void setStatusBarColor(CollapsingToolbarLayout layout) {
layout.setContentScrimColor(colorPrimary);
layout.setStatusBarScrimColor(colorPrimaryVariant);
layout.setStatusBarScrimColor(colorPrimary);
}
public void apply(CollapsingToolbarLayout layout, Toolbar toolbar) {
@ -355,7 +352,6 @@ public class ThemeColor implements Pickable {
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(colorOnPrimary);
dest.writeInt(colorPrimary);
dest.writeInt(colorPrimaryVariant);
ParcelCompat.writeBoolean(dest, isDark);
dest.writeInt(original);
dest.writeInt(hintOnPrimary);

Loading…
Cancel
Save