diff options
7 files changed, 529 insertions, 444 deletions
diff --git a/core/java/com/android/internal/colorextraction/ColorExtractor.java b/core/java/com/android/internal/colorextraction/ColorExtractor.java index 04819a5999eb..2648604291d9 100644 --- a/core/java/com/android/internal/colorextraction/ColorExtractor.java +++ b/core/java/com/android/internal/colorextraction/ColorExtractor.java @@ -51,7 +51,7 @@ public class ColorExtractor implements WallpaperManager.OnColorsChangedListener private WallpaperColors mLockColors; public ColorExtractor(Context context) { - this(context, new Tonal()); + this(context, new Tonal(context)); } @VisibleForTesting diff --git a/core/java/com/android/internal/colorextraction/types/Tonal.java b/core/java/com/android/internal/colorextraction/types/Tonal.java index e78ca3844bed..dbc086c21304 100644 --- a/core/java/com/android/internal/colorextraction/types/Tonal.java +++ b/core/java/com/android/internal/colorextraction/types/Tonal.java @@ -19,15 +19,22 @@ package com.android.internal.colorextraction.types; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.WallpaperColors; +import android.content.Context; import android.graphics.Color; import android.util.Log; import android.util.MathUtils; import android.util.Range; +import com.android.internal.R; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.colorextraction.ColorExtractor.GradientColors; import com.android.internal.graphics.ColorUtils; +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; + +import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -49,9 +56,23 @@ public class Tonal implements ExtractionType { public static final int MAIN_COLOR_DARK = 0xff212121; public static final int SECONDARY_COLOR_DARK = 0xff000000; + private final TonalPalette mGreyPalette; + private final ArrayList<TonalPalette> mTonalPalettes; + private final ArrayList<ColorRange> mBlacklistedColors; + // Temporary variable to avoid allocations private float[] mTmpHSL = new float[3]; + public Tonal(Context context) { + + ConfigParser parser = new ConfigParser(context); + mTonalPalettes = parser.getTonalPalettes(); + mBlacklistedColors = parser.getBlacklistedColors(); + + mGreyPalette = mTonalPalettes.get(0); + mTonalPalettes.remove(0); + } + /** * Grab colors from WallpaperColors and set them into GradientColors. * Also applies the default gradient in case extraction fails. @@ -220,7 +241,7 @@ public class Tonal implements ExtractionType { if (DEBUG) { Log.d(TAG, "Gradients: \n\tNormal " + outColorsNormal + "\n\tDark " + outColorsDark - + "\n\tExtra dark: " + outColorsExtraDark); + + "\n\tExtra dark: " + outColorsExtraDark); } return true; @@ -266,7 +287,8 @@ public class Tonal implements ExtractionType { * @return true if color should be avoided */ private boolean isBlacklisted(float[] hsl) { - for (ColorRange badRange: BLACKLISTED_COLORS) { + for (int i = mBlacklistedColors.size() - 1; i >= 0; i--) { + ColorRange badRange = mBlacklistedColors.get(i); if (badRange.containsColor(hsl[0], hsl[1], hsl[2])) { return true; } @@ -322,19 +344,25 @@ public class Tonal implements ExtractionType { return minErrorIndex; } + @VisibleForTesting + public List<ColorRange> getBlacklistedColors() { + return mBlacklistedColors; + } + @Nullable - private static TonalPalette findTonalPalette(float h, float s) { + private TonalPalette findTonalPalette(float h, float s) { // Fallback to a grey palette if the color is too desaturated. // This avoids hue shifts. if (s < 0.05f) { - return GREY_PALETTE; + return mGreyPalette; } TonalPalette best = null; float error = Float.POSITIVE_INFINITY; - for (int i = 0; i < TONAL_PALETTES.length; i++) { - final TonalPalette candidate = TONAL_PALETTES[i]; + final int tonalPalettesCount = mTonalPalettes.size(); + for (int i = 0; i < tonalPalettesCount; i++) { + final TonalPalette candidate = mTonalPalettes.get(i); if (h >= candidate.minHue && h <= candidate.maxHue) { best = candidate; @@ -388,7 +416,6 @@ public class Tonal implements ExtractionType { + Arrays.toString(h) + " s: " + Arrays.toString(s) + " l: " + Arrays.toString(l)); } - this.h = h; this.s = s; this.l = l; @@ -406,430 +433,6 @@ public class Tonal implements ExtractionType { } } - // Data definition of Material Design tonal palettes - // When the sort type is set to TONAL, these palettes are used to find - // a best fit. Each palette is defined as 22 HSL colors - private static final TonalPalette[] TONAL_PALETTES = { - new TonalPalette( - new float[] {1f, 1f, 0.991f, 0.991f, 0.9833333333333333f, 0f, 0f, 0f, - 0.01134380453752181f, 0.015625000000000003f, 0.024193548387096798f, - 0.027397260273972573f, 0.017543859649122865f}, - new float[] {1f, 1f, 1f, 1f, 1f, 1f, 1f, 0.8434782608695652f, 1f, 1f, 1f, 1f, - 1f}, - new float[] {0.04f, 0.09f, 0.14f, 0.2f, 0.27450980392156865f, - 0.34901960784313724f, 0.4235294117647059f, 0.5490196078431373f, - 0.6254901960784314f, 0.6862745098039216f, 0.7568627450980392f, - 0.8568627450980393f, 0.9254901960784314f} - ), - new TonalPalette( - new float[] {0.638f, 0.638f, 0.6385767790262171f, 0.6301169590643275f, - 0.6223958333333334f, 0.6151079136690647f, 0.6065400843881856f, - 0.5986964618249534f, 0.5910746812386157f, 0.5833333333333334f, - 0.5748031496062993f, 0.5582010582010583f}, - new float[] {1f, 1f, 1f, 1f, 0.9014084507042253f, 0.8128654970760234f, - 0.7979797979797981f, 0.7816593886462883f, 0.778723404255319f, 1f, 1f, - 1f}, - new float[] {0.05f, 0.12f, 0.17450980392156862f, 0.2235294117647059f, - 0.2784313725490196f, 0.3352941176470588f, 0.388235294117647f, - 0.44901960784313727f, 0.5392156862745098f, 0.6509803921568628f, - 0.7509803921568627f, 0.8764705882352941f} - ), - new TonalPalette( - new float[] {0.563f, 0.569f, 0.5666f, 0.5669934640522876f, 0.5748031496062993f, - 0.5595238095238095f, 0.5473118279569893f, 0.5393258426966292f, - 0.5315955766192734f, 0.524031007751938f, 0.5154711673699016f, - 0.508080808080808f, 0.5f}, - new float[] {1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 0.8847736625514403f, 1f, 1f, - 1f}, - new float[] {0.07f, 0.12f, 0.16f, 0.2f, 0.24901960784313726f, - 0.27450980392156865f, 0.30392156862745096f, 0.34901960784313724f, - 0.4137254901960784f, 0.47647058823529415f, 0.5352941176470588f, - 0.6764705882352942f, 0.8f} - ), - new TonalPalette( - new float[] {0.508f, 0.511f, 0.508f, 0.508f, 0.5082304526748972f, - 0.5069444444444444f, 0.5f, 0.5f, 0.5f, 0.48724954462659376f, - 0.4800347222222222f, 0.4755134281200632f, 0.4724409448818897f, - 0.4671052631578947f}, - new float[] {1f, 1f, 1f, 1f, 1f, 0.8888888888888887f, 0.9242424242424242f, 1f, - 1f, 0.8133333333333332f, 0.7868852459016393f, 1f, 1f, 1f}, - new float[] {0.04f, 0.06f, 0.08f, 0.12f, 0.1588235294117647f, - 0.21176470588235297f, 0.25882352941176473f, 0.3f, 0.34901960784313724f, - 0.44117647058823534f, 0.5215686274509804f, 0.5862745098039216f, - 0.7509803921568627f, 0.8509803921568627f} - ), - new TonalPalette( - new float[] {0.333f, 0.333f, 0.333f, 0.3333333333333333f, 0.3333333333333333f, - 0.34006734006734f, 0.34006734006734f, 0.34006734006734f, - 0.34259259259259256f, 0.3475783475783476f, 0.34767025089605735f, - 0.3467741935483871f, 0.3703703703703704f}, - new float[] {0.70f, 0.72f, 0.69f, 0.6703296703296703f, 0.728813559322034f, - 0.5657142857142856f, 0.5076923076923077f, 0.3944223107569721f, - 0.6206896551724138f, 0.8931297709923666f, 1f, 1f, 1f}, - new float[] {0.05f, 0.08f, 0.14f, 0.1784313725490196f, 0.23137254901960785f, - 0.3431372549019608f, 0.38235294117647056f, 0.49215686274509807f, - 0.6588235294117647f, 0.7431372549019608f, 0.8176470588235294f, - 0.8784313725490196f, 0.9294117647058824f} - ), - new TonalPalette( - new float[] {0.161f, 0.163f, 0.163f, 0.162280701754386f, 0.15032679738562088f, - 0.15879265091863518f, 0.16236559139784948f, 0.17443868739205526f, - 0.17824074074074076f, 0.18674698795180725f, 0.18692449355432778f, - 0.1946778711484594f, 0.18604651162790695f}, - new float[] {1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f}, - new float[] {0.05f, 0.08f, 0.11f, 0.14901960784313725f, 0.2f, - 0.24901960784313726f, 0.30392156862745096f, 0.3784313725490196f, - 0.4235294117647059f, 0.48823529411764705f, 0.6450980392156863f, - 0.7666666666666666f, 0.8313725490196078f} - ), - new TonalPalette( - new float[] {0.108f, 0.105f, 0.105f, 0.105f, 0.10619469026548674f, - 0.11924686192468618f, 0.13046448087431692f, 0.14248366013071895f, - 0.1506024096385542f, 0.16220238095238093f, 0.16666666666666666f, - 0.16666666666666666f, 0.162280701754386f, 0.15686274509803924f}, - new float[] {1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f}, - new float[] {0.17f, 0.22f, 0.28f, 0.35f, 0.44313725490196076f, - 0.46862745098039216f, 0.47843137254901963f, 0.5f, 0.5117647058823529f, - 0.5607843137254902f, 0.6509803921568628f, 0.7509803921568627f, - 0.8509803921568627f, 0.9f} - ), - new TonalPalette( - new float[] {0.036f, 0.036f, 0.036f, 0.036f, 0.03561253561253561f, - 0.05098039215686275f, 0.07516339869281045f, 0.09477124183006536f, - 0.1150326797385621f, 0.134640522875817f, 0.14640522875816991f, - 0.1582397003745319f, 0.15773809523809523f, 0.15359477124183002f}, - new float[] {1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f}, - new float[] {0.19f, 0.26f, 0.34f, 0.39f, 0.4588235294117647f, 0.5f, 0.5f, 0.5f, - 0.5f, 0.5f, 0.5f, 0.6509803921568628f, 0.7803921568627451f, 0.9f} - ), - new TonalPalette( - new float[] {0.955f, 0.961f, 0.958f, 0.9596491228070175f, 0.9593837535014005f, - 0.9514767932489452f, 0.943859649122807f, 0.9396825396825397f, - 0.9395424836601307f, 0.9393939393939394f, 0.9362745098039216f, - 0.9754098360655739f, 0.9824561403508771f}, - new float[] {0.87f, 0.85f, 0.85f, 0.84070796460177f, 0.8206896551724138f, - 0.7979797979797981f, 0.7661290322580644f, 0.9051724137931036f, - 1f, 1f, 1f, 1f, 1f}, - new float[] {0.06f, 0.11f, 0.16f, 0.22156862745098038f, 0.2843137254901961f, - 0.388235294117647f, 0.48627450980392156f, 0.5450980392156863f, - 0.6f, 0.6764705882352942f, 0.8f, 0.8803921568627451f, - 0.9254901960784314f} - ), - new TonalPalette( - new float[] {0.866f, 0.855f, 0.841025641025641f, 0.8333333333333334f, - 0.8285256410256411f, 0.821522309711286f, 0.8083333333333333f, - 0.8046594982078853f, 0.8005822416302766f, 0.7842377260981912f, - 0.7771084337349398f, 0.7747747747747749f}, - new float[] {1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, - 0.737142857142857f, 0.6434108527131781f, 0.46835443037974644f}, - new float[] {0.05f, 0.08f, 0.12745098039215685f, 0.15490196078431373f, - 0.20392156862745098f, 0.24901960784313726f, 0.3137254901960784f, - 0.36470588235294116f, 0.44901960784313727f, 0.6568627450980392f, - 0.7470588235294118f, 0.8450980392156863f} - ), - new TonalPalette( - new float[] {0.925f, 0.93f, 0.938f, 0.947f, 0.955952380952381f, - 0.9681069958847737f, 0.9760479041916167f, 0.9873563218390804f, 0f, 0f, - 0.009057971014492771f, 0.026748971193415648f, - 0.041666666666666616f, 0.05303030303030304f}, - new float[] {1f, 1f, 1f, 1f, 1f, 0.8350515463917526f, 0.6929460580912863f, - 0.6387665198237885f, 0.6914893617021276f, 0.7583892617449666f, - 0.8070175438596495f, 0.9310344827586209f, 1f, 1f}, - new float[] {0.10f, 0.13f, 0.17f, 0.2f, 0.27450980392156865f, - 0.3803921568627451f, 0.4725490196078432f, 0.5549019607843138f, - 0.6313725490196078f, 0.707843137254902f, 0.7764705882352941f, - 0.8294117647058823f, 0.9058823529411765f, 0.9568627450980391f} - ), - new TonalPalette( - new float[] {0.733f, 0.736f, 0.744f, 0.7514619883040936f, 0.7679738562091503f, - 0.7802083333333333f, 0.7844311377245509f, 0.796875f, - 0.8165618448637316f, 0.8487179487179487f, 0.8582375478927203f, - 0.8562091503267975f, 0.8666666666666667f}, - new float[] {1f, 1f, 1f, 1f, 1f, 0.8163265306122449f, 0.6653386454183268f, - 0.7547169811320753f, 0.929824561403509f, 0.9558823529411766f, - 0.9560439560439562f, 1f, 1f}, - new float[] {0.07f, 0.12f, 0.17f, 0.2235294117647059f, 0.3f, - 0.38431372549019605f, 0.492156862745098f, 0.5843137254901961f, - 0.6647058823529411f, 0.7333333333333334f, 0.8215686274509804f, 0.9f, - 0.9411764705882353f} - ), - new TonalPalette( - new float[] {0.6666666666666666f, 0.6666666666666666f, 0.6666666666666666f, - 0.6666666666666666f, 0.6666666666666666f, 0.6666666666666666f, - 0.6666666666666666f, 0.6666666666666666f, 0.6666666666666666f, - 0.6666666666666666f, 0.6666666666666666f}, - new float[] {0.25f, 0.24590163934426232f, 0.17880794701986752f, - 0.14606741573033713f, 0.13761467889908252f, 0.14893617021276592f, - 0.16756756756756758f, 0.20312500000000017f, 0.26086956521739135f, - 0.29999999999999966f, 0.5000000000000004f}, - new float[] {0.18f, 0.2392156862745098f, 0.296078431372549f, - 0.34901960784313724f, 0.4274509803921569f, 0.5392156862745098f, - 0.6372549019607843f, 0.7490196078431373f, 0.8196078431372549f, - 0.8823529411764706f, 0.9372549019607843f} - ), - new TonalPalette( - new float[] {0.938f, 0.944f, 0.952f, 0.961f, 0.9678571428571429f, - 0.9944812362030905f, 0f, 0f, - 0.0047348484848484815f, 0.00316455696202532f, 0f, - 0.9980392156862745f, 0.9814814814814816f, 0.9722222222222221f}, - new float[] {1f, 1f, 1f, 1f, 1f, 0.7023255813953488f, 0.6638655462184874f, - 0.6521739130434782f, 0.7719298245614035f, 0.8315789473684211f, - 0.6867469879518071f, 0.7264957264957265f, 0.8181818181818182f, - 0.8181818181818189f}, - new float[] {0.08f, 0.13f, 0.18f, 0.23f, 0.27450980392156865f, - 0.4215686274509804f, - 0.4666666666666667f, 0.503921568627451f, 0.5529411764705883f, - 0.6274509803921569f, 0.6745098039215687f, 0.7705882352941176f, - 0.892156862745098f, 0.9568627450980391f} - ), - new TonalPalette( - new float[] {0.88f, 0.888f, 0.897f, 0.9052287581699346f, 0.9112021857923498f, - 0.9270152505446624f, 0.9343137254901961f, 0.9391534391534391f, - 0.9437984496124031f, 0.943661971830986f, 0.9438943894389439f, - 0.9426229508196722f, 0.9444444444444444f}, - new float[] {1f, 1f, 1f, 1f, 0.8133333333333332f, 0.7927461139896375f, - 0.7798165137614679f, 0.7777777777777779f, 0.8190476190476191f, - 0.8255813953488372f, 0.8211382113821142f, 0.8133333333333336f, - 0.8000000000000006f}, - new float[] {0.08f, 0.12f, 0.16f, 0.2f, 0.29411764705882354f, - 0.3784313725490196f, 0.42745098039215684f, 0.4764705882352941f, - 0.5882352941176471f, 0.6627450980392157f, 0.7588235294117647f, - 0.8529411764705882f, 0.9411764705882353f} - ), - new TonalPalette( - new float[] {0.669f, 0.680f, 0.6884057971014492f, 0.6974789915966387f, - 0.7079889807162534f, 0.7154471544715447f, 0.7217741935483872f, - 0.7274143302180687f, 0.7272727272727273f, 0.7258064516129031f, - 0.7252252252252251f, 0.7333333333333333f}, - new float[] {0.81f, 0.81f, 0.8214285714285715f, 0.6878612716763006f, - 0.6080402010050251f, 0.5774647887323943f, 0.5391304347826086f, - 0.46724890829694316f, 0.4680851063829788f, 0.462686567164179f, - 0.45679012345678977f, 0.4545454545454551f}, - new float[] {0.12f, 0.16f, 0.2196078431372549f, 0.33921568627450976f, - 0.39019607843137255f, 0.4176470588235294f, 0.45098039215686275f, - 0.5509803921568628f, 0.6313725490196078f, 0.7372549019607844f, - 0.8411764705882353f, 0.9352941176470588f} - ), - new TonalPalette( - new float[] {0.6470588235294118f, 0.6516666666666667f, 0.6464174454828661f, - 0.6441441441441442f, 0.6432748538011696f, 0.6416666666666667f, - 0.6402439024390243f, 0.6412429378531074f, 0.6435185185185186f, - 0.6428571428571429f}, - new float[] {0.8095238095238095f, 0.6578947368421053f, 0.5721925133689839f, - 0.5362318840579711f, 0.5f, 0.4424778761061947f, 0.44086021505376327f, - 0.44360902255639095f, 0.4499999999999997f, 0.4375000000000006f}, - new float[] {0.16470588235294117f, 0.2980392156862745f, 0.36666666666666664f, - 0.40588235294117647f, 0.44705882352941173f, - 0.5568627450980392f, 0.6352941176470588f, 0.7392156862745098f, - 0.8431372549019608f, 0.9372549019607843f} - ), - new TonalPalette( - new float[] {0.469f, 0.46732026143790845f, 0.4718614718614719f, - 0.4793650793650794f, 0.48071625344352614f, 0.4829683698296837f, - 0.484375f, 0.4841269841269842f, 0.48444444444444457f, - 0.48518518518518516f, 0.4907407407407408f}, - new float[] {1f, 1f, 1f, 1f, 1f, 1f, 0.6274509803921569f, 0.41832669322709176f, - 0.41899441340782106f, 0.4128440366972478f, 0.4090909090909088f}, - new float[] {0.07f, 0.1f, 0.15098039215686274f, 0.20588235294117646f, - 0.2372549019607843f, 0.26862745098039215f, 0.4f, 0.5078431372549019f, - 0.6490196078431372f, 0.7862745098039216f, 0.9137254901960784f} - ), - new TonalPalette( - new float[] {0.542f, 0.5444444444444444f, 0.5555555555555556f, - 0.5555555555555556f, 0.553763440860215f, 0.5526315789473684f, - 0.5555555555555556f, 0.5555555555555555f, 0.5555555555555556f, - 0.5512820512820514f, 0.5666666666666667f}, - new float[] {0.25f, 0.24590163934426232f, 0.19148936170212766f, - 0.1791044776119403f, 0.18343195266272191f, 0.18446601941747576f, - 0.1538461538461539f, 0.15625000000000003f, 0.15328467153284678f, - 0.15662650602409653f, 0.151515151515151f}, - new float[] {0.05f, 0.1196078431372549f, 0.1843137254901961f, - 0.2627450980392157f, - 0.33137254901960783f, 0.403921568627451f, 0.5411764705882354f, - 0.6235294117647059f, 0.7313725490196079f, 0.8372549019607843f, - 0.9352941176470588f} - ), - new TonalPalette( - new float[] {0.022222222222222223f, 0.02469135802469136f, 0.031249999999999997f, - 0.03947368421052631f, 0.04166666666666668f, - 0.043650793650793655f, 0.04411764705882352f, 0.04166666666666652f, - 0.04444444444444459f, 0.05555555555555529f}, - new float[] {0.33333333333333337f, 0.2783505154639175f, 0.2580645161290323f, - 0.25675675675675674f, 0.2528735632183908f, 0.17500000000000002f, - 0.15315315315315312f, 0.15189873417721522f, - 0.15789473684210534f, 0.15789473684210542f}, - new float[] {0.08823529411764705f, 0.19019607843137254f, 0.2431372549019608f, - 0.2901960784313725f, 0.3411764705882353f, 0.47058823529411764f, - 0.5647058823529412f, 0.6901960784313725f, 0.8137254901960784f, - 0.9254901960784314f} - ), - new TonalPalette( - new float[] {0.027f, 0.03f, 0.038f, 0.044f, 0.050884955752212385f, - 0.07254901960784313f, 0.0934640522875817f, - 0.10457516339869281f, 0.11699346405228758f, - 0.1255813953488372f, 0.1268939393939394f, 0.12533333333333332f, - 0.12500000000000003f, 0.12777777777777777f}, - new float[] {1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f}, - new float[] {0.25f, 0.3f, 0.35f, 0.4f, 0.44313725490196076f, 0.5f, 0.5f, 0.5f, - 0.5f, 0.5784313725490196f, - 0.6549019607843137f, 0.7549019607843137f, 0.8509803921568627f, - 0.9411764705882353f} - ) - }; - - private static final TonalPalette GREY_PALETTE = new TonalPalette( - new float[]{0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f}, - new float[]{0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f}, - new float[]{0.08f, 0.11f, 0.14901960784313725f, 0.2f, 0.2980392156862745f, 0.4f, - 0.4980392156862745f, 0.6196078431372549f, 0.7176470588235294f, - 0.8196078431372549f, 0.9176470588235294f, 0.9490196078431372f} - ); - - @SuppressWarnings("WeakerAccess") - @VisibleForTesting - public static final ColorRange[] BLACKLISTED_COLORS = new ColorRange[] { - - // Red - new ColorRange( - new Range<>(0f, 20f) /* H */, - new Range<>(0.7f, 1f) /* S */, - new Range<>(0.21f, 0.79f)) /* L */, - new ColorRange( - new Range<>(0f, 20f), - new Range<>(0.3f, 0.7f), - new Range<>(0.355f, 0.653f)), - - // Red Orange - new ColorRange( - new Range<>(20f, 40f), - new Range<>(0.7f, 1f), - new Range<>(0.28f, 0.643f)), - new ColorRange( - new Range<>(20f, 40f), - new Range<>(0.3f, 0.7f), - new Range<>(0.414f, 0.561f)), - new ColorRange( - new Range<>(20f, 40f), - new Range<>(0f, 3f), - new Range<>(0.343f, 0.584f)), - - // Orange - new ColorRange( - new Range<>(40f, 60f), - new Range<>(0.7f, 1f), - new Range<>(0.173f, 0.349f)), - new ColorRange( - new Range<>(40f, 60f), - new Range<>(0.3f, 0.7f), - new Range<>(0.233f, 0.427f)), - new ColorRange( - new Range<>(40f, 60f), - new Range<>(0f, 0.3f), - new Range<>(0.231f, 0.484f)), - - // Yellow 60 - new ColorRange( - new Range<>(60f, 80f), - new Range<>(0.7f, 1f), - new Range<>(0.488f, 0.737f)), - new ColorRange( - new Range<>(60f, 80f), - new Range<>(0.3f, 0.7f), - new Range<>(0.673f, 0.837f)), - - // Yellow Green 80 - new ColorRange( - new Range<>(80f, 100f), - new Range<>(0.7f, 1f), - new Range<>(0.469f, 0.61f)), - - // Yellow green 100 - new ColorRange( - new Range<>(100f, 120f), - new Range<>(0.7f, 1f), - new Range<>(0.388f, 0.612f)), - new ColorRange( - new Range<>(100f, 120f), - new Range<>(0.3f, 0.7f), - new Range<>(0.424f, 0.541f)), - - // Green - new ColorRange( - new Range<>(120f, 140f), - new Range<>(0.7f, 1f), - new Range<>(0.375f, 0.52f)), - new ColorRange( - new Range<>(120f, 140f), - new Range<>(0.3f, 0.7f), - new Range<>(0.435f, 0.524f)), - - // Green Blue 140 - new ColorRange( - new Range<>(140f, 160f), - new Range<>(0.7f, 1f), - new Range<>(0.496f, 0.641f)), - - // Seafoam - new ColorRange( - new Range<>(160f, 180f), - new Range<>(0.7f, 1f), - new Range<>(0.496f, 0.567f)), - - // Cyan - new ColorRange( - new Range<>(180f, 200f), - new Range<>(0.7f, 1f), - new Range<>(0.52f, 0.729f)), - - // Blue - new ColorRange( - new Range<>(220f, 240f), - new Range<>(0.7f, 1f), - new Range<>(0.396f, 0.571f)), - new ColorRange( - new Range<>(220f, 240f), - new Range<>(0.3f, 0.7f), - new Range<>(0.425f, 0.551f)), - - // Blue Purple 240 - new ColorRange( - new Range<>(240f, 260f), - new Range<>(0.7f, 1f), - new Range<>(0.418f, 0.639f)), - new ColorRange( - new Range<>(220f, 240f), - new Range<>(0.3f, 0.7f), - new Range<>(0.441f, 0.576f)), - - // Blue Purple 260 - new ColorRange( - new Range<>(260f, 280f), - new Range<>(0.3f, 1f), // Bigger range - new Range<>(0.461f, 0.553f)), - - // Fuchsia - new ColorRange( - new Range<>(300f, 320f), - new Range<>(0.7f, 1f), - new Range<>(0.484f, 0.588f)), - new ColorRange( - new Range<>(300f, 320f), - new Range<>(0.3f, 0.7f), - new Range<>(0.48f, 0.592f)), - - // Pink - new ColorRange( - new Range<>(320f, 340f), - new Range<>(0.7f, 1f), - new Range<>(0.466f, 0.629f)), - - // Soft red - new ColorRange( - new Range<>(340f, 360f), - new Range<>(0.7f, 1f), - new Range<>(0.437f, 0.596f)) - }; - /** * Representation of an HSL color range. * <ul> @@ -874,4 +477,124 @@ public class Tonal implements ExtractionType { return String.format("H: %s, S: %s, L %s", mHue, mSaturation, mLightness); } } -} + + @VisibleForTesting + public static class ConfigParser { + private final ArrayList<TonalPalette> mTonalPalettes; + private final ArrayList<ColorRange> mBlacklistedColors; + + public ConfigParser(Context context) { + mTonalPalettes = new ArrayList<>(); + mBlacklistedColors = new ArrayList<>(); + + // Load all palettes and the blacklist from an XML. + try { + XmlPullParser parser = context.getResources().getXml(R.xml.color_extraction); + int eventType = parser.getEventType(); + while (eventType != XmlPullParser.END_DOCUMENT) { + if (eventType == XmlPullParser.START_DOCUMENT || + eventType == XmlPullParser.END_TAG) { + // just skip + } else if (eventType == XmlPullParser.START_TAG) { + String tagName = parser.getName(); + if (tagName.equals("palettes")) { + parsePalettes(parser); + } else if (tagName.equals("blacklist")) { + parseBlacklist(parser); + } + } else { + throw new XmlPullParserException("Invalid XML event " + eventType + " - " + + parser.getName(), parser, null); + } + eventType = parser.next(); + } + } catch (XmlPullParserException | IOException e) { + throw new RuntimeException(e); + } + } + + public ArrayList<TonalPalette> getTonalPalettes() { + return mTonalPalettes; + } + + public ArrayList<ColorRange> getBlacklistedColors() { + return mBlacklistedColors; + } + + private void parseBlacklist(XmlPullParser parser) + throws XmlPullParserException, IOException { + parser.require(XmlPullParser.START_TAG, null, "blacklist"); + while (parser.next() != XmlPullParser.END_TAG) { + if (parser.getEventType() != XmlPullParser.START_TAG) { + continue; + } + String name = parser.getName(); + // Starts by looking for the entry tag + if (name.equals("range")) { + mBlacklistedColors.add(readRange(parser)); + parser.next(); + } else { + throw new XmlPullParserException("Invalid tag: " + name, parser, null); + } + } + } + + private ColorRange readRange(XmlPullParser parser) + throws XmlPullParserException, IOException { + parser.require(XmlPullParser.START_TAG, null, "range"); + float[] h = readFloatArray(parser.getAttributeValue(null, "h")); + float[] s = readFloatArray(parser.getAttributeValue(null, "s")); + float[] l = readFloatArray(parser.getAttributeValue(null, "l")); + + if (h == null || s == null || l == null) { + throw new XmlPullParserException("Incomplete range tag.", parser, null); + } + + return new ColorRange(new Range<>(h[0], h[1]), new Range<>(s[0], s[1]), + new Range<>(l[0], l[1])); + } + + private void parsePalettes(XmlPullParser parser) + throws XmlPullParserException, IOException { + parser.require(XmlPullParser.START_TAG, null, "palettes"); + while (parser.next() != XmlPullParser.END_TAG) { + if (parser.getEventType() != XmlPullParser.START_TAG) { + continue; + } + String name = parser.getName(); + // Starts by looking for the entry tag + if (name.equals("palette")) { + mTonalPalettes.add(readPalette(parser)); + parser.next(); + } else { + throw new XmlPullParserException("Invalid tag: " + name); + } + } + } + + private TonalPalette readPalette(XmlPullParser parser) + throws XmlPullParserException, IOException { + parser.require(XmlPullParser.START_TAG, null, "palette"); + + float[] h = readFloatArray(parser.getAttributeValue(null, "h")); + float[] s = readFloatArray(parser.getAttributeValue(null, "s")); + float[] l = readFloatArray(parser.getAttributeValue(null, "l")); + + if (h == null || s == null || l == null) { + throw new XmlPullParserException("Incomplete range tag.", parser, null); + } + + return new TonalPalette(h, s, l); + } + + private float[] readFloatArray(String attributeValue) + throws IOException, XmlPullParserException { + String[] tokens = attributeValue.replaceAll(" ", "").replaceAll("\n", "").split(","); + float[] numbers = new float[tokens.length]; + for (int i = 0; i < tokens.length; i++) { + numbers[i] = Float.parseFloat(tokens[i]); + } + return numbers; + } + } +}
\ No newline at end of file diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 2d7a5d34ddd0..2f81f43024d6 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -1485,6 +1485,7 @@ <java-symbol type="xml" name="global_keys" /> <java-symbol type="xml" name="default_zen_mode_config" /> <java-symbol type="xml" name="sms_7bit_translation_table" /> + <java-symbol type="xml" name="color_extraction" /> <java-symbol type="raw" name="color_fade_vert" /> <java-symbol type="raw" name="color_fade_frag" /> diff --git a/core/res/res/xml/color_extraction.xml b/core/res/res/xml/color_extraction.xml new file mode 100644 index 000000000000..7d52b20f7614 --- /dev/null +++ b/core/res/res/xml/color_extraction.xml @@ -0,0 +1,348 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2017 The Android Open Source Project + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License + --> + +<colorextraction> + <!-- List of material color palettes in HSL --> + <palettes> + <!-- Grey scale --> + <palette h="0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f" + s="0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f" + l="0.08f, 0.11f, 0.14901960784313725f, 0.2f, 0.2980392156862745f, 0.4f, + 0.4980392156862745f, 0.6196078431372549f, 0.7176470588235294f, + 0.8196078431372549f, 0.9176470588235294f, 0.9490196078431372f"/> + <!-- All colors --> + <palette h="1,1,0.991,0.991,0.9833333333333333,0,0,0, + 0.01134380453752181,0.015625000000000003,0.024193548387096798, + 0.027397260273972573,0.017543859649122865" + s="1,1,1,1,1,1,1,0.8434782608695652,1,1,1,1,1" + l="0.04,0.09,0.14,0.2,0.27450980392156865, + 0.34901960784313724,0.4235294117647059,0.5490196078431373, + 0.6254901960784314,0.6862745098039216,0.7568627450980392, + 0.8568627450980393,0.9254901960784314"/> + <palette h="0.638,0.638,0.6385767790262171,0.6301169590643275, + 0.6223958333333334,0.6151079136690647,0.6065400843881856, + 0.5986964618249534,0.5910746812386157,0.5833333333333334, + 0.5748031496062993,0.5582010582010583" + s="1,1,1,1,0.9014084507042253,0.8128654970760234, + 0.7979797979797981,0.7816593886462883,0.778723404255319,1,1,1" + l="0.05,0.12,0.17450980392156862,0.2235294117647059, + 0.2784313725490196,0.3352941176470588,0.388235294117647, + 0.44901960784313727,0.5392156862745098,0.6509803921568628, + 0.7509803921568627,0.8764705882352941"/> + <palette h="0.563,0.569,0.5666,0.5669934640522876,0.5748031496062993, + 0.5595238095238095,0.5473118279569893,0.5393258426966292, + 0.5315955766192734,0.524031007751938,0.5154711673699016, + 0.508080808080808,0.5" + s="1,1,1,1,1,1,1,1,1,0.8847736625514403,1,1,1" + l="0.07,0.12,0.16,0.2,0.24901960784313726, + 0.27450980392156865,0.30392156862745096,0.34901960784313724, + 0.4137254901960784,0.47647058823529415,0.5352941176470588, + 0.6764705882352942,0.8"/> + <palette h="0.508,0.511,0.508,0.508,0.5082304526748972, + 0.5069444444444444,0.5,0.5,0.5,0.48724954462659376, + 0.4800347222222222,0.4755134281200632,0.4724409448818897, + 0.4671052631578947" + s="1,1,1,1,1,0.8888888888888887,0.9242424242424242,1, + 1,0.8133333333333332,0.7868852459016393,1,1,1" + l="0.04,0.06,0.08,0.12,0.1588235294117647, + 0.21176470588235297,0.25882352941176473,0.3,0.34901960784313724, + 0.44117647058823534,0.5215686274509804,0.5862745098039216, + 0.7509803921568627,0.8509803921568627"/> + <palette h="0.333,0.333,0.333,0.3333333333333333,0.3333333333333333, + 0.34006734006734,0.34006734006734,0.34006734006734, + 0.34259259259259256,0.3475783475783476,0.34767025089605735, + 0.3467741935483871,0.3703703703703704" + s="0.70,0.72,0.69,0.6703296703296703,0.728813559322034, + 0.5657142857142856,0.5076923076923077,0.3944223107569721, + 0.6206896551724138,0.8931297709923666,1,1,1" + l="0.05,0.08,0.14,0.1784313725490196,0.23137254901960785, + 0.3431372549019608,0.38235294117647056,0.49215686274509807, + 0.6588235294117647,0.7431372549019608,0.8176470588235294, + 0.8784313725490196,0.9294117647058824"/> + <palette h="0.161,0.163,0.163,0.162280701754386,0.15032679738562088, + 0.15879265091863518,0.16236559139784948,0.17443868739205526, + 0.17824074074074076,0.18674698795180725,0.18692449355432778, + 0.1946778711484594,0.18604651162790695" + s="1,1,1,1,1,1,1,1,1,1,1,1,1" + l="0.05,0.08,0.11,0.14901960784313725,0.2, + 0.24901960784313726,0.30392156862745096,0.3784313725490196, + 0.4235294117647059,0.48823529411764705,0.6450980392156863, + 0.7666666666666666,0.8313725490196078"/> + <palette h="0.108,0.105,0.105,0.105,0.10619469026548674, + 0.11924686192468618,0.13046448087431692,0.14248366013071895, + 0.1506024096385542,0.16220238095238093,0.16666666666666666, + 0.16666666666666666,0.162280701754386,0.15686274509803924" + s="1,1,1,1,1,1,1,1,1,1,1,1,1,1" + l="0.17,0.22,0.28,0.35,0.44313725490196076, + 0.46862745098039216,0.47843137254901963,0.5,0.5117647058823529, + 0.5607843137254902,0.6509803921568628,0.7509803921568627, + 0.8509803921568627,0.9"/> + <palette h="0.036,0.036,0.036,0.036,0.03561253561253561, + 0.05098039215686275,0.07516339869281045,0.09477124183006536, + 0.1150326797385621,0.134640522875817,0.14640522875816991, + 0.1582397003745319,0.15773809523809523,0.15359477124183002" + s="1,1,1,1,1,1,1,1,1,1,1,1,1,1" + l="0.19,0.26,0.34,0.39,0.4588235294117647,0.5,0.5,0.5, + 0.5,0.5,0.5,0.6509803921568628,0.7803921568627451,0.9"/> + <palette h="0.955,0.961,0.958,0.9596491228070175,0.9593837535014005, + 0.9514767932489452,0.943859649122807,0.9396825396825397, + 0.9395424836601307,0.9393939393939394,0.9362745098039216, + 0.9754098360655739,0.9824561403508771" + s="0.87,0.85,0.85,0.84070796460177,0.8206896551724138, + 0.7979797979797981,0.7661290322580644,0.9051724137931036, + 1,1,1,1,1" + l="0.06,0.11,0.16,0.22156862745098038,0.2843137254901961, + 0.388235294117647,0.48627450980392156,0.5450980392156863, + 0.6,0.6764705882352942,0.8,0.8803921568627451, + 0.9254901960784314"/> + <palette h="0.866,0.855,0.841025641025641,0.8333333333333334, + 0.8285256410256411,0.821522309711286,0.8083333333333333, + 0.8046594982078853,0.8005822416302766,0.7842377260981912, + 0.7771084337349398,0.7747747747747749" + s="1,1,1,1,1,1,1,1,1, + 0.737142857142857,0.6434108527131781,0.46835443037974644" + l="0.05,0.08,0.12745098039215685,0.15490196078431373, + 0.20392156862745098,0.24901960784313726,0.3137254901960784, + 0.36470588235294116,0.44901960784313727,0.6568627450980392, + 0.7470588235294118,0.8450980392156863"/> + <palette h="0.925,0.93,0.938,0.947,0.955952380952381, + 0.9681069958847737,0.9760479041916167,0.9873563218390804,0,0, + 0.009057971014492771,0.026748971193415648, + 0.041666666666666616,0.05303030303030304" + s="1,1,1,1,1,0.8350515463917526,0.6929460580912863, + 0.6387665198237885,0.6914893617021276,0.7583892617449666, + 0.8070175438596495,0.9310344827586209,1,1" + l="0.10,0.13,0.17,0.2,0.27450980392156865, + 0.3803921568627451,0.4725490196078432,0.5549019607843138, + 0.6313725490196078,0.707843137254902,0.7764705882352941, + 0.8294117647058823,0.9058823529411765,0.9568627450980391"/> + <palette h="0.733,0.736,0.744,0.7514619883040936,0.7679738562091503, + 0.7802083333333333,0.7844311377245509,0.796875, + 0.8165618448637316,0.8487179487179487,0.8582375478927203, + 0.8562091503267975,0.8666666666666667" + s="1,1,1,1,1,0.8163265306122449,0.6653386454183268, + 0.7547169811320753,0.929824561403509,0.9558823529411766, + 0.9560439560439562,1,1" + l="0.07,0.12,0.17,0.2235294117647059,0.3, + 0.38431372549019605,0.492156862745098,0.5843137254901961, + 0.6647058823529411,0.7333333333333334,0.8215686274509804,0.9, + 0.9411764705882353"/> + <palette h="0.6666666666666666,0.6666666666666666,0.6666666666666666, + 0.6666666666666666,0.6666666666666666,0.6666666666666666, + 0.6666666666666666,0.6666666666666666,0.6666666666666666, + 0.6666666666666666,0.6666666666666666" + s="0.25,0.24590163934426232,0.17880794701986752, + 0.14606741573033713,0.13761467889908252,0.14893617021276592, + 0.16756756756756758,0.20312500000000017,0.26086956521739135, + 0.29999999999999966,0.5000000000000004" + l="0.18,0.2392156862745098,0.296078431372549, + 0.34901960784313724,0.4274509803921569,0.5392156862745098, + 0.6372549019607843,0.7490196078431373,0.8196078431372549, + 0.8823529411764706,0.9372549019607843"/> + <palette h="0.938,0.944,0.952,0.961,0.9678571428571429, + 0.9944812362030905,0,0, + 0.0047348484848484815,0.00316455696202532,0, + 0.9980392156862745,0.9814814814814816,0.9722222222222221" + s="1,1,1,1,1,0.7023255813953488,0.6638655462184874, + 0.6521739130434782,0.7719298245614035,0.8315789473684211, + 0.6867469879518071,0.7264957264957265,0.8181818181818182, + 0.8181818181818189" + l="0.08,0.13,0.18,0.23,0.27450980392156865, + 0.4215686274509804, + 0.4666666666666667,0.503921568627451,0.5529411764705883, + 0.6274509803921569,0.6745098039215687,0.7705882352941176, + 0.892156862745098,0.9568627450980391"/> + <palette h="0.88,0.888,0.897,0.9052287581699346,0.9112021857923498, + 0.9270152505446624,0.9343137254901961,0.9391534391534391, + 0.9437984496124031,0.943661971830986,0.9438943894389439, + 0.9426229508196722,0.9444444444444444" + s="1,1,1,1,0.8133333333333332,0.7927461139896375, + 0.7798165137614679,0.7777777777777779,0.8190476190476191, + 0.8255813953488372,0.8211382113821142,0.8133333333333336, + 0.8000000000000006" + l="0.08,0.12,0.16,0.2,0.29411764705882354, + 0.3784313725490196,0.42745098039215684,0.4764705882352941, + 0.5882352941176471,0.6627450980392157,0.7588235294117647, + 0.8529411764705882,0.9411764705882353"/> + <palette h="0.669,0.680,0.6884057971014492,0.6974789915966387, + 0.7079889807162534,0.7154471544715447,0.7217741935483872, + 0.7274143302180687,0.7272727272727273,0.7258064516129031, + 0.7252252252252251,0.7333333333333333" + s="0.81,0.81,0.8214285714285715,0.6878612716763006, + 0.6080402010050251,0.5774647887323943,0.5391304347826086, + 0.46724890829694316,0.4680851063829788,0.462686567164179, + 0.45679012345678977,0.4545454545454551" + l="0.12,0.16,0.2196078431372549,0.33921568627450976, + 0.39019607843137255,0.4176470588235294,0.45098039215686275, + 0.5509803921568628,0.6313725490196078,0.7372549019607844, + 0.8411764705882353,0.9352941176470588"/> + <palette h="0.6470588235294118,0.6516666666666667,0.6464174454828661, + 0.6441441441441442,0.6432748538011696,0.6416666666666667, + 0.6402439024390243,0.6412429378531074,0.6435185185185186, + 0.6428571428571429" + s="0.8095238095238095,0.6578947368421053,0.5721925133689839, + 0.5362318840579711,0.5,0.4424778761061947,0.44086021505376327, + 0.44360902255639095,0.4499999999999997,0.4375000000000006" + l="0.16470588235294117,0.2980392156862745,0.36666666666666664, + 0.40588235294117647,0.44705882352941173, + 0.5568627450980392,0.6352941176470588,0.7392156862745098, + 0.8431372549019608,0.9372549019607843"/> + <palette h="0.469,0.46732026143790845,0.4718614718614719, + 0.4793650793650794,0.48071625344352614,0.4829683698296837, + 0.484375,0.4841269841269842,0.48444444444444457, + 0.48518518518518516,0.4907407407407408" + s="1,1,1,1,1,1,0.6274509803921569,0.41832669322709176, + 0.41899441340782106,0.4128440366972478,0.4090909090909088" + l="0.07,0.1,0.15098039215686274,0.20588235294117646, + 0.2372549019607843,0.26862745098039215,0.4,0.5078431372549019, + 0.6490196078431372,0.7862745098039216,0.9137254901960784"/> + <palette h="0.542,0.5444444444444444,0.5555555555555556, + 0.5555555555555556,0.553763440860215,0.5526315789473684, + 0.5555555555555556,0.5555555555555555,0.5555555555555556, + 0.5512820512820514,0.5666666666666667" + s="0.25,0.24590163934426232,0.19148936170212766, + 0.1791044776119403,0.18343195266272191,0.18446601941747576, + 0.1538461538461539,0.15625000000000003,0.15328467153284678, + 0.15662650602409653,0.151515151515151" + l="0.05,0.1196078431372549,0.1843137254901961, + 0.2627450980392157, + 0.33137254901960783,0.403921568627451,0.5411764705882354, + 0.6235294117647059,0.7313725490196079,0.8372549019607843, + 0.9352941176470588"/> + <palette h="0.022222222222222223,0.02469135802469136,0.031249999999999997, + 0.03947368421052631,0.04166666666666668, + 0.043650793650793655,0.04411764705882352,0.04166666666666652, + 0.04444444444444459,0.05555555555555529" + s="0.33333333333333337,0.2783505154639175,0.2580645161290323, + 0.25675675675675674,0.2528735632183908,0.17500000000000002, + 0.15315315315315312,0.15189873417721522, + 0.15789473684210534,0.15789473684210542" + l="0.08823529411764705,0.19019607843137254,0.2431372549019608, + 0.2901960784313725,0.3411764705882353,0.47058823529411764, + 0.5647058823529412,0.6901960784313725,0.8137254901960784, + 0.9254901960784314"/> + <palette h="0.027,0.03,0.038,0.044,0.050884955752212385, + 0.07254901960784313,0.0934640522875817, + 0.10457516339869281,0.11699346405228758, + 0.1255813953488372,0.1268939393939394,0.12533333333333332, + 0.12500000000000003,0.12777777777777777" + s="1,1,1,1,1,1,1,1,1,1,1,1,1,1" + l="0.25,0.3,0.35,0.4,0.44313725490196076,0.5,0.5,0.5, + 0.5,0.5784313725490196, + 0.6549019607843137,0.7549019607843137,0.8509803921568627, + 0.9411764705882353"/> + </palettes> + <blacklist> + <!-- Red --> + <range h="0, 20" + s="0.7, 1" + l="0.21, 0.79"/> + <range h="0, 20" + s="0.3, 0.7" + l="0.355, 0.653"/> + <!-- Red Orange --> + <range h="20, 40" + s="0.7, 1" + l="0.28, 0.643"/> + <range h="20, 40" + s="0.3, 0.7" + l="0.414, 0.561"/> + <range h="20, 40" + s="0, 3" + l="0.343, 0.584"/> + <!-- Orange --> + <range h="40, 60" + s="0.7, 1" + l="0.173, 0.349"/> + <range h="40, 60" + s="0.3, 0.7" + l="0.233, 0.427"/> + <range h="40, 60" + s="0, 0.3" + l="0.231, 0.484"/> + <!-- Yellow 60 --> + <range h="60, 80" + s="0.7, 1" + l="0.488, 0.737"/> + <range h="60, 80" + s="0.3, 0.7" + l="0.673, 0.837"/> + <!-- Yellow Green 80 --> + <range h="80, 100" + s="0.7, 1" + l="0.469, 0.61"/> + <!-- Yellow green 100 --> + <range h="100, 120" + s="0.7, 1" + l="0.388, 0.612"/> + <range h="100, 120" + s="0.3, 0.7" + l="0.424, 0.541"/> + <!-- Green --> + <range h="120, 140" + s="0.7, 1" + l="0.375, 0.52"/> + <range h="120, 140" + s="0.3, 0.7" + l="0.435, 0.524"/> + <!-- Green Blue 140 --> + <range h="140, 160" + s="0.7, 1" + l="0.496, 0.641"/> + <!-- Seaoam --> + <range h="160, 180" + s="0.7, 1" + l="0.496, 0.567"/> + <!-- Cyan --> + <range h="180, 200" + s="0.7, 1" + l="0.52, 0.729"/> + <!-- Blue --> + <range h="220, 240" + s="0.7, 1" + l="0.396, 0.571"/> + <range h="220, 240" + s="0.3, 0.7" + l="0.425, 0.551"/> + <!-- Blue Purple 240 --> + <range h="240, 260" + s="0.7, 1" + l="0.418, 0.639"/> + <range h="220, 240" + s="0.3, 0.7" + l="0.441, 0.576"/> + <!-- Blue Purple 260 --> + <range h="260, 280" + s="0.3, 1" + l="0.461, 0.553"/> + <!-- Fuchsia --> + <range h="300, 320" + s="0.7, 1" + l="0.484, 0.588"/> + <range h="300, 320" + s="0.3, 0.7" + l="0.48, 0.592"/> + <!-- Pink --> + <range h="320, 340" + s="0.7, 1" + l="0.466, 0.629"/> + <!-- Soft red --> + <range h="340, 360" + s="0.7, 1" + l="0.437, 0.596"/> + </blacklist> +</colorextraction>
\ No newline at end of file diff --git a/packages/SystemUI/src/com/android/systemui/colorextraction/SysuiColorExtractor.java b/packages/SystemUI/src/com/android/systemui/colorextraction/SysuiColorExtractor.java index 3c895abd5e88..44cf003b3dcb 100644 --- a/packages/SystemUI/src/com/android/systemui/colorextraction/SysuiColorExtractor.java +++ b/packages/SystemUI/src/com/android/systemui/colorextraction/SysuiColorExtractor.java @@ -42,7 +42,7 @@ public class SysuiColorExtractor extends ColorExtractor { private final GradientColors mWpHiddenColors; public SysuiColorExtractor(Context context) { - this(context, new Tonal(), true); + this(context, new Tonal(context), true); } @VisibleForTesting diff --git a/packages/SystemUI/tests/src/com/android/systemui/colorextraction/SysuiColorExtractorTests.java b/packages/SystemUI/tests/src/com/android/systemui/colorextraction/SysuiColorExtractorTests.java index 690186e91f55..d0f0bfd88883 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/colorextraction/SysuiColorExtractorTests.java +++ b/packages/SystemUI/tests/src/com/android/systemui/colorextraction/SysuiColorExtractorTests.java @@ -48,7 +48,8 @@ public class SysuiColorExtractorTests extends SysuiTestCase { @Test public void getColors_usesGreyIfWallpaperNotVisible() { - SysuiColorExtractor extractor = new SysuiColorExtractor(getContext(), new Tonal(), false); + SysuiColorExtractor extractor = new SysuiColorExtractor(getContext(), + new Tonal(getContext()), false); simulateEvent(extractor); extractor.setWallpaperVisible(false); diff --git a/tests/Internal/src/com/android/internal/colorextraction/types/TonalTest.java b/tests/Internal/src/com/android/internal/colorextraction/types/TonalTest.java index d408b84109bc..6dc9ba7b621f 100644 --- a/tests/Internal/src/com/android/internal/colorextraction/types/TonalTest.java +++ b/tests/Internal/src/com/android/internal/colorextraction/types/TonalTest.java @@ -20,6 +20,7 @@ import static org.junit.Assert.assertTrue; import android.app.WallpaperColors; import android.graphics.Color; +import android.support.test.InstrumentationRegistry; import android.support.test.filters.SmallTest; import android.support.test.runner.AndroidJUnit4; import android.util.Range; @@ -42,7 +43,7 @@ public class TonalTest { @Test public void extractInto_usesFallback() { GradientColors normal = new GradientColors(); - Tonal tonal = new Tonal(); + Tonal tonal = new Tonal(InstrumentationRegistry.getContext()); tonal.extractInto(null, normal, new GradientColors(), new GradientColors()); assertFalse("Should use fallback color if WallpaperColors is null.", @@ -52,13 +53,14 @@ public class TonalTest { @Test public void extractInto_usesFallbackWhenTooLightOrDark() { GradientColors normal = new GradientColors(); - Tonal tonal = new Tonal(); + Tonal tonal = new Tonal(InstrumentationRegistry.getContext()); tonal.extractInto(new WallpaperColors(Color.valueOf(0xff000000), null, null, 0), normal, new GradientColors(), new GradientColors()); assertTrue("Should use fallback color if WallpaperColors is too dark.", normal.getMainColor() == Tonal.MAIN_COLOR_DARK); - tonal.extractInto(new WallpaperColors(Color.valueOf(0xffffffff), null, null, 0), + tonal.extractInto(new WallpaperColors(Color.valueOf(0xffffffff), null, null, + WallpaperColors.HINT_SUPPORTS_DARK_TEXT), normal, new GradientColors(), new GradientColors()); assertTrue("Should use fallback color if WallpaperColors is too light.", normal.getMainColor() == Tonal.MAIN_COLOR_LIGHT); @@ -89,18 +91,28 @@ public class TonalTest { } @Test - public void colorRange_excludeBlacklistedColor() { - // Creating a WallpaperColors object that contains *only* blacklisted colors - float[] hsl = Tonal.BLACKLISTED_COLORS[0].getCenter(); + public void configParser_dataSanity() { + Tonal.ConfigParser config = new Tonal.ConfigParser(InstrumentationRegistry.getContext()); + // 1 to avoid regression where only first item would be parsed. + assertTrue("Tonal palettes are empty", config.getTonalPalettes().size() > 1); + assertTrue("Blacklisted colors are empty", config.getBlacklistedColors().size() > 1); + } + + @Test + public void tonal_excludeBlacklistedColor() { + // Make sure that palette generation will fail. + Tonal tonal = new Tonal(InstrumentationRegistry.getContext()); + + // Creating a WallpaperColors object that contains *only* blacklisted colors. + float[] hsl = tonal.getBlacklistedColors().get(0).getCenter(); WallpaperColors colors = new WallpaperColors(Color.valueOf(ColorUtils.HSLToColor(hsl)), null, null, 0); // Make sure that palette generation will fail - Tonal tonal = new Tonal(); GradientColors normal = new GradientColors(); tonal.extractInto(colors, normal, new GradientColors(), new GradientColors()); - assertFalse("Cannot generate a tonal palette from blacklisted colors.", - normal.getMainColor() == Tonal.MAIN_COLOR_LIGHT); + assertTrue("Cannot generate a tonal palette from blacklisted colors.", + normal.getMainColor() == Tonal.MAIN_COLOR_DARK); } } |