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

Commit 28b8c82b authored by Brad Hinegardner's avatar Brad Hinegardner
Browse files

Scale the large clock down to make way for date weather move

Bug: 372246519
Test: ClockSectionTest.kt
Flag: com.android.systemui.shared.clock_reactive_smartspace_layout
Change-Id: Ie8323d9ad190498cbbe316bbb8c3eca4a1325805
parent 6004dec2
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@
    <dimen name="clock_vertical_digit_buffer">8dp</dimen>

    <!-- When large clock is showing, offset the smartspace by this amount -->
    <dimen name="keyguard_smartspace_top_offset">12dp</dimen>
    <dimen name="keyguard_smartspace_top_offset">6dp</dimen>
    <!--Dimens used in both lockscreen  preview and smartspace -->
    <dimen name="date_weather_view_height">24dp</dimen>
    <dimen name="enhanced_smartspace_height">104dp</dimen>
+75 −15
Original line number Diff line number Diff line
@@ -64,13 +64,16 @@ import org.mockito.kotlin.mock
class ClockSectionTest : SysuiTestCase() {
    private lateinit var underTest: ClockSection

    private val KEYGUARD_SMARTSPACE_TOP_OFFSET: Int
        get() =
            kosmos.fakeSystemBarUtilsProxy.getStatusBarHeight() / 2 +
            context.resources.getDimensionPixelSize(customR.dimen.keyguard_smartspace_top_offset)

    private val LARGE_CLOCK_TOP_WITHOUT_SMARTSPACE: Int
        get() =
            kosmos.fakeSystemBarUtilsProxy.getStatusBarHeight() +
                context.resources.getDimensionPixelSize(customR.dimen.small_clock_padding_top) +
                context.resources.getDimensionPixelSize(
                    customR.dimen.keyguard_smartspace_top_offset
                )
                context.resources.getDimensionPixelSize(customR.dimen.keyguard_smartspace_top_offset)

