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

Commit 70cd8eaf authored by András Kurucz's avatar András Kurucz
Browse files

[Flexiglass] Simplify NSSL's stack height calculation

Separate the Flexiglass and the Legacy way of calculating the stack
height. When Flexiglass is enabled:
 - verify that we never add listeners to
   NSSL.mStackHeightChangeListeners
 - stop setting NSSL.mContentHeight, and use mIntrinsicContentHeight
   instead
 - don't use NSSL.getIntrinsicPadding()
 - don't use NSSL.getScrimTopPadding()

Bug: 332574413
Fixes: 347768714
Test: manually verify if the stack height is updated correctly in the
shade, and in the lock screen
Flag: com.android.systemui.scene_container

Change-Id: Ic05953a85f7c8b3855eea5e2c8a04f2ea8445cd8
parent dd998443
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -255,8 +255,8 @@ public class NotificationShelf extends ActivatableNotificationView {
        }

        final float stackBottom = SceneContainerFlag.isEnabled()
                ? ambientState.getStackTop() + ambientState.getStackHeight()
                : ambientState.getStackY() + ambientState.getStackHeight();
                ? ambientState.getStackTop() + ambientState.getInterpolatedStackHeight()
                : ambientState.getStackY() + ambientState.getInterpolatedStackHeight();

        if (viewState.hidden) {
            // if the shelf is hidden, position it at the end of the stack (plus the clip
+9 −7
Original line number Diff line number Diff line
@@ -173,7 +173,8 @@ public class AmbientState implements Dumpable {
    }

    /**
     * @return Height of the notifications panel without top padding when expansion completes.
     * @return Height of the available space for the notification content, when the shade
     * expansion completes.
     */
    public float getStackEndHeight() {
        return mStackEndHeight;
@@ -276,17 +277,18 @@ public class AmbientState implements Dumpable {
    }

    /**
     * @see #getStackHeight()
     * @return Height of the notification content returned by {@link #getStackEndHeight()}, but
     * interpolated by the shade expansion fraction.
     */
    public void setStackHeight(float stackHeight) {
        mStackHeight = stackHeight;
    public float getInterpolatedStackHeight() {
        return mStackHeight;
    }

    /**
     * @return Height of notifications panel interpolated by the expansion fraction.
     * @see #getInterpolatedStackHeight()
     */
    public float getStackHeight() {
        return mStackHeight;
    public void setInterpolatedStackHeight(float stackHeight) {
        mStackHeight = stackHeight;
    }

    @Inject
+36 −15
Original line number Diff line number Diff line
@@ -875,7 +875,7 @@ public class NotificationStackScrollLayout
        y = (int) (mAmbientState.getStackY());
        drawDebugInfo(canvas, y, Color.CYAN, /* label= */ "mAmbientState.getStackY() = " + y);

        y = (int) (mAmbientState.getStackY() + mAmbientState.getStackHeight());
        y = (int) (mAmbientState.getStackY() + mAmbientState.getInterpolatedStackHeight());
        drawDebugInfo(canvas, y, Color.LTGRAY,
                /* label= */ "mAmbientState.getStackY() + mAmbientState.getStackHeight() = " + y);

@@ -1124,11 +1124,13 @@ public class NotificationStackScrollLayout

    @Override
    public void addStackHeightChangedListener(@NonNull Runnable runnable) {
        if (SceneContainerFlag.isUnexpectedlyInLegacyMode()) return;
        mStackHeightChangedListeners.addIfAbsent(runnable);
    }

    @Override
    public void removeStackHeightChangedListener(@NonNull Runnable runnable) {
        if (SceneContainerFlag.isUnexpectedlyInLegacyMode()) return;
        mStackHeightChangedListeners.remove(runnable);
    }

@@ -1477,7 +1479,7 @@ public class NotificationStackScrollLayout

    @VisibleForTesting
    public void updateStackEndHeightAndStackHeight(float fraction) {
        final float oldStackHeight = mAmbientState.getStackHeight();
        final float oldStackHeight = mAmbientState.getInterpolatedStackHeight();
        if (SceneContainerFlag.isEnabled()) {
            final float endHeight;
            if (!shouldSkipHeightUpdate()) {
@@ -1485,20 +1487,20 @@ public class NotificationStackScrollLayout
            } else {
                endHeight = mAmbientState.getStackEndHeight();
            }
            updateStackHeight(endHeight, fraction);
            updateInterpolatedStackHeight(endHeight, fraction);
        } else {
            if (mQsExpansionFraction <= 0 && !shouldSkipHeightUpdate()) {
                final float endHeight = updateStackEndHeight(
                        getHeight(), getEmptyBottomMarginInternal(), getTopPadding());
                updateStackHeight(endHeight, fraction);
                updateInterpolatedStackHeight(endHeight, fraction);
            } else {
                // Always updateStackHeight to prevent jumps in the stack height when this fraction
                // suddenly reapplies after a freeze.
                final float endHeight = mAmbientState.getStackEndHeight();
                updateStackHeight(endHeight, fraction);
                updateInterpolatedStackHeight(endHeight, fraction);
            }
        }
        if (oldStackHeight != mAmbientState.getStackHeight()) {
        if (oldStackHeight != mAmbientState.getInterpolatedStackHeight()) {
            requestChildrenUpdate();
        }
    }
@@ -1532,7 +1534,7 @@ public class NotificationStackScrollLayout
    }

    @VisibleForTesting
    public void updateStackHeight(float endHeight, float fraction) {
    public void updateInterpolatedStackHeight(float endHeight, float fraction) {
        if (!newAodTransition()) {
            // During the (AOD<=>LS) transition where dozeAmount is changing,
            // apply dozeAmount to stack height instead of expansionFraction
@@ -1542,7 +1544,7 @@ public class NotificationStackScrollLayout
                fraction = 1f - dozeAmount;
            }
        }
        mAmbientState.setStackHeight(
        mAmbientState.setInterpolatedStackHeight(
                MathUtils.lerp(endHeight * StackScrollAlgorithm.START_FRACTION,
                        endHeight, fraction));
    }
@@ -2523,10 +2525,33 @@ public class NotificationStackScrollLayout
    }

    @VisibleForTesting
    void updateContentHeight() {
    void updateStackHeight() {
        if (SceneContainerFlag.isUnexpectedlyInLegacyMode()) return;

        final int shelfIntrinsicHeight = mShelf != null ? mShelf.getIntrinsicHeight() : 0;
        final int footerIntrinsicHeight =
                mFooterView != null ? mFooterView.getIntrinsicHeight() : 0;
        final int notificationsHeight = (int) mNotificationStackSizeCalculator.computeHeight(
                /* notificationStackScrollLayout= */ this,
                mMaxDisplayedNotifications,
                shelfIntrinsicHeight
        );
        mIntrinsicContentHeight = notificationsHeight;
        final int fullStackHeight = notificationsHeight + footerIntrinsicHeight + mBottomPadding;
        if (mScrollViewFields.getIntrinsicStackHeight() != fullStackHeight) {
            mScrollViewFields.setIntrinsicStackHeight(fullStackHeight);
            notifyStackHeightChangedListeners();
        }
    }

    private void updateContentHeight() {
        if (SceneContainerFlag.isEnabled()) {
            updateStackHeight();
            return;
        }

        final float scrimTopPadding = getScrimTopPaddingOrZero();
        final int shelfIntrinsicHeight = mShelf != null ? mShelf.getIntrinsicHeight() : 0;
        final int footerIntrinsicHeight = mFooterView != null ? mFooterView.getIntrinsicHeight() : 0;
        final float height =
                (int) scrimTopPadding + (int) mNotificationStackSizeCalculator.computeHeight(
                        /* notificationStackScrollLayout= */ this, mMaxDisplayedNotifications,
@@ -2537,19 +2562,15 @@ public class NotificationStackScrollLayout
        // state the maxPanelHeight and the contentHeight should be bigger
        mContentHeight =
                (int) (height + Math.max(getIntrinsicPadding(), getTopPadding()) + mBottomPadding);
        mScrollViewFields.setIntrinsicStackHeight(
                (int) (getIntrinsicPadding() + mIntrinsicContentHeight + footerIntrinsicHeight
                        + mBottomPadding));
        updateScrollability();
        clampScrollPosition();
        updateStackPosition();
        mAmbientState.setContentHeight(mContentHeight);

        notifyStackHeightChangedListeners();
    }

    @Override
    public int getIntrinsicStackHeight() {
        if (SceneContainerFlag.isUnexpectedlyInLegacyMode()) return 0;
        return mScrollViewFields.getIntrinsicStackHeight();
    }

+3 −2
Original line number Diff line number Diff line
@@ -575,7 +575,8 @@ public class StackScrollAlgorithm {
        final float shelfHeight = showingShelf ? ambientState.getShelf().getIntrinsicHeight() : 0f;
        final float scrimPadding = getScrimTopPaddingOrZero(ambientState);

        final float stackHeight = ambientState.getStackHeight() - shelfHeight - scrimPadding;
        final float stackHeight =
                ambientState.getInterpolatedStackHeight() - shelfHeight - scrimPadding;
        final float stackEndHeight = ambientState.getStackEndHeight() - shelfHeight - scrimPadding;
        if (stackEndHeight == 0f) {
            // This should not happen, since even when the shade is empty we show EmptyShadeView
@@ -734,7 +735,7 @@ public class StackScrollAlgorithm {
                            || ambientState.getDozeAmount() == 1f
                            || bypassPulseNotExpanding
                            ? ambientState.getInnerHeight()
                            : ambientState.getStackHeight();
                            : ambientState.getInterpolatedStackHeight();
                    final float shelfStart = stackBottom
                            - ambientState.getShelf().getIntrinsicHeight()
                            - mPaddingBetweenElements;
+9 −9
Original line number Diff line number Diff line
@@ -342,7 +342,7 @@ open class NotificationShelfTest : SysuiTestCase() {
        val stackTop = 200f
        val stackHeight = 800f
        whenever(ambientState.stackTop).thenReturn(stackTop)
        whenever(ambientState.stackHeight).thenReturn(stackHeight)
        whenever(ambientState.interpolatedStackHeight).thenReturn(stackHeight)
        val shelfTop = stackTop + stackHeight - shelf.height
        val stackScrollAlgorithmState = StackScrollAlgorithmState()
        val viewInShelf = mock(ExpandableView::class.java)
@@ -378,7 +378,7 @@ open class NotificationShelfTest : SysuiTestCase() {
        val stackTop = 200f
        val stackHeight = 800f
        whenever(ambientState.stackTop).thenReturn(stackTop)
        whenever(ambientState.stackHeight).thenReturn(stackHeight)
        whenever(ambientState.interpolatedStackHeight).thenReturn(stackHeight)
        val paddingBetweenElements =
            context.resources.getDimensionPixelSize(R.dimen.notification_divider_height)
        whenever(ambientState.isShadeExpanded).thenReturn(true)
@@ -404,7 +404,7 @@ open class NotificationShelfTest : SysuiTestCase() {
    fun updateState_withNullLastVisibleBackgroundChild_hideShelf() {
        // GIVEN
        whenever(ambientState.stackY).thenReturn(100f)
        whenever(ambientState.stackHeight).thenReturn(100f)
        whenever(ambientState.interpolatedStackHeight).thenReturn(100f)
        val paddingBetweenElements =
            context.resources.getDimensionPixelSize(R.dimen.notification_divider_height)
        val endOfStack = 200f + paddingBetweenElements
@@ -433,7 +433,7 @@ open class NotificationShelfTest : SysuiTestCase() {
        val stackTop = 200f
        val stackHeight = 800f
        whenever(ambientState.stackTop).thenReturn(stackTop)
        whenever(ambientState.stackHeight).thenReturn(stackHeight)
        whenever(ambientState.interpolatedStackHeight).thenReturn(stackHeight)
        val paddingBetweenElements =
            context.resources.getDimensionPixelSize(R.dimen.notification_divider_height)
        whenever(ambientState.isShadeExpanded).thenReturn(true)
@@ -459,7 +459,7 @@ open class NotificationShelfTest : SysuiTestCase() {
    fun updateState_withNullFirstViewInShelf_hideShelf() {
        // GIVEN
        whenever(ambientState.stackY).thenReturn(100f)
        whenever(ambientState.stackHeight).thenReturn(100f)
        whenever(ambientState.interpolatedStackHeight).thenReturn(100f)
        val paddingBetweenElements =
            context.resources.getDimensionPixelSize(R.dimen.notification_divider_height)
        val endOfStack = 200f + paddingBetweenElements
@@ -488,7 +488,7 @@ open class NotificationShelfTest : SysuiTestCase() {
        val stackTop = 200f
        val stackHeight = 800f
        whenever(ambientState.stackTop).thenReturn(stackTop)
        whenever(ambientState.stackHeight).thenReturn(stackHeight)
        whenever(ambientState.interpolatedStackHeight).thenReturn(stackHeight)
        val paddingBetweenElements =
            context.resources.getDimensionPixelSize(R.dimen.notification_divider_height)
        val lastVisibleBackgroundChild = mock<ExpandableView>()
@@ -514,7 +514,7 @@ open class NotificationShelfTest : SysuiTestCase() {
    fun updateState_withCollapsedShade_hideShelf() {
        // GIVEN
        whenever(ambientState.stackY).thenReturn(100f)
        whenever(ambientState.stackHeight).thenReturn(100f)
        whenever(ambientState.interpolatedStackHeight).thenReturn(100f)
        val paddingBetweenElements =
            context.resources.getDimensionPixelSize(R.dimen.notification_divider_height)
        val endOfStack = 200f + paddingBetweenElements
@@ -543,7 +543,7 @@ open class NotificationShelfTest : SysuiTestCase() {
        val stackTop = 200f
        val stackHeight = 800f
        whenever(ambientState.stackTop).thenReturn(stackTop)
        whenever(ambientState.stackHeight).thenReturn(stackHeight)
        whenever(ambientState.interpolatedStackHeight).thenReturn(stackHeight)
        val paddingBetweenElements =
            context.resources.getDimensionPixelSize(R.dimen.notification_divider_height)
        whenever(ambientState.isShadeExpanded).thenReturn(true)
@@ -583,7 +583,7 @@ open class NotificationShelfTest : SysuiTestCase() {
    fun updateState_withHiddenSectionBeforeShelf_hideShelf() {
        // GIVEN
        whenever(ambientState.stackY).thenReturn(100f)
        whenever(ambientState.stackHeight).thenReturn(100f)
        whenever(ambientState.interpolatedStackHeight).thenReturn(100f)
        val paddingBetweenElements =
            context.resources.getDimensionPixelSize(R.dimen.notification_divider_height)
        val endOfStack = 200f + paddingBetweenElements
Loading