Loading packages/SystemUI/src/com/android/keyguard/clock/AnalogClockController.java +18 −8 Original line number Diff line number Diff line Loading @@ -74,6 +74,11 @@ public class AnalogClockController implements ClockPlugin { private View mView; private TextClock mLockClock; /** * Helper to extract colors from wallpaper palette for clock face. */ private final ClockPalette mPalette = new ClockPalette(); /** * Create a BubbleClockController instance. * Loading Loading @@ -162,17 +167,21 @@ public class AnalogClockController implements ClockPlugin { public void setStyle(Style style) {} @Override public void setTextColor(int color) { } public void setTextColor(int color) { updateColor(); } @Override public void setColorPalette(boolean supportsDarkText, int[] colorPalette) { if (colorPalette == null || colorPalette.length == 0) { return; mPalette.setColorPalette(supportsDarkText, colorPalette); updateColor(); } final int length = colorPalette.length; mLockClock.setTextColor(colorPalette[Math.max(0, length - 2)]); mAnalogClock.setClockColors(colorPalette[Math.max(0, length - 5)], colorPalette[Math.max(0, length - 2)]); private void updateColor() { final int primary = mPalette.getPrimaryColor(); final int secondary = mPalette.getSecondaryColor(); mLockClock.setTextColor(secondary); mAnalogClock.setClockColors(primary, secondary); } @Override Loading @@ -184,6 +193,7 @@ public class AnalogClockController implements ClockPlugin { @Override public void setDarkAmount(float darkAmount) { mPalette.setDarkAmount(darkAmount); mClockPosition.setDarkAmount(darkAmount); mBigClockView.setDarkAmount(darkAmount); } Loading packages/SystemUI/src/com/android/keyguard/clock/BubbleClockController.java +18 −9 Original line number Diff line number Diff line Loading @@ -74,6 +74,11 @@ public class BubbleClockController implements ClockPlugin { private View mLockClockContainer; private TextClock mLockClock; /** * Helper to extract colors from wallpaper palette for clock face. */ private final ClockPalette mPalette = new ClockPalette(); /** * Create a BubbleClockController instance. * Loading Loading @@ -162,22 +167,26 @@ public class BubbleClockController implements ClockPlugin { public void setStyle(Style style) {} @Override public void setTextColor(int color) { } public void setTextColor(int color) { updateColor(); } @Override public void setColorPalette(boolean supportsDarkText, int[] colorPalette) { if (colorPalette == null || colorPalette.length == 0) { return; mPalette.setColorPalette(supportsDarkText, colorPalette); updateColor(); } final int length = colorPalette.length; final int primaryColor = colorPalette[Math.max(0, length - 2)]; final int secondaryColor = colorPalette[Math.max(0, length - 5)]; mLockClock.setTextColor(primaryColor); mAnalogClock.setClockColors(secondaryColor, primaryColor); private void updateColor() { final int primary = mPalette.getPrimaryColor(); final int secondary = mPalette.getSecondaryColor(); mLockClock.setTextColor(secondary); mAnalogClock.setClockColors(primary, secondary); } @Override public void setDarkAmount(float darkAmount) { mPalette.setDarkAmount(darkAmount); mClockPosition.setDarkAmount(darkAmount); mView.setDarkAmount(darkAmount); } Loading packages/SystemUI/src/com/android/keyguard/clock/ClockPalette.kt 0 → 100644 +73 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 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 */ package com.android.keyguard.clock import android.graphics.Color import android.util.MathUtils private const val PRIMARY_INDEX = 5 private const val SECONDARY_DARK_INDEX = 8 private const val SECONDARY_LIGHT_INDEX = 2 /** * A helper class to extract colors from a clock face. */ class ClockPalette { private var darkAmount: Float = 0f private var accentPrimary: Int = Color.WHITE private var accentSecondaryLight: Int = Color.WHITE private var accentSecondaryDark: Int = Color.BLACK private val lightHSV: FloatArray = FloatArray(3) private val darkHSV: FloatArray = FloatArray(3) private val hsv: FloatArray = FloatArray(3) /** Returns a color from the palette as an RGB packed int. */ fun getPrimaryColor(): Int { return accentPrimary } /** Returns either a light or dark color from the palette as an RGB packed int. */ fun getSecondaryColor(): Int { Color.colorToHSV(accentSecondaryLight, lightHSV) Color.colorToHSV(accentSecondaryDark, darkHSV) for (i in 0..2) { hsv[i] = MathUtils.lerp(darkHSV[i], lightHSV[i], darkAmount) } return Color.HSVToColor(hsv) } /** See {@link ClockPlugin#setColorPalette}. */ fun setColorPalette(supportsDarkText: Boolean, colorPalette: IntArray?) { if (colorPalette == null || colorPalette.isEmpty()) { accentPrimary = Color.WHITE accentSecondaryLight = Color.WHITE accentSecondaryDark = if (supportsDarkText) Color.BLACK else Color.WHITE return } val length = colorPalette.size accentPrimary = colorPalette[Math.max(0, length - PRIMARY_INDEX)] accentSecondaryLight = colorPalette[Math.max(0, length - SECONDARY_LIGHT_INDEX)] accentSecondaryDark = colorPalette[Math.max(0, length - if (supportsDarkText) SECONDARY_DARK_INDEX else SECONDARY_LIGHT_INDEX)] } /** See {@link ClockPlugin#setDarkAmount}. */ fun setDarkAmount(darkAmount: Float) { this.darkAmount = darkAmount } } packages/SystemUI/tests/src/com/android/keyguard/clock/AnalogClockControllerTest.java +3 −2 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.keyguard.clock; import static com.google.common.truth.Truth.assertThat; import android.content.res.Resources; import android.graphics.Color; import android.test.suitebuilder.annotation.SmallTest; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper.RunWithLooper; Loading Loading @@ -67,9 +68,9 @@ public final class AnalogClockControllerTest extends SysuiTestCase { public void setColorPalette_setDigitalClock() { ViewGroup smallClock = (ViewGroup) mClockController.getView(); // WHEN color palette is set mClockController.setColorPalette(true, new int[]{42}); mClockController.setColorPalette(true, new int[]{Color.RED}); // THEN child of small clock should have text color set. TextView digitalClock = (TextView) smallClock.getChildAt(0); assertThat(digitalClock.getCurrentTextColor()).isEqualTo(42); assertThat(digitalClock.getCurrentTextColor()).isEqualTo(Color.RED); } } packages/SystemUI/tests/src/com/android/keyguard/clock/BubbleClockControllerTest.java +3 −2 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.keyguard.clock; import static com.google.common.truth.Truth.assertThat; import android.content.res.Resources; import android.graphics.Color; import android.test.suitebuilder.annotation.SmallTest; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper.RunWithLooper; Loading Loading @@ -66,9 +67,9 @@ public final class BubbleClockControllerTest extends SysuiTestCase { public void setColorPalette_setDigitalClock() { ViewGroup smallClock = (ViewGroup) mClockController.getView(); // WHEN text color is set mClockController.setColorPalette(true, new int[]{42}); mClockController.setColorPalette(true, new int[]{Color.RED}); // THEN child of small clock should have text color set. TextView digitalClock = (TextView) smallClock.getChildAt(0); assertThat(digitalClock.getCurrentTextColor()).isEqualTo(42); assertThat(digitalClock.getCurrentTextColor()).isEqualTo(Color.RED); } } Loading
packages/SystemUI/src/com/android/keyguard/clock/AnalogClockController.java +18 −8 Original line number Diff line number Diff line Loading @@ -74,6 +74,11 @@ public class AnalogClockController implements ClockPlugin { private View mView; private TextClock mLockClock; /** * Helper to extract colors from wallpaper palette for clock face. */ private final ClockPalette mPalette = new ClockPalette(); /** * Create a BubbleClockController instance. * Loading Loading @@ -162,17 +167,21 @@ public class AnalogClockController implements ClockPlugin { public void setStyle(Style style) {} @Override public void setTextColor(int color) { } public void setTextColor(int color) { updateColor(); } @Override public void setColorPalette(boolean supportsDarkText, int[] colorPalette) { if (colorPalette == null || colorPalette.length == 0) { return; mPalette.setColorPalette(supportsDarkText, colorPalette); updateColor(); } final int length = colorPalette.length; mLockClock.setTextColor(colorPalette[Math.max(0, length - 2)]); mAnalogClock.setClockColors(colorPalette[Math.max(0, length - 5)], colorPalette[Math.max(0, length - 2)]); private void updateColor() { final int primary = mPalette.getPrimaryColor(); final int secondary = mPalette.getSecondaryColor(); mLockClock.setTextColor(secondary); mAnalogClock.setClockColors(primary, secondary); } @Override Loading @@ -184,6 +193,7 @@ public class AnalogClockController implements ClockPlugin { @Override public void setDarkAmount(float darkAmount) { mPalette.setDarkAmount(darkAmount); mClockPosition.setDarkAmount(darkAmount); mBigClockView.setDarkAmount(darkAmount); } Loading
packages/SystemUI/src/com/android/keyguard/clock/BubbleClockController.java +18 −9 Original line number Diff line number Diff line Loading @@ -74,6 +74,11 @@ public class BubbleClockController implements ClockPlugin { private View mLockClockContainer; private TextClock mLockClock; /** * Helper to extract colors from wallpaper palette for clock face. */ private final ClockPalette mPalette = new ClockPalette(); /** * Create a BubbleClockController instance. * Loading Loading @@ -162,22 +167,26 @@ public class BubbleClockController implements ClockPlugin { public void setStyle(Style style) {} @Override public void setTextColor(int color) { } public void setTextColor(int color) { updateColor(); } @Override public void setColorPalette(boolean supportsDarkText, int[] colorPalette) { if (colorPalette == null || colorPalette.length == 0) { return; mPalette.setColorPalette(supportsDarkText, colorPalette); updateColor(); } final int length = colorPalette.length; final int primaryColor = colorPalette[Math.max(0, length - 2)]; final int secondaryColor = colorPalette[Math.max(0, length - 5)]; mLockClock.setTextColor(primaryColor); mAnalogClock.setClockColors(secondaryColor, primaryColor); private void updateColor() { final int primary = mPalette.getPrimaryColor(); final int secondary = mPalette.getSecondaryColor(); mLockClock.setTextColor(secondary); mAnalogClock.setClockColors(primary, secondary); } @Override public void setDarkAmount(float darkAmount) { mPalette.setDarkAmount(darkAmount); mClockPosition.setDarkAmount(darkAmount); mView.setDarkAmount(darkAmount); } Loading
packages/SystemUI/src/com/android/keyguard/clock/ClockPalette.kt 0 → 100644 +73 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 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 */ package com.android.keyguard.clock import android.graphics.Color import android.util.MathUtils private const val PRIMARY_INDEX = 5 private const val SECONDARY_DARK_INDEX = 8 private const val SECONDARY_LIGHT_INDEX = 2 /** * A helper class to extract colors from a clock face. */ class ClockPalette { private var darkAmount: Float = 0f private var accentPrimary: Int = Color.WHITE private var accentSecondaryLight: Int = Color.WHITE private var accentSecondaryDark: Int = Color.BLACK private val lightHSV: FloatArray = FloatArray(3) private val darkHSV: FloatArray = FloatArray(3) private val hsv: FloatArray = FloatArray(3) /** Returns a color from the palette as an RGB packed int. */ fun getPrimaryColor(): Int { return accentPrimary } /** Returns either a light or dark color from the palette as an RGB packed int. */ fun getSecondaryColor(): Int { Color.colorToHSV(accentSecondaryLight, lightHSV) Color.colorToHSV(accentSecondaryDark, darkHSV) for (i in 0..2) { hsv[i] = MathUtils.lerp(darkHSV[i], lightHSV[i], darkAmount) } return Color.HSVToColor(hsv) } /** See {@link ClockPlugin#setColorPalette}. */ fun setColorPalette(supportsDarkText: Boolean, colorPalette: IntArray?) { if (colorPalette == null || colorPalette.isEmpty()) { accentPrimary = Color.WHITE accentSecondaryLight = Color.WHITE accentSecondaryDark = if (supportsDarkText) Color.BLACK else Color.WHITE return } val length = colorPalette.size accentPrimary = colorPalette[Math.max(0, length - PRIMARY_INDEX)] accentSecondaryLight = colorPalette[Math.max(0, length - SECONDARY_LIGHT_INDEX)] accentSecondaryDark = colorPalette[Math.max(0, length - if (supportsDarkText) SECONDARY_DARK_INDEX else SECONDARY_LIGHT_INDEX)] } /** See {@link ClockPlugin#setDarkAmount}. */ fun setDarkAmount(darkAmount: Float) { this.darkAmount = darkAmount } }
packages/SystemUI/tests/src/com/android/keyguard/clock/AnalogClockControllerTest.java +3 −2 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.keyguard.clock; import static com.google.common.truth.Truth.assertThat; import android.content.res.Resources; import android.graphics.Color; import android.test.suitebuilder.annotation.SmallTest; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper.RunWithLooper; Loading Loading @@ -67,9 +68,9 @@ public final class AnalogClockControllerTest extends SysuiTestCase { public void setColorPalette_setDigitalClock() { ViewGroup smallClock = (ViewGroup) mClockController.getView(); // WHEN color palette is set mClockController.setColorPalette(true, new int[]{42}); mClockController.setColorPalette(true, new int[]{Color.RED}); // THEN child of small clock should have text color set. TextView digitalClock = (TextView) smallClock.getChildAt(0); assertThat(digitalClock.getCurrentTextColor()).isEqualTo(42); assertThat(digitalClock.getCurrentTextColor()).isEqualTo(Color.RED); } }
packages/SystemUI/tests/src/com/android/keyguard/clock/BubbleClockControllerTest.java +3 −2 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.keyguard.clock; import static com.google.common.truth.Truth.assertThat; import android.content.res.Resources; import android.graphics.Color; import android.test.suitebuilder.annotation.SmallTest; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper.RunWithLooper; Loading Loading @@ -66,9 +67,9 @@ public final class BubbleClockControllerTest extends SysuiTestCase { public void setColorPalette_setDigitalClock() { ViewGroup smallClock = (ViewGroup) mClockController.getView(); // WHEN text color is set mClockController.setColorPalette(true, new int[]{42}); mClockController.setColorPalette(true, new int[]{Color.RED}); // THEN child of small clock should have text color set. TextView digitalClock = (TextView) smallClock.getChildAt(0); assertThat(digitalClock.getCurrentTextColor()).isEqualTo(42); assertThat(digitalClock.getCurrentTextColor()).isEqualTo(Color.RED); } }