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

Commit 58d33353 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Fix disappearing HUN when drag down from heads up" into rvc-dev am: 1ef59a81

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11901358

Change-Id: I982da5db99a7692d829af762ebd115764952de06
parents 0be5b828 1ef59a81
Loading
Loading
Loading
Loading
+25 −0
Original line number Original line Diff line number Diff line
@@ -83,6 +83,8 @@ public class AmbientState {
    private float mDozeAmount = 0.0f;
    private float mDozeAmount = 0.0f;
    private HeadsUpManager mHeadUpManager;
    private HeadsUpManager mHeadUpManager;
    private Runnable mOnPulseHeightChangedListener;
    private Runnable mOnPulseHeightChangedListener;
    private ExpandableNotificationRow mTrackedHeadsUpRow;
    private float mAppearFraction;


    public AmbientState(
    public AmbientState(
            Context context,
            Context context,
@@ -543,4 +545,27 @@ public class AmbientState {
    public Runnable getOnPulseHeightChangedListener() {
    public Runnable getOnPulseHeightChangedListener() {
        return mOnPulseHeightChangedListener;
        return mOnPulseHeightChangedListener;
    }
    }

    public void setTrackedHeadsUpRow(ExpandableNotificationRow row) {
        mTrackedHeadsUpRow = row;
    }

    /**
     * Returns the currently tracked heads up row, if there is one and it is currently above the
     * shelf (still appearing).
     */
    public ExpandableNotificationRow getTrackedHeadsUpRow() {
        if (mTrackedHeadsUpRow == null || !mTrackedHeadsUpRow.isAboveShelf()) {
            return null;
        }
        return mTrackedHeadsUpRow;
    }

    public void setAppearFraction(float appearFraction) {
        mAppearFraction = appearFraction;
    }

    public float getAppearFraction() {
        return mAppearFraction;
    }
}
}
+23 −16
Original line number Original line Diff line number Diff line
@@ -1420,14 +1420,12 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd
                // start
                // start
                translationY = height - appearStartPosition + getExpandTranslationStart();
                translationY = height - appearStartPosition + getExpandTranslationStart();
            }
            }
            stackHeight = (int) (height - translationY);
            if (isHeadsUpTransition()) {
            if (isHeadsUpTransition()) {
                stackHeight =
                        getFirstVisibleSection().getFirstVisibleChild().getPinnedHeadsUpHeight();
                translationY = MathUtils.lerp(mHeadsUpInset - mTopPadding, 0, appearFraction);
                translationY = MathUtils.lerp(mHeadsUpInset - mTopPadding, 0, appearFraction);
            } else {
                stackHeight = (int) (height - translationY);
            }
            }
        }
        }
        mAmbientState.setAppearFraction(appearFraction);
        if (stackHeight != mCurrentStackHeight) {
        if (stackHeight != mCurrentStackHeight) {
            mCurrentStackHeight = stackHeight;
            mCurrentStackHeight = stackHeight;
            updateAlgorithmHeightAndPadding();
            updateAlgorithmHeightAndPadding();
@@ -1545,17 +1543,18 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd
     */
     */
    @ShadeViewRefactor(RefactorComponent.COORDINATOR)
    @ShadeViewRefactor(RefactorComponent.COORDINATOR)
    private float getAppearEndPosition() {
    private float getAppearEndPosition() {
        int appearPosition;
        int appearPosition = 0;
        int notGoneChildCount = getNotGoneChildCount();
        int visibleNotifCount = getVisibleNotificationCount();
        if (mEmptyShadeView.getVisibility() == GONE && notGoneChildCount != 0) {
        if (mEmptyShadeView.getVisibility() == GONE && visibleNotifCount > 0) {
            if (isHeadsUpTransition()
            if (isHeadsUpTransition()
                    || (mHeadsUpManager.hasPinnedHeadsUp() && !mAmbientState.isDozing())) {
                    || (mHeadsUpManager.hasPinnedHeadsUp() && !mAmbientState.isDozing())) {
                appearPosition = getTopHeadsUpPinnedHeight();
                if (mShelf.getVisibility() != GONE && visibleNotifCount > 1) {
            } else {
                    appearPosition += mShelf.getIntrinsicHeight() + mPaddingBetweenElements;
                appearPosition = 0;
                if (notGoneChildCount >= 1 && mShelf.getVisibility() != GONE) {
                    appearPosition += mShelf.getIntrinsicHeight();
                }
                }
                appearPosition += getTopHeadsUpPinnedHeight()
                        + getPositionInLinearLayout(mAmbientState.getTrackedHeadsUpRow());
            } else if (mShelf.getVisibility() != GONE) {
                appearPosition += mShelf.getIntrinsicHeight();
            }
            }
        } else {
        } else {
            appearPosition = mEmptyShadeView.getHeight();
            appearPosition = mEmptyShadeView.getHeight();
@@ -1565,9 +1564,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd


    @ShadeViewRefactor(RefactorComponent.SHADE_VIEW)
    @ShadeViewRefactor(RefactorComponent.SHADE_VIEW)
    private boolean isHeadsUpTransition() {
    private boolean isHeadsUpTransition() {
        NotificationSection firstVisibleSection = getFirstVisibleSection();
        return mAmbientState.getTrackedHeadsUpRow() != null;
        return mTrackingHeadsUp && firstVisibleSection != null
                && firstVisibleSection.getFirstVisibleChild().isAboveShelf();
    }
    }


    /**
    /**
@@ -2975,8 +2972,17 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd
    @ShadeViewRefactor(RefactorComponent.COORDINATOR)
    @ShadeViewRefactor(RefactorComponent.COORDINATOR)
    public int getLayoutMinHeight() {
    public int getLayoutMinHeight() {
        if (isHeadsUpTransition()) {
        if (isHeadsUpTransition()) {
            ExpandableNotificationRow trackedHeadsUpRow = mAmbientState.getTrackedHeadsUpRow();
            if (trackedHeadsUpRow.isAboveShelf()) {
                int hunDistance = (int) MathUtils.lerp(
                        0,
                        getPositionInLinearLayout(trackedHeadsUpRow),
                        mAmbientState.getAppearFraction());
                return getTopHeadsUpPinnedHeight() + hunDistance;
            } else {
                return getTopHeadsUpPinnedHeight();
                return getTopHeadsUpPinnedHeight();
            }
            }
        }
        return mShelf.getVisibility() == GONE ? 0 : mShelf.getIntrinsicHeight();
        return mShelf.getVisibility() == GONE ? 0 : mShelf.getIntrinsicHeight();
    }
    }


@@ -5295,6 +5301,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd


    @ShadeViewRefactor(RefactorComponent.SHADE_VIEW)
    @ShadeViewRefactor(RefactorComponent.SHADE_VIEW)
    public void setTrackingHeadsUp(ExpandableNotificationRow row) {
    public void setTrackingHeadsUp(ExpandableNotificationRow row) {
        mAmbientState.setTrackedHeadsUpRow(row);
        mTrackingHeadsUp = row != null;
        mTrackingHeadsUp = row != null;
        mRoundnessManager.setTrackingHeadsUp(row);
        mRoundnessManager.setTrackingHeadsUp(row);
    }
    }
+24 −5
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@ import android.annotation.Nullable;
import android.content.Context;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.Resources;
import android.util.Log;
import android.util.Log;
import android.util.MathUtils;
import android.view.View;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup;


@@ -441,7 +442,7 @@ public class StackScrollAlgorithm {
        } else if (isEmptyShadeView) {
        } else if (isEmptyShadeView) {
            childViewState.yTranslation = ambientState.getInnerHeight() - childHeight
            childViewState.yTranslation = ambientState.getInnerHeight() - childHeight
                    + ambientState.getStackTranslation() * 0.25f;
                    + ambientState.getStackTranslation() * 0.25f;
        } else {
        } else if (child != ambientState.getTrackedHeadsUpRow()) {
            clampPositionToShelf(child, childViewState, ambientState);
            clampPositionToShelf(child, childViewState, ambientState);
        }
        }


@@ -539,6 +540,19 @@ public class StackScrollAlgorithm {
    private void updateHeadsUpStates(StackScrollAlgorithmState algorithmState,
    private void updateHeadsUpStates(StackScrollAlgorithmState algorithmState,
            AmbientState ambientState) {
            AmbientState ambientState) {
        int childCount = algorithmState.visibleChildren.size();
        int childCount = algorithmState.visibleChildren.size();

        // Move the tracked heads up into position during the appear animation, by interpolating
        // between the HUN inset (where it will appear as a HUN) and the end position in the shade
        ExpandableNotificationRow trackedHeadsUpRow = ambientState.getTrackedHeadsUpRow();
        if (trackedHeadsUpRow != null) {
            ExpandableViewState childState = trackedHeadsUpRow.getViewState();
            if (childState != null) {
                float endPosition = childState.yTranslation - ambientState.getStackTranslation();
                childState.yTranslation = MathUtils.lerp(
                        mHeadsUpInset, endPosition, ambientState.getAppearFraction());
            }
        }

        ExpandableNotificationRow topHeadsUpEntry = null;
        ExpandableNotificationRow topHeadsUpEntry = null;
        for (int i = 0; i < childCount; i++) {
        for (int i = 0; i < childCount; i++) {
            View child = algorithmState.visibleChildren.get(i);
            View child = algorithmState.visibleChildren.get(i);
@@ -561,7 +575,7 @@ public class StackScrollAlgorithm {
                        && !row.showingPulsing()) {
                        && !row.showingPulsing()) {
                    // Ensure that the heads up is always visible even when scrolled off
                    // Ensure that the heads up is always visible even when scrolled off
                    clampHunToTop(ambientState, row, childState);
                    clampHunToTop(ambientState, row, childState);
                    if (i == 0 && row.isAboveShelf()) {
                    if (isTopEntry && row.isAboveShelf()) {
                        // the first hun can't get off screen.
                        // the first hun can't get off screen.
                        clampHunToMaxTranslation(ambientState, row, childState);
                        clampHunToMaxTranslation(ambientState, row, childState);
                        childState.hidden = false;
                        childState.hidden = false;
@@ -636,9 +650,13 @@ public class StackScrollAlgorithm {
            return;
            return;
        }
        }


        ExpandableNotificationRow trackedHeadsUpRow = ambientState.getTrackedHeadsUpRow();
        boolean isBeforeTrackedHeadsUp = trackedHeadsUpRow != null
                && mHostView.indexOfChild(child) < mHostView.indexOfChild(trackedHeadsUpRow);

        int shelfStart = ambientState.getInnerHeight()
        int shelfStart = ambientState.getInnerHeight()
                - ambientState.getShelf().getIntrinsicHeight();
                - ambientState.getShelf().getIntrinsicHeight();
        if (ambientState.isAppearing() && !child.isAboveShelf()) {
        if (ambientState.isAppearing() && !child.isAboveShelf() && !isBeforeTrackedHeadsUp) {
            // Don't show none heads-up notifications while in appearing phase.
            // Don't show none heads-up notifications while in appearing phase.
            childViewState.yTranslation = Math.max(childViewState.yTranslation, shelfStart);
            childViewState.yTranslation = Math.max(childViewState.yTranslation, shelfStart);
        }
        }
@@ -695,7 +713,8 @@ public class StackScrollAlgorithm {
            }
            }
            childViewState.zTranslation = baseZ
            childViewState.zTranslation = baseZ
                    + childrenOnTop * zDistanceBetweenElements;
                    + childrenOnTop * zDistanceBetweenElements;
        } else if (i == 0 && (child.isAboveShelf() || child.showingPulsing())) {
        } else if (child == ambientState.getTrackedHeadsUpRow()
                || (i == 0 && (child.isAboveShelf() || child.showingPulsing()))) {
            // In case this is a new view that has never been measured before, we don't want to
            // In case this is a new view that has never been measured before, we don't want to
            // elevate if we are currently expanded more then the notification
            // elevate if we are currently expanded more then the notification
            int shelfHeight = ambientState.getShelf() == null ? 0 :
            int shelfHeight = ambientState.getShelf() == null ? 0 :
@@ -703,7 +722,7 @@ public class StackScrollAlgorithm {
            float shelfStart = ambientState.getInnerHeight()
            float shelfStart = ambientState.getInnerHeight()
                    - shelfHeight + ambientState.getTopPadding()
                    - shelfHeight + ambientState.getTopPadding()
                    + ambientState.getStackTranslation();
                    + ambientState.getStackTranslation();
            float notificationEnd = childViewState.yTranslation + child.getPinnedHeadsUpHeight()
            float notificationEnd = childViewState.yTranslation + child.getIntrinsicHeight()
                    + mPaddingBetweenElements;
                    + mPaddingBetweenElements;
            if (shelfStart > notificationEnd) {
            if (shelfStart > notificationEnd) {
                childViewState.zTranslation = baseZ;
                childViewState.zTranslation = baseZ;