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

Commit acb41b15 authored by Shawn Lee's avatar Shawn Lee
Browse files

[flexiglass] Update HUN position when placeholder moves during snooze

Bug: 357661886
Test: manually verified that the HUN position follows the HUN placeholder when dragged and flung
Flag: com.android.systemui.scene_container
Change-Id: I4ccf53bc6c52be0b86fa628873801f31cfcf57ef
parent cffff723
Loading
Loading
Loading
Loading
+5 −11
Original line number Diff line number Diff line
@@ -68,7 +68,6 @@ import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.layout.onPlaced
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.layout.positionInWindow
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.unit.Dp
@@ -82,7 +81,6 @@ import com.android.compose.animation.scene.LowestZIndexContentPicker
import com.android.compose.animation.scene.NestedScrollBehavior
import com.android.compose.animation.scene.SceneScope
import com.android.compose.modifiers.thenIf
import com.android.internal.policy.SystemBarUtils
import com.android.systemui.common.ui.compose.windowinsets.LocalRawScreenHeight
import com.android.systemui.common.ui.compose.windowinsets.LocalScreenCornerRadius
import com.android.systemui.res.R
@@ -137,14 +135,16 @@ fun SceneScope.HeadsUpNotificationSpace(
                .notificationHeadsUpHeight(stackScrollView)
                .debugBackground(viewModel, DEBUG_HUN_COLOR)
                .onGloballyPositioned { coordinates: LayoutCoordinates ->
                    val positionInWindow = coordinates.positionInWindow()
                    val boundsInWindow = coordinates.boundsInWindow()
                    debugLog(viewModel) {
                        "HUNS onGloballyPositioned:" +
                            " size=${coordinates.size}" +
                            " bounds=$boundsInWindow"
                    }
                    // Note: boundsInWindow doesn't scroll off the screen
                    stackScrollView.setHeadsUpTop(boundsInWindow.top)
                    // Note: boundsInWindow doesn't scroll off the screen, so use positionInWindow
                    // for top bound, which can scroll off screen while snoozing
                    stackScrollView.setHeadsUpTop(positionInWindow.y)
                    stackScrollView.setHeadsUpBottom(boundsInWindow.bottom)
                }
    )
@@ -159,16 +159,10 @@ fun SceneScope.SnoozeableHeadsUpNotificationSpace(
    stackScrollView: NotificationScrollView,
    viewModel: NotificationsPlaceholderViewModel,
) {
    val context = LocalContext.current
    val density = LocalDensity.current
    val statusBarHeight = SystemBarUtils.getStatusBarHeight(context)
    val headsUpPadding =
        with(density) { dimensionResource(id = R.dimen.heads_up_status_bar_padding).roundToPx() }

    val isHeadsUp by viewModel.isHeadsUpOrAnimatingAway.collectAsStateWithLifecycle(false)

    var scrollOffset by remember { mutableFloatStateOf(0f) }
    val minScrollOffset = -(statusBarHeight + headsUpPadding.toFloat())
    val minScrollOffset = -(stackScrollView.getHeadsUpInset().toFloat())
    val maxScrollOffset = 0f

    val scrollableState = rememberScrollableState { delta ->
+6 −0
Original line number Diff line number Diff line
@@ -1244,6 +1244,7 @@ public class NotificationStackScrollLayout
    @Override
    public void setHeadsUpTop(float headsUpTop) {
        mAmbientState.setHeadsUpTop(headsUpTop);
        requestChildrenUpdate();
    }

    @Override
@@ -2533,6 +2534,11 @@ public class NotificationStackScrollLayout
        return getTopHeadsUpIntrinsicHeight();
    }

    @Override
    public int getHeadsUpInset() {
        return mHeadsUpInset;
    }

    /**
     * Calculate the gap height between two different views
     *
+3 −0
Original line number Diff line number Diff line
@@ -86,6 +86,9 @@ interface NotificationScrollView {
    /** Sets whether the view is displayed in doze mode. */
    fun setDozing(dozing: Boolean)

    /** Gets the inset for HUNs when they are not visible */
    fun getHeadsUpInset(): Int

    /** Adds a listener to be notified, when the stack height might have changed. */
    fun addStackHeightChangedListener(runnable: Runnable)

+5 −1
Original line number Diff line number Diff line
@@ -88,7 +88,11 @@ constructor(
            launch { viewModel.qsExpandFraction.collect { view.setQsExpandFraction(it) } }
            launch { viewModel.isScrollable.collect { view.setScrollingEnabled(it) } }
            launch { viewModel.isDozing.collect { isDozing -> view.setDozing(isDozing) } }
            launch { viewModel.shouldResetStackTop.filter { it }.collect { view.setStackTop(0f) } }
            launch {
                viewModel.shouldResetStackTop
                    .filter { it }
                    .collect { view.setStackTop(-(view.getHeadsUpInset().toFloat())) }
            }

            launchAndDispose {
                view.setSyntheticScrollConsumer(viewModel.syntheticScrollConsumer)