tobiaskaminsky 2017-08-11 14:46:47 +02:00
parent 424e2cdbc0
commit fa35cc5914
No known key found for this signature in database
GPG key ID: 0E00D4D47D0C5AF7

View file

@ -125,12 +125,9 @@ public class ThemeUtils {
*/ */
public static boolean darkTheme() { public static boolean darkTheme() {
int primaryColor = primaryColor(); int primaryColor = primaryColor();
float[] hsl = colorToHSL(primaryColor);
int red = Color.red(primaryColor); return (hsl[2] / 100) <= 0.5;
int green = Color.green(primaryColor);
int blue = Color.blue(primaryColor);
return ((0.299 * red + 0.587 * green + 0.114 * blue) / 255) <= 0.5;
} }
/** /**
@ -172,14 +169,20 @@ public class ThemeUtils {
} }
public static int adjustLightness(float lightnessDelta, int color) { public static int adjustLightness(float lightnessDelta, int color) {
float[] hsl = new float[3]; float[] hsl = colorToHSL(color);
ColorUtils.RGBToHSL(Color.red(color), Color.green(color), Color.blue(color), hsl);
hsl[2] += lightnessDelta; hsl[2] += lightnessDelta;
return ColorUtils.HSLToColor(hsl); return ColorUtils.HSLToColor(hsl);
} }
private static float[] colorToHSL(int color) {
float[] hsl = new float[3];
ColorUtils.RGBToHSL(Color.red(color), Color.green(color), Color.blue(color), hsl);
return hsl;
}
/** /**
* sets the tinting of the given ImageButton's icon to color_accent. * sets the tinting of the given ImageButton's icon to color_accent.
* *