    private val LARGE_CLOCK_TOP
        get() =
@@ -159,8 +162,7 @@ class ClockSectionTest : SysuiTestCase() {
            val cs = ConstraintSet()
            underTest.applyDefaultConstraints(cs)

            assertLargeClockTop(cs, LARGE_CLOCK_TOP_WITHOUT_SMARTSPACE +
                    ENHANCED_SMART_SPACE_HEIGHT)
            assertLargeClockTop(cs, KEYGUARD_SMARTSPACE_TOP_OFFSET + ENHANCED_SMART_SPACE_HEIGHT)
            assertSmallClockTop(cs)
        }

@@ -207,13 +209,16 @@ class ClockSectionTest : SysuiTestCase() {
                val cs = ConstraintSet()
                underTest.applyDefaultConstraints(cs)

                assertLargeClockTop(cs, LARGE_CLOCK_TOP_WITHOUT_SMARTSPACE +
                        ENHANCED_SMART_SPACE_HEIGHT)
                assertLargeClockTop(
                    cs,
                    KEYGUARD_SMARTSPACE_TOP_OFFSET + ENHANCED_SMART_SPACE_HEIGHT,
                )
                assertSmallClockTop(cs)
            }
        }

    @Test
    @DisableFlags(com.android.systemui.shared.Flags.FLAG_CLOCK_REACTIVE_SMARTSPACE_LAYOUT)
    fun testApplyDefaultConstraints_LargeClock_MissingSmartspace_SplitShade() =
        kosmos.testScope.runTest {
            with(kosmos) {
@@ -238,6 +243,32 @@ class ClockSectionTest : SysuiTestCase() {
        }

    @Test
    @EnableFlags(com.android.systemui.shared.Flags.FLAG_CLOCK_REACTIVE_SMARTSPACE_LAYOUT)
    fun testApplyDefaultConstraints_LargeClock_MissingSmartspace_SplitShade_ReactiveSmartspace() =
        kosmos.testScope.runTest {
            with(kosmos) {
                DIMENSION_BY_IDENTIFIER = listOf() // Remove Smartspace from mock
                val isShadeLayoutWide by collectLastValue(shadeRepository.isShadeLayoutWide)
                val isLargeClockVisible by
                collectLastValue(keyguardClockViewModel.isLargeClockVisible)

                shadeRepository.setShadeLayoutWide(true)
                keyguardClockInteractor.setClockSize(ClockSize.LARGE)
                notificationsKeyguardInteractor.setNotificationsFullyHidden(true)
                keyguardSmartspaceInteractor.setBcSmartspaceVisibility(VISIBLE)
                fakeConfigurationController.notifyConfigurationChanged()
                advanceUntilIdle()

                val cs = ConstraintSet()
                underTest.applyDefaultConstraints(cs)

                assertLargeClockTop(cs, KEYGUARD_SMARTSPACE_TOP_OFFSET)
                assertSmallClockTop(cs)
            }
        }

    @Test
    @DisableFlags(com.android.systemui.shared.Flags.FLAG_CLOCK_REACTIVE_SMARTSPACE_LAYOUT)
    fun testApplyDefaultConstraints_LargeClock_MissingSmartspace_NonSplitShade() =
        kosmos.testScope.runTest {
            with(kosmos) {
@@ -261,6 +292,31 @@ class ClockSectionTest : SysuiTestCase() {
            }
        }

    @Test
    @EnableFlags(com.android.systemui.shared.Flags.FLAG_CLOCK_REACTIVE_SMARTSPACE_LAYOUT)
    fun testApplyDefaultConstraints_LargeClock_MissingSmartspace_NonSplitShade_ReactiveSmartspace() =
        kosmos.testScope.runTest {
            with(kosmos) {
                DIMENSION_BY_IDENTIFIER = listOf() // Remove Smartspace from mock
                val isShadeLayoutWide by collectLastValue(shadeRepository.isShadeLayoutWide)
                val isLargeClockVisible by
                collectLastValue(keyguardClockViewModel.isLargeClockVisible)

                shadeRepository.setShadeLayoutWide(false)
                keyguardClockInteractor.setClockSize(ClockSize.LARGE)
                notificationsKeyguardInteractor.setNotificationsFullyHidden(true)
                keyguardSmartspaceInteractor.setBcSmartspaceVisibility(VISIBLE)
                fakeConfigurationController.notifyConfigurationChanged()
                advanceUntilIdle()

                val cs = ConstraintSet()
                underTest.applyDefaultConstraints(cs)

                assertLargeClockTop(cs, KEYGUARD_SMARTSPACE_TOP_OFFSET)
                assertSmallClockTop(cs)
            }
        }

    @Test
    @DisableFlags(com.android.systemui.shared.Flags.FLAG_CLOCK_REACTIVE_SMARTSPACE_LAYOUT)
    fun testApplyDefaultConstraints_SmallClock_SplitShade() =
@@ -304,8 +360,10 @@ class ClockSectionTest : SysuiTestCase() {
                val cs = ConstraintSet()
                underTest.applyDefaultConstraints(cs)

                assertLargeClockTop(cs, LARGE_CLOCK_TOP_WITHOUT_SMARTSPACE +
                        ENHANCED_SMART_SPACE_HEIGHT)
                assertLargeClockTop(
                    cs,
                    KEYGUARD_SMARTSPACE_TOP_OFFSET + ENHANCED_SMART_SPACE_HEIGHT,
                )
                assertSmallClockTop(cs)
            }
        }
@@ -351,8 +409,10 @@ class ClockSectionTest : SysuiTestCase() {

                val cs = ConstraintSet()
                underTest.applyDefaultConstraints(cs)
                assertLargeClockTop(cs, LARGE_CLOCK_TOP_WITHOUT_SMARTSPACE +
                        ENHANCED_SMART_SPACE_HEIGHT)
                assertLargeClockTop(
                    cs,
                    KEYGUARD_SMARTSPACE_TOP_OFFSET + ENHANCED_SMART_SPACE_HEIGHT,
                )
                assertSmallClockTop(cs)
            }
        }
+166 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.systemui.keyguard.ui.viewmodel

import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
@@ -98,6 +100,34 @@ class AodBurnInViewModelTest : SysuiTestCase() {
        }

    @Test
    @EnableFlags(com.android.systemui.shared.Flags.FLAG_CLOCK_REACTIVE_SMARTSPACE_LAYOUT)
    fun translationAndScale_whenNotDozing_reactiveSmartspace() =
        testScope.runTest {
            val movement by collectLastValue(underTest.movement)
            assertThat(movement?.translationX).isEqualTo(0)

            // Set to not dozing (on lockscreen)
            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.AOD,
                    to = KeyguardState.LOCKSCREEN,
                    value = 1f,
                    transitionState = TransitionState.FINISHED,
                ),
                validateStep = false,
            )

            // Trigger a change to the burn-in model
            burnInFlow.value = BurnInModel(translationX = 20, translationY = 30, scale = 0.5f)

            assertThat(movement?.translationX).isEqualTo(0)
            assertThat(movement?.translationY).isEqualTo(0)
            assertThat(movement?.scale).isEqualTo(0.9f)
            assertThat(movement?.scaleClockOnly).isEqualTo(true)
        }

    @Test
    @DisableFlags(com.android.systemui.shared.Flags.FLAG_CLOCK_REACTIVE_SMARTSPACE_LAYOUT)
    fun translationAndScale_whenNotDozing() =
        testScope.runTest {
            val movement by collectLastValue(underTest.movement)
@@ -124,6 +154,55 @@ class AodBurnInViewModelTest : SysuiTestCase() {
        }

    @Test
    @EnableFlags(com.android.systemui.shared.Flags.FLAG_CLOCK_REACTIVE_SMARTSPACE_LAYOUT)
    fun translationX_aodToLockscreen_reactiveSmartspace() =
        testScope.runTest {
            underTest.updateBurnInParams(burnInParameters.copy(translationX = { -100f }))
            val movement by collectLastValue(underTest.movement)
            assertThat(movement?.translationX).isEqualTo(0)

            // Trigger a change to the burn-in model
            burnInFlow.value = BurnInModel(translationX = 20, translationY = 30, scale = 0.5f)

            // Set to not dozing (on lockscreen)
            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.AOD,
                    to = KeyguardState.LOCKSCREEN,
                    value = 0f,
                    transitionState = TransitionState.STARTED,
                ),
                validateStep = false,
            )
            // Set to not dozing (on lockscreen)
            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.AOD,
                    to = KeyguardState.LOCKSCREEN,
                    value = 0f,
                    transitionState = TransitionState.RUNNING,
                ),
                validateStep = false,
            )
            assertThat(movement?.translationX).isEqualTo(-100)
            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.AOD,
                    to = KeyguardState.LOCKSCREEN,
                    value = 1f,
                    transitionState = TransitionState.FINISHED,
                ),
                validateStep = false,
            )

            assertThat(movement?.translationX).isEqualTo(0)
            assertThat(movement?.translationY).isEqualTo(0)
            assertThat(movement?.scale).isEqualTo(0.9f)
            assertThat(movement?.scaleClockOnly).isEqualTo(true)
        }

    @Test
    @DisableFlags(com.android.systemui.shared.Flags.FLAG_CLOCK_REACTIVE_SMARTSPACE_LAYOUT)
    fun translationX_aodToLockscreen() =
        testScope.runTest {
            underTest.updateBurnInParams(burnInParameters.copy(translationX = { -100f }))
@@ -171,6 +250,49 @@ class AodBurnInViewModelTest : SysuiTestCase() {
        }

    @Test
    @EnableFlags(com.android.systemui.shared.Flags.FLAG_CLOCK_REACTIVE_SMARTSPACE_LAYOUT)
    fun translationAndScale_whenFullyDozing_reactiveSmartspace() =
        testScope.runTest {
            underTest.updateBurnInParams(burnInParameters.copy(minViewY = 100))
            val movement by collectLastValue(underTest.movement)
            assertThat(movement?.translationX).isEqualTo(0)

            // Set to dozing (on AOD)
            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.GONE,
                    to = KeyguardState.AOD,
                    value = 1f,
                    transitionState = TransitionState.FINISHED,
                ),
                validateStep = false,
            )
            // Trigger a change to the burn-in model
            burnInFlow.value = BurnInModel(translationX = 20, translationY = 30, scale = 0.5f)

            assertThat(movement?.translationX).isEqualTo(20)
            assertThat(movement?.translationY).isEqualTo(30)
            assertThat(movement?.scale).isEqualTo(0.5f)
            assertThat(movement?.scaleClockOnly).isEqualTo(true)

            // Set to the beginning of GONE->AOD transition
            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.GONE,
                    to = KeyguardState.AOD,
                    value = 0f,
                    transitionState = TransitionState.STARTED,
                ),
                validateStep = false,
            )
            assertThat(movement?.translationX).isEqualTo(0)
            assertThat(movement?.translationY).isEqualTo(0)
            assertThat(movement?.scale).isEqualTo(0.9f)
            assertThat(movement?.scaleClockOnly).isEqualTo(true)
        }

    @Test
    @DisableFlags(com.android.systemui.shared.Flags.FLAG_CLOCK_REACTIVE_SMARTSPACE_LAYOUT)
    fun translationAndScale_whenFullyDozing() =
        testScope.runTest {
            underTest.updateBurnInParams(burnInParameters.copy(minViewY = 100))
@@ -212,6 +334,50 @@ class AodBurnInViewModelTest : SysuiTestCase() {
        }

    @Test
    @EnableFlags(com.android.systemui.shared.Flags.FLAG_CLOCK_REACTIVE_SMARTSPACE_LAYOUT)
    fun translationAndScale_whenFullyDozing_MigrationFlagOn_staysOutOfTopInset_reactiveSmartspace() =
        testScope.runTest {
            underTest.updateBurnInParams(burnInParameters.copy(minViewY = 100, topInset = 80))
            val movement by collectLastValue(underTest.movement)
            assertThat(movement?.translationX).isEqualTo(0)

            // Set to dozing (on AOD)
            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.GONE,
                    to = KeyguardState.AOD,
                    value = 1f,
                    transitionState = TransitionState.FINISHED,
                ),
                validateStep = false,
            )

            // Trigger a change to the burn-in model
            burnInFlow.value = BurnInModel(translationX = 20, translationY = -30, scale = 0.5f)
            assertThat(movement?.translationX).isEqualTo(20)
            // -20 instead of -30, due to inset of 80
            assertThat(movement?.translationY).isEqualTo(-20)
            assertThat(movement?.scale).isEqualTo(0.5f)
            assertThat(movement?.scaleClockOnly).isEqualTo(true)

            // Set to the beginning of GONE->AOD transition
            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.GONE,
                    to = KeyguardState.AOD,
                    value = 0f,
                    transitionState = TransitionState.STARTED,
                ),
                validateStep = false,
            )
            assertThat(movement?.translationX).isEqualTo(0)
            assertThat(movement?.translationY).isEqualTo(0)
            assertThat(movement?.scale).isEqualTo(0.9f)
            assertThat(movement?.scaleClockOnly).isEqualTo(true)
        }

    @Test
    @DisableFlags(com.android.systemui.shared.Flags.FLAG_CLOCK_REACTIVE_SMARTSPACE_LAYOUT)
    fun translationAndScale_whenFullyDozing_MigrationFlagOn_staysOutOfTopInset() =
        testScope.runTest {
            underTest.updateBurnInParams(burnInParameters.copy(minViewY = 100, topInset = 80))
+1 −1
Original line number Diff line number Diff line
@@ -115,7 +115,7 @@
    <dimen name="below_clock_padding_end">16dp</dimen>
    <dimen name="below_clock_padding_start_icons">28dp</dimen>
    <dimen name="smartspace_padding_horizontal">16dp</dimen>
    <dimen name="smartspace_padding_vertical">12dp</dimen>
    <dimen name="smartspace_padding_vertical">6dp</dimen>

    <!-- Proportion of the screen height to use to set the maximum height of the bouncer to when
         the device is in the DEVICE_POSTURE_HALF_OPENED posture, for the PIN/pattern entry. 0 will
+25 −14
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.doze.util

import android.util.MathUtils
import com.android.systemui.shared.Flags

private const val MILLIS_PER_MINUTES = 1000 * 60f
private const val BURN_IN_PREVENTION_PERIOD_Y = 521f
@@ -25,33 +26,43 @@ private const val BURN_IN_PREVENTION_PERIOD_SCALE = 181f
private const val BURN_IN_PREVENTION_PERIOD_PROGRESS = 89f

/**
 * Returns the translation offset that should be used to avoid burn in at
 * the current time (in pixels.)
 * Returns the translation offset that should be used to avoid burn in at the current time (in
 * pixels.)
 *
 * @param amplitude Maximum translation that will be interpolated.
 * @param xAxis If we're moving on X or Y.
 */
fun getBurnInOffset(amplitude: Int, xAxis: Boolean): Int {
    return zigzag(System.currentTimeMillis() / MILLIS_PER_MINUTES,
    return zigzag(
            System.currentTimeMillis() / MILLIS_PER_MINUTES,
            amplitude.toFloat(),
            if (xAxis) BURN_IN_PREVENTION_PERIOD_X else BURN_IN_PREVENTION_PERIOD_Y).toInt()
            if (xAxis) BURN_IN_PREVENTION_PERIOD_X else BURN_IN_PREVENTION_PERIOD_Y,
        )
        .toInt()
}

/**
 * Returns a progress offset (between 0f and 1.0f) that should be used to avoid burn in at
 * the current time.
 * Returns a progress offset (between 0f and 1.0f) that should be used to avoid burn in at the
 * current time.
 */
fun getBurnInProgressOffset(): Float {
    return zigzag(System.currentTimeMillis() / MILLIS_PER_MINUTES,
        1f, BURN_IN_PREVENTION_PERIOD_PROGRESS)
    return zigzag(
        System.currentTimeMillis() / MILLIS_PER_MINUTES,
        1f,
        BURN_IN_PREVENTION_PERIOD_PROGRESS,
    )
}

/**
 * Returns a value to scale a view in order to avoid burn in.
 */
/** Returns a value to scale a view in order to avoid burn in. */
fun getBurnInScale(): Float {
    return 0.8f + zigzag(System.currentTimeMillis() / MILLIS_PER_MINUTES,
            0.2f, BURN_IN_PREVENTION_PERIOD_SCALE)
    val multiplier = if (Flags.clockReactiveSmartspaceLayout()) 0.75f else 0.8f

    return multiplier +
        zigzag(
            System.currentTimeMillis() / MILLIS_PER_MINUTES,
            0.2f,
            BURN_IN_PREVENTION_PERIOD_SCALE,
        )
}

/**
Loading