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

Commit 9fea83c3 authored by Jeff DeCew's avatar Jeff DeCew
Browse files

Apply contentAlpha for brightness mirror to notifications

The alpha value is:
* Stored in NotificationPlaceHolderRepository
* Bound to NotificationStackView
* Combined (via min) with other alphas in NSSLController
* Applied to NSSL

Fixes: 332558331
Test: atest SystemUiRoboTest
Flag: com.android.systemui.scene_container
Change-Id: I6f88117d767b9a8e7eb76c8f27089f0b532ada9c
parent 59c1c2be
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
@@ -150,6 +151,9 @@ private fun SceneScope.QuickSettingsScene(
            label = "alphaAnimationBrightnessMirrorContentHiding",
        )

    viewModel.notifications.setAlphaForBrightnessMirror(contentAlpha)
    DisposableEffect(Unit) { onDispose { viewModel.notifications.setAlphaForBrightnessMirror(1f) } }

    BrightnessMirror(
        viewModel = viewModel.brightnessMirrorViewModel,
        qsSceneAdapter = viewModel.qsSceneAdapter
+4 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
@@ -327,6 +328,9 @@ private fun SceneScope.SplitShade(
            label = "alphaAnimationBrightnessMirrorContentHiding",
        )

    viewModel.notifications.setAlphaForBrightnessMirror(contentAlpha)
    DisposableEffect(Unit) { onDispose { viewModel.notifications.setAlphaForBrightnessMirror(1f) } }

    val brightnessMirrorShowingModifier = Modifier.graphicsLayer { alpha = contentAlpha }

    Box(
+21 −8
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@ class NotificationStackAppearanceIntegrationTest : SysuiTestCase() {
        }
    private val testScope = kosmos.testScope
    private val placeholderViewModel by lazy { kosmos.notificationsPlaceholderViewModel }
    private val appearanceViewModel by lazy { kosmos.notificationScrollViewModel }
    private val scrollViewModel by lazy { kosmos.notificationScrollViewModel }
    private val sceneInteractor by lazy { kosmos.sceneInteractor }
    private val fakeSceneDataSource by lazy { kosmos.fakeSceneDataSource }

@@ -67,7 +67,7 @@ class NotificationStackAppearanceIntegrationTest : SysuiTestCase() {
        testScope.runTest {
            val radius = MutableStateFlow(32)
            val leftOffset = MutableStateFlow(0)
            val shape by collectLastValue(appearanceViewModel.shadeScrimShape(radius, leftOffset))
            val shape by collectLastValue(scrollViewModel.shadeScrimShape(radius, leftOffset))

            placeholderViewModel.onScrimBoundsChanged(
                ShadeScrimBounds(left = 0f, top = 200f, right = 100f, bottom = 550f)
@@ -98,6 +98,19 @@ class NotificationStackAppearanceIntegrationTest : SysuiTestCase() {
                )
        }

    @Test
    fun brightnessMirrorAlpha_updatesViewModel() =
        testScope.runTest {
            val maxAlpha by collectLastValue(scrollViewModel.maxAlpha)
            assertThat(maxAlpha).isEqualTo(1f)
            placeholderViewModel.setAlphaForBrightnessMirror(0.33f)
            assertThat(maxAlpha).isEqualTo(0.33f)
            placeholderViewModel.setAlphaForBrightnessMirror(0f)
            assertThat(maxAlpha).isEqualTo(0f)
            placeholderViewModel.setAlphaForBrightnessMirror(1f)
            assertThat(maxAlpha).isEqualTo(1f)
        }

    @Test
    fun shadeExpansion_goneToShade() =
        testScope.runTest {
@@ -106,9 +119,9 @@ class NotificationStackAppearanceIntegrationTest : SysuiTestCase() {
                    ObservableTransitionState.Idle(scene = Scenes.Gone)
                )
            sceneInteractor.setTransitionState(transitionState)
            val expandFraction by collectLastValue(appearanceViewModel.expandFraction)
            val expandFraction by collectLastValue(scrollViewModel.expandFraction)
            assertThat(expandFraction).isEqualTo(0f)
            val isScrollable by collectLastValue(appearanceViewModel.isScrollable)
            val isScrollable by collectLastValue(scrollViewModel.isScrollable)
            assertThat(isScrollable).isFalse()

            fakeSceneDataSource.pause()
@@ -143,9 +156,9 @@ class NotificationStackAppearanceIntegrationTest : SysuiTestCase() {
                    ObservableTransitionState.Idle(scene = Scenes.Lockscreen)
                )
            sceneInteractor.setTransitionState(transitionState)
            val expandFraction by collectLastValue(appearanceViewModel.expandFraction)
            val expandFraction by collectLastValue(scrollViewModel.expandFraction)
            assertThat(expandFraction).isEqualTo(1f)
            val isScrollable by collectLastValue(appearanceViewModel.isScrollable)
            val isScrollable by collectLastValue(scrollViewModel.isScrollable)
            assertThat(isScrollable).isFalse()
        }

@@ -157,11 +170,11 @@ class NotificationStackAppearanceIntegrationTest : SysuiTestCase() {
                    ObservableTransitionState.Idle(scene = Scenes.Shade)
                )
            sceneInteractor.setTransitionState(transitionState)
            val expandFraction by collectLastValue(appearanceViewModel.expandFraction)
            val expandFraction by collectLastValue(scrollViewModel.expandFraction)
            assertThat(expandFraction).isEqualTo(1f)

            fakeSceneDataSource.changeScene(toScene = Scenes.Shade)
            val isScrollable by collectLastValue(appearanceViewModel.isScrollable)
            val isScrollable by collectLastValue(scrollViewModel.isScrollable)
            assertThat(isScrollable).isTrue()

            fakeSceneDataSource.pause()
+6 −0
Original line number Diff line number Diff line
@@ -1146,11 +1146,17 @@ public class NotificationStackScrollLayout
        }
    }

    @NonNull
    @Override
    public View asView() {
        return this;
    }

    @Override
    public void setMaxAlpha(float alpha) {
        mController.setMaxAlphaFromView(alpha);
    }

    @Override
    public void setScrolledToTop(boolean scrolledToTop) {
        mScrollViewFields.setScrolledToTop(scrolledToTop);
+8 −1
Original line number Diff line number Diff line
@@ -356,6 +356,7 @@ public class NotificationStackScrollLayoutController implements Dumpable {
    private float mMaxAlphaForKeyguard = 1.0f;
    private String mMaxAlphaForKeyguardSource = "constructor";
    private float mMaxAlphaForUnhide = 1.0f;
    private float mMaxAlphaFromView = 1.0f;

    /**
     * Maximum alpha when to and from or sitting idle on the glanceable hub. Will be 1.0f when the
@@ -1317,9 +1318,14 @@ public class NotificationStackScrollLayoutController implements Dumpable {
        updateAlpha();
    }

    void setMaxAlphaFromView(float alpha) {
        mMaxAlphaFromView = alpha;
        updateAlpha();
    }

    private void updateAlpha() {
        if (mView != null) {
            mView.setAlpha(Math.min(mMaxAlphaForKeyguard,
            mView.setAlpha(Math.min(Math.min(mMaxAlphaFromView, mMaxAlphaForKeyguard),
                    Math.min(mMaxAlphaForUnhide, mMaxAlphaForGlanceableHub)));
        }
    }
@@ -1789,6 +1795,7 @@ public class NotificationStackScrollLayoutController implements Dumpable {

    @Override
    public void dump(@NonNull PrintWriter pw, @NonNull String[] args) {
        pw.println("mMaxAlphaFromView=" + mMaxAlphaFromView);
        pw.println("mMaxAlphaForUnhide=" + mMaxAlphaForUnhide);
        pw.println("mMaxAlphaForGlanceableHub=" + mMaxAlphaForGlanceableHub);
        pw.println("mMaxAlphaForKeyguard=" + mMaxAlphaForKeyguard);
Loading