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

Commit f2647e5d authored by Brad Hinegardner's avatar Brad Hinegardner
Browse files

Fall back to date weather below small clock sometimes

Based on certain criteria, we should fall back
to the small clock having the date weather below
it due to various size constraints

Bug: 400744872
Test: KeyguardSmartspaceViewModelTest.kt
Flag: com.android.systemui.shared.clock_reactive_smartspace_layout
Change-Id: I380c1ac4950e6044ca39f1ea3e48f2170da5ff4b
parent 46bca737
Loading
Loading
Loading
Loading
+63 −1
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

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

import android.content.res.Configuration
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
@@ -44,7 +47,7 @@ class KeyguardSmartspaceViewModelTest : SysuiTestCase() {
    val kosmos = testKosmos()
    val testScope = kosmos.testScope
    val underTest = kosmos.keyguardSmartspaceViewModel
    val res = context.resources
    @Mock private lateinit var mockConfiguration: Configuration

    @Mock(answer = Answers.RETURNS_DEEP_STUBS) private lateinit var clockController: ClockController

@@ -119,4 +122,63 @@ class KeyguardSmartspaceViewModelTest : SysuiTestCase() {
                assertThat(isShadeLayoutWide).isFalse()
            }
        }

    @Test
    @DisableFlags(com.android.systemui.shared.Flags.FLAG_CLOCK_REACTIVE_SMARTSPACE_LAYOUT)
    fun dateWeatherBelowSmallClock_smartspacelayoutflag_off_true() {
        val result = KeyguardSmartspaceViewModel.dateWeatherBelowSmallClock(mockConfiguration)

        assertThat(result).isTrue()
    }

    @Test
    @EnableFlags(com.android.systemui.shared.Flags.FLAG_CLOCK_REACTIVE_SMARTSPACE_LAYOUT)
    fun dateWeatherBelowSmallClock_defaultFontAndDisplaySize_false() {
        val fontScale = 1.0f
        val screenWidthDp = 347
        mockConfiguration.fontScale = fontScale
        mockConfiguration.screenWidthDp = screenWidthDp

        val result = KeyguardSmartspaceViewModel.dateWeatherBelowSmallClock(mockConfiguration)

        assertThat(result).isFalse()
    }

    @Test
    @EnableFlags(com.android.systemui.shared.Flags.FLAG_CLOCK_REACTIVE_SMARTSPACE_LAYOUT)
    fun dateWeatherBelowSmallClock_variousFontAndDisplaySize_false() {
        mockConfiguration.fontScale = 1.0f
        mockConfiguration.screenWidthDp = 347
        val result1 = KeyguardSmartspaceViewModel.dateWeatherBelowSmallClock(mockConfiguration)
        assertThat(result1).isFalse()

        mockConfiguration.fontScale = 1.2f
        mockConfiguration.screenWidthDp = 347
        val result2 = KeyguardSmartspaceViewModel.dateWeatherBelowSmallClock(mockConfiguration)
        assertThat(result2).isFalse()

        mockConfiguration.fontScale = 1.7f
        mockConfiguration.screenWidthDp = 412
        val result3 = KeyguardSmartspaceViewModel.dateWeatherBelowSmallClock(mockConfiguration)
        assertThat(result3).isFalse()
    }

    @Test
    @EnableFlags(com.android.systemui.shared.Flags.FLAG_CLOCK_REACTIVE_SMARTSPACE_LAYOUT)
    fun dateWeatherBelowSmallClock_variousFontAndDisplaySize_true() {
        mockConfiguration.fontScale = 1.0f
        mockConfiguration.screenWidthDp = 310
        val result1 = KeyguardSmartspaceViewModel.dateWeatherBelowSmallClock(mockConfiguration)
        assertThat(result1).isTrue()

        mockConfiguration.fontScale = 1.5f
        mockConfiguration.screenWidthDp = 347
        val result2 = KeyguardSmartspaceViewModel.dateWeatherBelowSmallClock(mockConfiguration)
        assertThat(result2).isTrue()

        mockConfiguration.fontScale = 2.0f
        mockConfiguration.screenWidthDp = 411
        val result3 = KeyguardSmartspaceViewModel.dateWeatherBelowSmallClock(mockConfiguration)
        assertThat(result3).isTrue()
    }
}
+1 −7
Original line number Diff line number Diff line
@@ -128,13 +128,7 @@ object KeyguardBlueprintViewBinder {
        cs: ConstraintSet,
        constraintLayout: ConstraintLayout,
    ) {
        val ids =
            listOf(
                sharedR.id.date_smartspace_view,
                sharedR.id.date_smartspace_view_large,
                sharedR.id.weather_smartspace_view,
                sharedR.id.weather_smartspace_view_large,
            )
        val ids = listOf(sharedR.id.date_smartspace_view, sharedR.id.date_smartspace_view_large)

        for (i in ids) {
            constraintLayout.getViewById(i)?.visibility = cs.getVisibility(i)
+0 −2
Original line number Diff line number Diff line
@@ -193,7 +193,6 @@ object KeyguardRootViewBinder {
                            childViews[largeClockId]?.translationY = y
                            if (com.android.systemui.shared.Flags.clockReactiveSmartspaceLayout()) {
                                childViews[largeClockDateId]?.translationY = y
                                childViews[largeClockWeatherId]?.translationY = y
                            }
                            childViews[aodPromotedNotificationId]?.translationY = y
                            childViews[aodNotificationIconContainerId]?.translationY = y
@@ -584,7 +583,6 @@ object KeyguardRootViewBinder {
    private val aodNotificationIconContainerId = R.id.aod_notification_icon_container
    private val largeClockId = customR.id.lockscreen_clock_view_large
    private val largeClockDateId = sharedR.id.date_smartspace_view_large
    private val largeClockWeatherId = sharedR.id.weather_smartspace_view_large
    private val smallClockId = customR.id.lockscreen_clock_view
    private val indicationArea = R.id.keyguard_indication_area
    private val startButton = R.id.start_button
+26 −44
Original line number Diff line number Diff line
@@ -91,14 +91,9 @@ object KeyguardSmartspaceViewBinder {
                            R.dimen.smartspace_padding_vertical
                        )

                    val smallViewIds =
                        listOf(sharedR.id.date_smartspace_view, sharedR.id.weather_smartspace_view)
                    val smallViewId = sharedR.id.date_smartspace_view

                    val largeViewIds =
                        listOf(
                            sharedR.id.date_smartspace_view_large,
                            sharedR.id.weather_smartspace_view_large,
                        )
                    val largeViewId = sharedR.id.date_smartspace_view_large

                    launch("$TAG#smartspaceViewModel.burnInLayerVisibility") {
                        combine(
@@ -109,14 +104,12 @@ object KeyguardSmartspaceViewBinder {
                            .collect { (visibility, isLargeClock) ->
                                if (isLargeClock) {
                                    // hide small clock date/weather
                                    for (viewId in smallViewIds) {
                                        keyguardRootView.findViewById<View>(viewId)?.let {
                                    keyguardRootView.findViewById<View>(smallViewId)?.let {
                                        it.visibility = View.GONE
                                    }
                                }
                            }
                    }
                    }

                    launch("$TAG#clockEventController.onClockBoundsChanged") {
                        // Whenever the doze amount changes, the clock may update it's view bounds.
@@ -130,11 +123,10 @@ object KeyguardSmartspaceViewBinder {
                                ::Pair,
                            )
                            .collect { (isLargeClock, clockBounds) ->
                                for (id in (if (isLargeClock) smallViewIds else largeViewIds)) {
                                    keyguardRootView.findViewById<View>(id)?.let {
                                val viewId = if (isLargeClock) smallViewId else largeViewId
                                keyguardRootView.findViewById<View>(viewId)?.let {
                                    it.visibility = View.GONE
                                }
                                }

                                if (clockBounds == VRectF.ZERO) return@collect
                                if (isLargeClock) {
@@ -144,18 +136,19 @@ object KeyguardSmartspaceViewBinder {
                                                sharedR.id.date_smartspace_view_large
                                            )
                                            ?.height ?: 0
                                    for (id in largeViewIds) {
                                        keyguardRootView.findViewById<View>(id)?.let { view ->

                                    keyguardRootView.findViewById<View>(largeViewId)?.let { view ->
                                        val viewHeight = view.height
                                        val offset = (largeDateHeight - viewHeight) / 2
                                            view.top =
                                                (clockBounds.bottom + yBuffer + offset).toInt()
                                        view.top = (clockBounds.bottom + yBuffer + offset).toInt()
                                        view.bottom = view.top + viewHeight
                                    }
                                    }
                                } else {
                                    for (id in smallViewIds) {
                                        keyguardRootView.findViewById<View>(id)?.let { view ->
                                } else if (
                                    !KeyguardSmartspaceViewModel.dateWeatherBelowSmallClock(
                                        keyguardRootView.resources.configuration
                                    )
                                ) {
                                    keyguardRootView.findViewById<View>(smallViewId)?.let { view ->
                                        val viewWidth = view.width
                                        if (view.isLayoutRtl()) {
                                            view.right = (clockBounds.left - xBuffer).toInt()
@@ -172,7 +165,6 @@ object KeyguardSmartspaceViewBinder {
            }
        }
    }
    }

    private fun updateBCSmartspaceInBurnInLayer(
        keyguardRootView: ConstraintLayout,
@@ -218,11 +210,6 @@ object KeyguardSmartspaceViewBinder {
                val dateView =
                    constraintLayout.requireViewById<View>(sharedR.id.date_smartspace_view)
                addView(dateView)
                if (com.android.systemui.shared.Flags.clockReactiveSmartspaceLayout()) {
                    val weatherView =
                        constraintLayout.requireViewById<View>(sharedR.id.weather_smartspace_view)
                    addView(weatherView)
                }
            }
        }
    }
@@ -240,11 +227,6 @@ object KeyguardSmartspaceViewBinder {
                val dateView =
                    constraintLayout.requireViewById<View>(sharedR.id.date_smartspace_view)
                removeView(dateView)
                if (com.android.systemui.shared.Flags.clockReactiveSmartspaceLayout()) {
                    val weatherView =
                        constraintLayout.requireViewById<View>(sharedR.id.weather_smartspace_view)
                    removeView(weatherView)
                }
            }
        }
    }
+14 −8
Original line number Diff line number Diff line
@@ -121,18 +121,22 @@ constructor(
            setAlpha(getNonTargetClockFace(clock).views, 0F)

            if (!keyguardClockViewModel.isLargeClockVisible.value) {
                if (com.android.systemui.shared.Flags.clockReactiveSmartspaceLayout()) {
                if (
                    KeyguardSmartspaceViewModel.dateWeatherBelowSmallClock(
                        context.resources.configuration
                    )
                ) {
                    connect(
                        sharedR.id.bc_smartspace_view,
                        TOP,
                        customR.id.lockscreen_clock_view,
                        sharedR.id.date_smartspace_view,
                        BOTTOM,
                    )
                } else {
                    connect(
                        sharedR.id.bc_smartspace_view,
                        TOP,
                        sharedR.id.date_smartspace_view,
                        customR.id.lockscreen_clock_view,
                        BOTTOM,
                    )
                }
@@ -187,6 +191,8 @@ constructor(
        val guideline =
            if (keyguardClockViewModel.clockShouldBeCentered.value) PARENT_ID
            else R.id.split_shade_guideline
        val dateWeatherBelowSmallClock =
            KeyguardSmartspaceViewModel.dateWeatherBelowSmallClock(context.resources.configuration)
        constraints.apply {
            connect(customR.id.lockscreen_clock_view_large, START, PARENT_ID, START)
            connect(customR.id.lockscreen_clock_view_large, END, guideline, END)
@@ -254,11 +260,7 @@ constructor(
                        0
                    }

            if (com.android.systemui.shared.Flags.clockReactiveSmartspaceLayout()) {
                clockInteractor.setNotificationStackDefaultTop(
                    (smallClockBottom + marginBetweenSmartspaceAndNotification).toFloat()
                )
            } else {
            if (dateWeatherBelowSmallClock) {
                val dateWeatherSmartspaceHeight =
                    getDimen(context, DATE_WEATHER_VIEW_HEIGHT).toFloat()
                clockInteractor.setNotificationStackDefaultTop(
@@ -266,6 +268,10 @@ constructor(
                        dateWeatherSmartspaceHeight +
                        marginBetweenSmartspaceAndNotification
                )
            } else {
                clockInteractor.setNotificationStackDefaultTop(
                    (smallClockBottom + marginBetweenSmartspaceAndNotification).toFloat()
                )
            }
        }

Loading