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

Commit 828dd91d authored by Fabián Kozynski's avatar Fabián Kozynski
Browse files

[Flexiglass] Fix brightness mirror

The brightness mirror was not properly aligned after changes for focus.

Replicate BrightnessMirrorController so things match. We also need to
make sure that the mirror container can be wider than its container in
flexiglass.

Also, have two different ways of calculating offset based on the
location of the mirror with respect to the window.

Test: atest com.android.systemui.settings.brightness.ui
Test: manual in phone, unfolded, and landscape
Fixes: 348640465
Flag: com.android.systemui.scene_container

Change-Id: Ic0c500e1dc2258e8b1cb368b8aa42b9ad183ce65
parent 999a6a71
Loading
Loading
Loading
Loading
+18 −3
Original line number Diff line number Diff line
@@ -18,8 +18,9 @@ package com.android.systemui.qs.ui.composable

import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
@@ -39,6 +40,7 @@ fun BrightnessMirror(
    viewModel: BrightnessMirrorViewModel,
    qsSceneAdapter: QSSceneAdapter,
    modifier: Modifier = Modifier,
    measureFromContainer: Boolean = false,
) {
    val isShowing by viewModel.isShowing.collectAsStateWithLifecycle()
    val mirrorAlpha by
@@ -47,9 +49,22 @@ fun BrightnessMirror(
            label = "alphaAnimationBrightnessMirrorShowing",
        )
    val mirrorOffsetAndSize by viewModel.locationAndSize.collectAsStateWithLifecycle()
    val offset = IntOffset(0, mirrorOffsetAndSize.yOffset)
    val yOffset =
        if (measureFromContainer) {
            mirrorOffsetAndSize.yOffsetFromContainer
        } else {
            mirrorOffsetAndSize.yOffsetFromWindow
        }
    val offset = IntOffset(0, yOffset)

    Box(modifier = modifier.fillMaxSize().graphicsLayer { alpha = mirrorAlpha }) {
    // Use unbounded=true as the full mirror (with paddings and background offset) may be larger
    // than the space we have (but it will fit, because the brightness slider fits).
    Box(
        modifier =
            modifier.fillMaxHeight().wrapContentWidth(unbounded = true).graphicsLayer {
                alpha = mirrorAlpha
            }
    ) {
        QuickSettingsTheme {
            // The assumption for using this AndroidView is that there will be only one in view at
            // a given time (which is a reasonable assumption). Because `QSSceneAdapter` (actually
+5 −1
Original line number Diff line number Diff line
@@ -185,7 +185,11 @@ private fun SceneScope.QuickSettingsScene(

    BrightnessMirror(
        viewModel = viewModel.brightnessMirrorViewModel,
        qsSceneAdapter = viewModel.qsSceneAdapter
        qsSceneAdapter = viewModel.qsSceneAdapter,
        modifier =
            Modifier.thenIf(cutoutLocation != CutoutLocation.CENTER) {
                Modifier.displayCutoutPadding()
            }
    )

    val shouldPunchHoleBehindScrim =
+3 −4
Original line number Diff line number Diff line
@@ -36,7 +36,6 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
@@ -474,9 +473,9 @@ private fun SceneScope.SplitShade(
                    BrightnessMirror(
                        viewModel = viewModel.brightnessMirrorViewModel,
                        qsSceneAdapter = viewModel.qsSceneAdapter,
                        // Need to remove the offset of the header height, as the mirror uses
                        // the position of the Brightness slider in the window
                        modifier = Modifier.offset(y = -ShadeHeader.Dimensions.CollapsedHeight)
                        // Need to use the offset measured from the container as the header
                        // has to be accounted for
                        measureFromContainer = true
                    )
                    Column(
                        verticalArrangement = Arrangement.Top,
+23 −0
Original line number Diff line number Diff line
@@ -68,4 +68,27 @@ class BrightnessMirrorInflaterTest : SysuiTestCase() {

        Assert.setTestThread(null)
    }

    @Test
    fun inflate_frameHasPadding() {
        Assert.setTestThread(Thread.currentThread())

        val (frame, _) =
            BrightnessMirrorInflater.inflate(
                themedContext,
                kosmos.brightnessSliderControllerFactory,
            )

        assertThat(frame.visibility).isEqualTo(View.VISIBLE)

        val padding =
            context.resources.getDimensionPixelSize(R.dimen.rounded_slider_background_padding)

        assertThat(frame.paddingLeft).isEqualTo(padding)
        assertThat(frame.paddingTop).isEqualTo(padding)
        assertThat(frame.paddingRight).isEqualTo(padding)
        assertThat(frame.paddingBottom).isEqualTo(padding)

        Assert.setTestThread(null)
    }
}
+20 −35
Original line number Diff line number Diff line
@@ -16,10 +16,9 @@

package com.android.systemui.settings.brightness.ui.viewmodel

import android.content.applicationContext
import android.content.res.mainResources
import android.view.ContextThemeWrapper
import android.view.View
import android.widget.FrameLayout
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
@@ -27,12 +26,10 @@ import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.kosmos.testScope
import com.android.systemui.res.R
import com.android.systemui.settings.brightness.domain.interactor.brightnessMirrorShowingInteractor
import com.android.systemui.settings.brightness.ui.binder.BrightnessMirrorInflater
import com.android.systemui.settings.brightness.ui.viewModel.BrightnessMirrorViewModel
import com.android.systemui.settings.brightness.ui.viewModel.LocationAndSize
import com.android.systemui.settings.brightnessSliderControllerFactory
import com.android.systemui.testKosmos
import com.android.systemui.util.Assert
import com.android.systemui.util.mockito.any
import com.android.systemui.util.mockito.mock
import com.android.systemui.util.mockito.whenever
@@ -47,9 +44,6 @@ class BrightnessMirrorViewModelTest : SysuiTestCase() {

    private val kosmos = testKosmos()

    private val themedContext =
        ContextThemeWrapper(kosmos.applicationContext, R.style.Theme_SystemUI_QuickSettings)

    private val underTest =
        with(kosmos) {
            BrightnessMirrorViewModel(
@@ -76,7 +70,7 @@ class BrightnessMirrorViewModelTest : SysuiTestCase() {
        }

    @Test
    fun setLocationInWindow_correctLocationAndSize() =
    fun locationInWindowAndContainer_correctLocationAndSize() =
        with(kosmos) {
            testScope.runTest {
                val locationAndSize by collectLastValue(underTest.locationAndSize)
@@ -101,6 +95,7 @@ class BrightnessMirrorViewModelTest : SysuiTestCase() {
                        whenever(measuredHeight).thenReturn(height)
                        whenever(measuredWidth).thenReturn(width)
                    }
                val yOffsetFromContainer = setContainerViewHierarchy(mockView)

                underTest.setLocationAndSize(mockView)

@@ -108,7 +103,8 @@ class BrightnessMirrorViewModelTest : SysuiTestCase() {
                    .isEqualTo(
                        // Adjust for padding around the view
                        LocationAndSize(
                            yOffset = y - padding,
                            yOffsetFromWindow = y - padding,
                            yOffsetFromContainer = yOffsetFromContainer - padding,
                            width = width + 2 * padding,
                            height = height + 2 * padding,
                        )
@@ -116,31 +112,20 @@ class BrightnessMirrorViewModelTest : SysuiTestCase() {
            }
        }

    @Test
    fun setLocationInWindow_paddingSetToRootView() =
        with(kosmos) {
            Assert.setTestThread(Thread.currentThread())
            val padding =
                mainResources.getDimensionPixelSize(R.dimen.rounded_slider_background_padding)

            val view = mock<View>()
    private fun setContainerViewHierarchy(mockView: View): Int {
        val rootView = FrameLayout(context)
        val containerView = FrameLayout(context).apply { id = R.id.quick_settings_container }
        val otherView = FrameLayout(context)

            val (_, sliderController) =
                BrightnessMirrorInflater.inflate(
                    themedContext,
                    brightnessSliderControllerFactory,
                )
            underTest.setToggleSlider(sliderController)
        rootView.addView(containerView)
        containerView.addView(otherView)
        otherView.addView(mockView)

            underTest.setLocationAndSize(view)

            with(sliderController.rootView) {
                assertThat(paddingBottom).isEqualTo(padding)
                assertThat(paddingTop).isEqualTo(padding)
                assertThat(paddingLeft).isEqualTo(padding)
                assertThat(paddingRight).isEqualTo(padding)
            }
        containerView.setLeftTopRightBottom(1, /* top= */ 1, 1, 1)
        otherView.setLeftTopRightBottom(0, /* top= */ 2, 0, 0)
        whenever(mockView.parent).thenReturn(otherView)
        whenever(mockView.top).thenReturn(3)

            Assert.setTestThread(null)
        return 2 + 3
    }
}
Loading