Skip to content

Commit

Permalink
Merge pull request #1314 from nextcloud/colorThreshold
Browse files Browse the repository at this point in the history
Use same color detection as in server
  • Loading branch information
AndyScherzinger authored Aug 11, 2017
2 parents e3fe948 + fa35cc5 commit 519702c
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/main/java/com/owncloud/android/utils/ThemeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,9 @@ public static int fontColor() {
*/
public static boolean darkTheme() {
int primaryColor = primaryColor();
float[] hsl = colorToHSL(primaryColor);

int red = Color.red(primaryColor);
int green = Color.green(primaryColor);
int blue = Color.blue(primaryColor);

return ((0.299 * red + 0.587 * green + 0.114 * blue) / 255) <= 0.5;
return (hsl[2] / 100) <= 0.5;
}

/**
Expand Down Expand Up @@ -172,14 +169,20 @@ public static String getDefaultDisplayNameForRootFolder() {
}

public static int adjustLightness(float lightnessDelta, int color) {
float[] hsl = new float[3];
ColorUtils.RGBToHSL(Color.red(color), Color.green(color), Color.blue(color), hsl);
float[] hsl = colorToHSL(color);

hsl[2] += lightnessDelta;

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.
*
Expand Down

0 comments on commit 519702c

Please sign in to comment.