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

Commit 176aad5f authored by Andre Le's avatar Andre Le Committed by Android (Google) Code Review
Browse files

Merge "Flexiglass: Reposition keyguard ambient indicator based on usfps" into main

parents e1add8bb 4ac22a26
Loading
Loading
Loading
Loading
+93 −35
Original line number Diff line number Diff line
@@ -72,8 +72,8 @@ interface LockscreenLayoutViewModel {
     * `false` if only heads-up notifications are showing).
     */
    val isNotificationsVisible: Boolean
    /** Whether the ambient indication UI should currently be showing. */
    val isAmbientIndicationVisible: Boolean
    /** Whether udfps is supported. */
    val isUdfpsSupported: Boolean
    /** Amount of horizontal translation that should be applied to elements in the scene. */
    val unfoldTranslations: UnfoldTranslations
}
@@ -222,13 +222,25 @@ fun LockscreenSceneLayout(
        }
    }

    /** Convenience function to draw the bottom area without needing to pass a lot of parameters. */
    /**
     * Convenience function to draw the ambient indication without needing to pass a lot of
     * parameters.
     */
    @Composable
    fun bottomArea(modifier: Modifier = Modifier) {
        BottomArea(
            startShortcut = startShortcut,
            isAmbientIndicationVisible = viewModel.isAmbientIndicationVisible,
    fun ambientIndication(modifier: Modifier = Modifier) {
        AmbientIndication(
            ambientIndication = ambientIndication,
            modifier = modifier.navigationBarsPadding(),
        )
    }

    /**
     * Convenience function to draw the shortcut area without needing to pass a lot of parameters.
     */
    @Composable
    fun shortcutArea(modifier: Modifier = Modifier) {
        ShortcutArea(
            startShortcut = startShortcut,
            bottomIndication = bottomIndication,
            endShortcut = endShortcut,
            unfoldTranslations = viewModel.unfoldTranslations,
@@ -255,19 +267,38 @@ fun LockscreenSceneLayout(
            Box(Modifier.graphicsLayer { translationX = viewModel.unfoldTranslations.end }) {
                largeClock()
            }
            bottomArea()

            if (viewModel.isUdfpsSupported) {
                lockIcon()
                ambientIndication()
            } else {
                ambientIndication()
                lockIcon()
            }

            shortcutArea()
            settingsMenu()
        },
        modifier = modifier,
    ) { measurables, constraints ->
        check(measurables.size == 6)
        check(measurables.size == 7)
        val statusBarMeasurable = measurables[0]
        val contentColumnMeasurable = measurables[1]
        val largeClockMeasurable = measurables[2]
        val bottomAreaMeasurable = measurables[3]
        val lockIconMeasurable = measurables[4]
        val settingsMenuMeasurable = measurables[5]
        val ambientIndicationMeasurable =
            if (viewModel.isUdfpsSupported) {
                measurables[4]
            } else {
                measurables[3]
            }
        val lockIconMeasurable =
            if (viewModel.isUdfpsSupported) {
                measurables[3]
            } else {
                measurables[4]
            }
        val shortcutAreaMeasurable = measurables[5]
        val settingsMenuMeasurable = measurables[6]

        val statusBarPlaceable =
            statusBarMeasurable.measure(constraints = Constraints.fixedWidth(constraints.maxWidth))
@@ -349,8 +380,15 @@ fun LockscreenSceneLayout(
                else -> null
            }

        val bottomAreaPlaceable =
            bottomAreaMeasurable.measure(constraints = Constraints.fixedWidth(constraints.maxWidth))
        val ambientIndicationPlaceable =
            ambientIndicationMeasurable.measure(
                constraints = Constraints.fixedWidth(constraints.maxWidth)
            )

        val shortcutAreaPlaceable =
            shortcutAreaMeasurable.measure(
                constraints = Constraints.fixedWidth(constraints.maxWidth)
            )

        val settingsMenuPleaceable = settingsMenuMeasurable.measure(constraints)

@@ -389,8 +427,25 @@ fun LockscreenSceneLayout(
                    },
            )

            bottomAreaPlaceable.place(0, constraints.maxHeight - bottomAreaPlaceable.measuredHeight)
            if (viewModel.isUdfpsSupported) {
                lockIconPlaceable.place(x = lockIconBounds.left, y = lockIconBounds.top)
                ambientIndicationPlaceable.place(
                    0,
                    constraints.maxHeight - ambientIndicationPlaceable.measuredHeight,
                )
            } else {
                ambientIndicationPlaceable.place(
                    0,
                    constraints.maxHeight - ambientIndicationPlaceable.measuredHeight,
                )
                lockIconPlaceable.place(x = lockIconBounds.left, y = lockIconBounds.top)
            }

            shortcutAreaPlaceable.place(
                0,
                constraints.maxHeight - shortcutAreaPlaceable.measuredHeight,
            )

            settingsMenuPleaceable.placeRelative(
                x = (constraints.maxWidth - settingsMenuPleaceable.measuredWidth) / 2,
                y = constraints.maxHeight - settingsMenuPleaceable.measuredHeight,
@@ -399,35 +454,38 @@ fun LockscreenSceneLayout(
    }
}

/** Draws the bottom area of the layout. */
@Composable
private fun BottomArea(
    startShortcut: @Composable () -> Unit,
    isAmbientIndicationVisible: Boolean,
private fun AmbientIndication(
    ambientIndication: @Composable () -> Unit,
    bottomIndication: @Composable () -> Unit,
    endShortcut: @Composable () -> Unit,
    unfoldTranslations: UnfoldTranslations,
    modifier: Modifier = Modifier,
) {
    Column(
        horizontalAlignment = Alignment.CenterHorizontally,
        verticalArrangement = Arrangement.spacedBy(8.dp),
        modifier = modifier.fillMaxWidth().padding(horizontal = 16.dp),
    ) {
        if (isAmbientIndicationVisible) {
        ambientIndication()
    }

        Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth()) {
            Box(Modifier.graphicsLayer { translationX = unfoldTranslations.start }) {
                startShortcut()
}

/** Draws the shortcut area of the layout. */
@Composable
private fun ShortcutArea(
    startShortcut: @Composable () -> Unit,
    bottomIndication: @Composable () -> Unit,
    endShortcut: @Composable () -> Unit,
    unfoldTranslations: UnfoldTranslations,
    modifier: Modifier = Modifier,
) {
    Row(
        horizontalArrangement = Arrangement.Center,
        verticalAlignment = Alignment.CenterVertically,
        modifier = modifier.fillMaxWidth().padding(horizontal = 16.dp),
    ) {
        Box(Modifier.graphicsLayer { translationX = unfoldTranslations.start }) { startShortcut() }
        Box(Modifier.weight(1f)) { bottomIndication() }
        Box(Modifier.graphicsLayer { translationX = unfoldTranslations.end }) { endShortcut() }
    }
}
}

/**
 * Draws the content column.
+6 −6
Original line number Diff line number Diff line
@@ -95,17 +95,17 @@ class LockscreenContentViewModelTest(flags: FlagsParameterization) : SysuiTestCa
    }

    @Test
    fun isAmbientIndicationVisible_withUdfps_false() =
    fun isUdfpsSupported_withoutUdfps_false() =
        kosmos.runTest {
            whenever(authController.isUdfpsSupported).thenReturn(true)
            assertThat(underTest.layout.isAmbientIndicationVisible).isFalse()
            whenever(authController.isUdfpsSupported).thenReturn(false)
            assertThat(underTest.layout.isUdfpsSupported).isFalse()
        }

    @Test
    fun isAmbientIndicationVisible_withoutUdfps_true() =
    fun isUdfpsSupported_withUdfps_true() =
        kosmos.runTest {
            whenever(authController.isUdfpsSupported).thenReturn(false)
            assertThat(underTest.layout.isAmbientIndicationVisible).isTrue()
            whenever(authController.isUdfpsSupported).thenReturn(true)
            assertThat(underTest.layout.isUdfpsSupported).isTrue()
        }

    @Test
+2 −2
Original line number Diff line number Diff line
@@ -146,8 +146,8 @@ constructor(
                    initialValue = activeNotificationsInteractor.areAnyNotificationsPresentValue,
                )

            override val isAmbientIndicationVisible: Boolean
                get() = !authController.isUdfpsSupported
            override val isUdfpsSupported: Boolean
                get() = authController.isUdfpsSupported

            override val unfoldTranslations: UnfoldTranslations =
                object : UnfoldTranslations {