diff --git a/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/DefaultClockController.kt b/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/DefaultClockController.kt index 2a40f5c70420d..4df7a44d3e1d9 100644 --- a/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/DefaultClockController.kt +++ b/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/DefaultClockController.kt @@ -95,7 +95,7 @@ class DefaultClockController( open inner class DefaultClockFaceController( override val view: AnimatableClockView, - val seedColor: Int?, + var seedColor: Int?, ) : ClockFaceController { // MAGENTA is a placeholder, and will be assigned correctly in initialize @@ -111,9 +111,9 @@ class DefaultClockController( init { if (seedColor != null) { - currentColor = seedColor + currentColor = seedColor!! } - view.setColors(currentColor, currentColor) + view.setColors(DOZE_COLOR, currentColor) } override val events = @@ -141,7 +141,7 @@ class DefaultClockController( fun updateColor() { val color = if (seedColor != null) { - seedColor + seedColor!! } else if (isRegionDark) { resources.getColor(android.R.color.system_accent1_100) } else { @@ -194,6 +194,14 @@ class DefaultClockController( smallClock.updateColor() } + override fun onSeedColorChanged(seedColor: Int?) { + largeClock.seedColor = seedColor + smallClock.seedColor = seedColor + + largeClock.updateColor() + smallClock.updateColor() + } + override fun onLocaleChanged(locale: Locale) { val nf = NumberFormat.getInstance(locale) if (nf.format(FORMAT_NUMBER.toLong()) == burmeseNumerals) { diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/ClockProviderPlugin.kt b/packages/SystemUI/plugin/src/com/android/systemui/plugins/ClockProviderPlugin.kt index ab4aca569bd4a..54c837fb8760d 100644 --- a/packages/SystemUI/plugin/src/com/android/systemui/plugins/ClockProviderPlugin.kt +++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/ClockProviderPlugin.kt @@ -112,6 +112,9 @@ interface ClockEvents { /** Call whenever the color palette should update */ fun onColorPaletteChanged(resources: Resources) {} + /** Call if the seed color has changed and should be updated */ + fun onSeedColorChanged(seedColor: Int?) {} + /** Call whenever the weather data should update */ fun onWeatherDataChanged(data: WeatherData) {} } diff --git a/packages/SystemUI/tests/src/com/android/systemui/shared/clocks/DefaultClockProviderTest.kt b/packages/SystemUI/tests/src/com/android/systemui/shared/clocks/DefaultClockProviderTest.kt index cd2efc061b72e..7fa27f34cd9f2 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/shared/clocks/DefaultClockProviderTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/shared/clocks/DefaultClockProviderTest.kt @@ -26,6 +26,7 @@ import android.widget.FrameLayout import androidx.test.filters.SmallTest import com.android.systemui.R import com.android.systemui.SysuiTestCase +import com.android.systemui.plugins.ClockSettings import com.android.systemui.shared.clocks.DefaultClockController.Companion.DOZE_COLOR import com.android.systemui.util.mockito.any import com.android.systemui.util.mockito.eq @@ -40,7 +41,6 @@ import org.junit.Test import org.junit.runner.RunWith import org.mockito.ArgumentMatchers.anyBoolean import org.mockito.ArgumentMatchers.anyFloat -import org.mockito.ArgumentMatchers.anyInt import org.mockito.ArgumentMatchers.notNull import org.mockito.Mock import org.mockito.Mockito.never @@ -97,13 +97,14 @@ class DefaultClockProviderTest : SysuiTestCase() { @Test fun defaultClock_initialize() { val clock = provider.createClock(DEFAULT_CLOCK_ID) - verify(mockSmallClockView).setColors(Color.MAGENTA, Color.MAGENTA) - verify(mockLargeClockView).setColors(Color.MAGENTA, Color.MAGENTA) + verify(mockSmallClockView).setColors(DOZE_COLOR, Color.MAGENTA) + verify(mockLargeClockView).setColors(DOZE_COLOR, Color.MAGENTA) clock.initialize(resources, 0f, 0f) - verify(mockSmallClockView).setColors(eq(DOZE_COLOR), anyInt()) - verify(mockLargeClockView).setColors(eq(DOZE_COLOR), anyInt()) + val expectedColor = 0 + verify(mockSmallClockView).setColors(DOZE_COLOR, expectedColor) + verify(mockLargeClockView).setColors(DOZE_COLOR, expectedColor) verify(mockSmallClockView).onTimeZoneChanged(notNull()) verify(mockLargeClockView).onTimeZoneChanged(notNull()) verify(mockSmallClockView).refreshTime() @@ -159,15 +160,31 @@ class DefaultClockProviderTest : SysuiTestCase() { @Test fun defaultClock_events_onColorPaletteChanged() { + val expectedColor = 0 val clock = provider.createClock(DEFAULT_CLOCK_ID) - verify(mockSmallClockView).setColors(Color.MAGENTA, Color.MAGENTA) - verify(mockLargeClockView).setColors(Color.MAGENTA, Color.MAGENTA) + verify(mockSmallClockView).setColors(DOZE_COLOR, Color.MAGENTA) + verify(mockLargeClockView).setColors(DOZE_COLOR, Color.MAGENTA) clock.events.onColorPaletteChanged(resources) - verify(mockSmallClockView).setColors(eq(DOZE_COLOR), anyInt()) - verify(mockLargeClockView).setColors(eq(DOZE_COLOR), anyInt()) + verify(mockSmallClockView).setColors(DOZE_COLOR, expectedColor) + verify(mockLargeClockView).setColors(DOZE_COLOR, expectedColor) + } + + @Test + fun defaultClock_events_onSeedColorChanged() { + val initSeedColor = 10 + val newSeedColor = 20 + val clock = provider.createClock(ClockSettings(DEFAULT_CLOCK_ID, initSeedColor)) + + verify(mockSmallClockView).setColors(DOZE_COLOR, initSeedColor) + verify(mockLargeClockView).setColors(DOZE_COLOR, initSeedColor) + + clock.events.onSeedColorChanged(newSeedColor) + + verify(mockSmallClockView).setColors(DOZE_COLOR, newSeedColor) + verify(mockLargeClockView).setColors(DOZE_COLOR, newSeedColor) } @Test