Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 765485f7 authored by Hawkwood Glazier's avatar Hawkwood Glazier Committed by Android (Google) Code Review
Browse files

Merge "Add alternative color updating path for seed colors" into tm-qpr-dev

parents 515ff456 874061c2
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -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) {
+3 −0
Original line number Diff line number Diff line
@@ -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) {}
}
+26 −9
Original line number Diff line number Diff line
@@ -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