Loading api/current.txt +1 −0 Original line number Diff line number Diff line Loading @@ -11276,6 +11276,7 @@ package android.graphics { method public static int blue(int); method public static void colorToHSV(int, float[]); method public static int green(int); method public static float luminance(int); method public static int parseColor(java.lang.String); method public static int red(int); method public static int rgb(int, int, int); api/system-current.txt +1 −0 Original line number Diff line number Diff line Loading @@ -11613,6 +11613,7 @@ package android.graphics { method public static int blue(int); method public static void colorToHSV(int, float[]); method public static int green(int); method public static float luminance(int); method public static int parseColor(java.lang.String); method public static int red(int); method public static int rgb(int, int, int); core/java/com/android/internal/policy/PhoneWindow.java +1 −1 Original line number Diff line number Diff line Loading @@ -4032,7 +4032,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { // dark or the light button frame. TypedValue value = new TypedValue(); getContext().getTheme().resolveAttribute(R.attr.colorPrimary, value, true); if (Color.brightness(value.data) < 0.5) { if (Color.luminance(value.data) < 0.5) { nonClientDecorView = (NonClientDecorView) mLayoutInflater.inflate( R.layout.non_client_decor_dark, null); } else { Loading graphics/java/android/graphics/Color.java +13 −81 Original line number Diff line number Diff line Loading @@ -113,89 +113,21 @@ public class Color { } /** * Returns the hue component of a color int. * Returns the relative luminance of a color. * <p> * Assumes sRGB encoding. Based on the formula for relative luminance * defined in WCAG 2.0, W3C Recommendation 11 December 2008. * * @return A value between 0.0f and 1.0f * * @hide Pending API council * @return a value between 0 (darkest black) and 1 (lightest white) */ public static float hue(@ColorInt int color) { int r = (color >> 16) & 0xFF; int g = (color >> 8) & 0xFF; int b = color & 0xFF; int V = Math.max(b, Math.max(r, g)); int temp = Math.min(b, Math.min(r, g)); float H; if (V == temp) { H = 0; } else { final float vtemp = (float) (V - temp); final float cr = (V - r) / vtemp; final float cg = (V - g) / vtemp; final float cb = (V - b) / vtemp; if (r == V) { H = cb - cg; } else if (g == V) { H = 2 + cr - cb; } else { H = 4 + cg - cr; } H /= 6.f; if (H < 0) { H++; } } return H; } /** * Returns the saturation component of a color int. * * @return A value between 0.0f and 1.0f * * @hide Pending API council */ public static float saturation(@ColorInt int color) { int r = (color >> 16) & 0xFF; int g = (color >> 8) & 0xFF; int b = color & 0xFF; int V = Math.max(b, Math.max(r, g)); int temp = Math.min(b, Math.min(r, g)); float S; if (V == temp) { S = 0; } else { S = (V - temp) / (float) V; } return S; } /** * Returns the brightness component of a color int. * * @return A value between 0.0f and 1.0f * * @hide Pending API council */ public static float brightness(@ColorInt int color) { int r = (color >> 16) & 0xFF; int g = (color >> 8) & 0xFF; int b = color & 0xFF; int V = Math.max(b, Math.max(r, g)); return (V / 255.f); public static float luminance(@ColorInt int color) { double red = Color.red(color) / 255.0; red = red < 0.03928 ? red / 12.92 : Math.pow((red + 0.055) / 1.055, 2.4); double green = Color.green(color) / 255.0; green = green < 0.03928 ? green / 12.92 : Math.pow((green + 0.055) / 1.055, 2.4); double blue = Color.blue(color) / 255.0; blue = blue < 0.03928 ? blue / 12.92 : Math.pow((blue + 0.055) / 1.055, 2.4); return (float) ((0.2126 * red) + (0.7152 * green) + (0.0722 * blue)); } /** Loading Loading
api/current.txt +1 −0 Original line number Diff line number Diff line Loading @@ -11276,6 +11276,7 @@ package android.graphics { method public static int blue(int); method public static void colorToHSV(int, float[]); method public static int green(int); method public static float luminance(int); method public static int parseColor(java.lang.String); method public static int red(int); method public static int rgb(int, int, int);
api/system-current.txt +1 −0 Original line number Diff line number Diff line Loading @@ -11613,6 +11613,7 @@ package android.graphics { method public static int blue(int); method public static void colorToHSV(int, float[]); method public static int green(int); method public static float luminance(int); method public static int parseColor(java.lang.String); method public static int red(int); method public static int rgb(int, int, int);
core/java/com/android/internal/policy/PhoneWindow.java +1 −1 Original line number Diff line number Diff line Loading @@ -4032,7 +4032,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { // dark or the light button frame. TypedValue value = new TypedValue(); getContext().getTheme().resolveAttribute(R.attr.colorPrimary, value, true); if (Color.brightness(value.data) < 0.5) { if (Color.luminance(value.data) < 0.5) { nonClientDecorView = (NonClientDecorView) mLayoutInflater.inflate( R.layout.non_client_decor_dark, null); } else { Loading
graphics/java/android/graphics/Color.java +13 −81 Original line number Diff line number Diff line Loading @@ -113,89 +113,21 @@ public class Color { } /** * Returns the hue component of a color int. * Returns the relative luminance of a color. * <p> * Assumes sRGB encoding. Based on the formula for relative luminance * defined in WCAG 2.0, W3C Recommendation 11 December 2008. * * @return A value between 0.0f and 1.0f * * @hide Pending API council * @return a value between 0 (darkest black) and 1 (lightest white) */ public static float hue(@ColorInt int color) { int r = (color >> 16) & 0xFF; int g = (color >> 8) & 0xFF; int b = color & 0xFF; int V = Math.max(b, Math.max(r, g)); int temp = Math.min(b, Math.min(r, g)); float H; if (V == temp) { H = 0; } else { final float vtemp = (float) (V - temp); final float cr = (V - r) / vtemp; final float cg = (V - g) / vtemp; final float cb = (V - b) / vtemp; if (r == V) { H = cb - cg; } else if (g == V) { H = 2 + cr - cb; } else { H = 4 + cg - cr; } H /= 6.f; if (H < 0) { H++; } } return H; } /** * Returns the saturation component of a color int. * * @return A value between 0.0f and 1.0f * * @hide Pending API council */ public static float saturation(@ColorInt int color) { int r = (color >> 16) & 0xFF; int g = (color >> 8) & 0xFF; int b = color & 0xFF; int V = Math.max(b, Math.max(r, g)); int temp = Math.min(b, Math.min(r, g)); float S; if (V == temp) { S = 0; } else { S = (V - temp) / (float) V; } return S; } /** * Returns the brightness component of a color int. * * @return A value between 0.0f and 1.0f * * @hide Pending API council */ public static float brightness(@ColorInt int color) { int r = (color >> 16) & 0xFF; int g = (color >> 8) & 0xFF; int b = color & 0xFF; int V = Math.max(b, Math.max(r, g)); return (V / 255.f); public static float luminance(@ColorInt int color) { double red = Color.red(color) / 255.0; red = red < 0.03928 ? red / 12.92 : Math.pow((red + 0.055) / 1.055, 2.4); double green = Color.green(color) / 255.0; green = green < 0.03928 ? green / 12.92 : Math.pow((green + 0.055) / 1.055, 2.4); double blue = Color.blue(color) / 255.0; blue = blue < 0.03928 ? blue / 12.92 : Math.pow((blue + 0.055) / 1.055, 2.4); return (float) ((0.2126 * red) + (0.7152 * green) + (0.0722 * blue)); } /** Loading