소스 검색

use same color detection as https://github.com/nextcloud/server/pull/5953/files#diff-3de1769d04fcc4f13f8d546d9fbdac19

tobiaskaminsky 7 년 전
부모
커밋
fa35cc5914
1개의 변경된 파일10개의 추가작업 그리고 7개의 파일을 삭제
  1. 10 7
      src/main/java/com/owncloud/android/utils/ThemeUtils.java

+ 10 - 7
src/main/java/com/owncloud/android/utils/ThemeUtils.java

@@ -125,12 +125,9 @@ public class ThemeUtils {
      */
     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;
     }
 
     /**
@@ -172,14 +169,20 @@ public class ThemeUtils {
     }
 
     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.
      *