Loading core/java/android/content/res/ColorStateList.java +3 −3 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.util.Xml; import com.android.internal.R; import com.android.internal.graphics.ColorUtils; import com.android.internal.graphics.cam.Cam; import com.android.internal.util.ArrayUtils; import com.android.internal.util.GrowingArrayUtils; Loading Loading @@ -555,9 +556,8 @@ public class ColorStateList extends ComplexColor implements Parcelable { final int alpha = MathUtils.constrain((int) (baseAlpha * alphaMod + 0.5f), 0, 255); if (validLStar) { final double[] labColor = new double[3]; ColorUtils.colorToLAB(baseColor, labColor); baseColor = ColorUtils.LABToColor(lStar, labColor[1], labColor[2]); final Cam baseCam = ColorUtils.colorToCAM(baseColor); baseColor = ColorUtils.CAMToColor(baseCam.getHue(), baseCam.getChroma(), lStar); } return (baseColor & 0xFFFFFF) | (alpha << 24); Loading core/tests/coretests/res/color/color_with_lstar.xml 0 → 100644 +20 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- ~ Copyright (C) 2021 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. --> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:color="#ff0000" android:lStar="50" /> </selector> core/tests/coretests/res/values/colors.xml +1 −0 Original line number Diff line number Diff line Loading @@ -25,5 +25,6 @@ <drawable name="yellow">#ffffff00</drawable> <color name="testcolor1">#ff00ff00</color> <color name="testcolor2">#ffff0000</color> <color name="testcolor3">#fff00000</color> <color name="failColor">#ff0000ff</color> </resources> core/tests/coretests/src/android/graphics/ColorStateListTest.java +6 −0 Original line number Diff line number Diff line Loading @@ -67,4 +67,10 @@ public class ColorStateListTest extends AndroidTestCase { int defaultColor = mResources.getColor(R.color.color_no_default); assertEquals(mResources.getColor(R.color.testcolor1), defaultColor); } @SmallTest public void testLstar() throws Exception { int defaultColor = mResources.getColor(R.color.color_with_lstar); assertEquals(mResources.getColor(R.color.testcolor3), defaultColor); } } Loading
core/java/android/content/res/ColorStateList.java +3 −3 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.util.Xml; import com.android.internal.R; import com.android.internal.graphics.ColorUtils; import com.android.internal.graphics.cam.Cam; import com.android.internal.util.ArrayUtils; import com.android.internal.util.GrowingArrayUtils; Loading Loading @@ -555,9 +556,8 @@ public class ColorStateList extends ComplexColor implements Parcelable { final int alpha = MathUtils.constrain((int) (baseAlpha * alphaMod + 0.5f), 0, 255); if (validLStar) { final double[] labColor = new double[3]; ColorUtils.colorToLAB(baseColor, labColor); baseColor = ColorUtils.LABToColor(lStar, labColor[1], labColor[2]); final Cam baseCam = ColorUtils.colorToCAM(baseColor); baseColor = ColorUtils.CAMToColor(baseCam.getHue(), baseCam.getChroma(), lStar); } return (baseColor & 0xFFFFFF) | (alpha << 24); Loading
core/tests/coretests/res/color/color_with_lstar.xml 0 → 100644 +20 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- ~ Copyright (C) 2021 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. --> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:color="#ff0000" android:lStar="50" /> </selector>
core/tests/coretests/res/values/colors.xml +1 −0 Original line number Diff line number Diff line Loading @@ -25,5 +25,6 @@ <drawable name="yellow">#ffffff00</drawable> <color name="testcolor1">#ff00ff00</color> <color name="testcolor2">#ffff0000</color> <color name="testcolor3">#fff00000</color> <color name="failColor">#ff0000ff</color> </resources>
core/tests/coretests/src/android/graphics/ColorStateListTest.java +6 −0 Original line number Diff line number Diff line Loading @@ -67,4 +67,10 @@ public class ColorStateListTest extends AndroidTestCase { int defaultColor = mResources.getColor(R.color.color_no_default); assertEquals(mResources.getColor(R.color.testcolor1), defaultColor); } @SmallTest public void testLstar() throws Exception { int defaultColor = mResources.getColor(R.color.color_with_lstar); assertEquals(mResources.getColor(R.color.testcolor3), defaultColor); } }