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

Commit 40cebe44 authored by Selim Cinek's avatar Selim Cinek
Browse files

Improved the behavior of overscroll

The overscroll logic could get stuck previously, which lead to
a forehead visible on the lock screen.
This improves the logic and animation to look much better.

Fixes: 190029393
Test: expand shade, observe nice overshoot, no forehead on lockscreen
Change-Id: I2c9d5313626d3037c7bd3c942820c391da99b459
parent 00630da0
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -311,6 +311,13 @@ public class FlingAnimationUtils {
        return mMinVelocityPxPerSecond;
    }

    /**
     * @return a velocity considered fast
     */
    public float getHighVelocityPxPerSecond() {
        return mHighVelocityPxPerSecond;
    }

    /**
     * An interpolator which interpolates two interpolators with an interpolator.
     */
+10 −0
Original line number Diff line number Diff line
@@ -93,6 +93,16 @@ public class Interpolators {
                (float) (1.0f - Math.exp(-b * progress)) * (overshootAmount + 1.0f));
    }

    /**
     * Similar to {@link #getOvershootInterpolation(float, float, float)} but the overshoot
     * starts immediately here, instead of first having a section of non-overshooting
     *
     * @param progress a progress value going from 0 to 1
     */
    public static float getOvershootInterpolation(float progress) {
        return MathUtils.max(0.0f, (float) (1.0f - Math.exp(-4 * progress)));
    }

    /**
     * Interpolate alpha for notifications background scrim during shade expansion.
     * @param fraction Shade expansion fraction
+3 −0
Original line number Diff line number Diff line
@@ -771,6 +771,9 @@
    <!-- Move distance for the unlock hint animation on the lockscreen -->
    <dimen name="hint_move_distance">75dp</dimen>

    <!-- The overshoot amount when the panel flings open -->
    <dimen name="panel_overshoot_amount">16dp</dimen>

    <!-- The width of the region on the left/right edge of the screen for performing the camera/
         phone hints. -->
    <dimen name="edge_tap_area_width">48dp</dimen>
+5 −5
Original line number Diff line number Diff line
@@ -83,7 +83,7 @@ public class AmbientState {
    private ExpandableNotificationRow mTrackedHeadsUpRow;
    private float mAppearFraction;
    private boolean mIsShadeOpening;
    private float mSectionPadding;
    private float mOverExpansion;

    /** Distance of top of notifications panel from top of screen. */
    private float mStackY = 0;
@@ -182,12 +182,12 @@ public class AmbientState {
        return mIsShadeOpening;
    }

    void setSectionPadding(float padding) {
        mSectionPadding = padding;
    void setOverExpansion(float overExpansion) {
        mOverExpansion = overExpansion;
    }

    float getSectionPadding() {
        return mSectionPadding;
    float getOverExpansion() {
        return mOverExpansion;
    }

    private static int getZDistanceBetweenElements(Context context) {
+23 −7
Original line number Diff line number Diff line
@@ -119,6 +119,7 @@ import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

import javax.inject.Inject;
import javax.inject.Named;
@@ -470,6 +471,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
                }
            };

    private Consumer<Integer> mScrollListener;
    private final ScrollAdapter mScrollAdapter = new ScrollAdapter() {
        @Override
        public boolean isScrolledToTop() {
@@ -552,8 +554,12 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
        }
    }

    void setSectionPadding(float margin) {
        mAmbientState.setSectionPadding(margin);
    /**
     * Set the overexpansion of the panel to be applied to the view.
     */
    void setOverExpansion(float margin) {
        mAmbientState.setOverExpansion(margin);
        updateStackPosition();
        requestChildrenUpdate();
    }

@@ -1136,7 +1142,8 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
     */
    private void updateStackPosition() {
        // Consider interpolating from an mExpansionStartY for use on lockscreen and AOD
        float endTopPosition = mTopPadding + mExtraTopInsetForFullShadeTransition;
        float endTopPosition = mTopPadding + mExtraTopInsetForFullShadeTransition
                + mAmbientState.getOverExpansion();
        final float fraction = mAmbientState.getExpansionFraction();
        final float stackY = MathUtils.lerp(0, endTopPosition, fraction);
        mAmbientState.setStackY(stackY);
@@ -1144,7 +1151,6 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
            mOnStackYChanged.run();
        }
        if (mQsExpansionFraction <= 0) {
            final float scrimTopPadding = mAmbientState.isOnKeyguard() ? 0 : mSidePaddings;
            final float stackEndHeight = Math.max(0f,
                    getHeight() - getEmptyBottomMargin() - mTopPadding);
            mAmbientState.setStackEndHeight(stackEndHeight);
@@ -1166,7 +1172,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
    @ShadeViewRefactor(RefactorComponent.COORDINATOR)
    public void setExpandedHeight(float height) {
        final float shadeBottom = getHeight() - getEmptyBottomMargin();
        final float expansionFraction = MathUtils.constrain(height / shadeBottom, 0f, 1f);
        final float expansionFraction = MathUtils.saturate(height / shadeBottom);
        mAmbientState.setExpansionFraction(expansionFraction);
        updateStackPosition();

@@ -2395,8 +2401,8 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
        float topOverScroll = getCurrentOverScrollAmount(true);
        return mScrolledToTopOnFirstDown
                && !mExpandedInThisMotion
                && topOverScroll > mMinTopOverScrollToEscape
                && initialVelocity > 0;
                && (initialVelocity > mMinimumVelocity
                        || (topOverScroll > mMinTopOverScrollToEscape && initialVelocity > 0));
    }

    /**
@@ -4552,6 +4558,9 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
    }

    private void updateOnScrollChange() {
        if (mScrollListener != null) {
            mScrollListener.accept(mOwnScrollY);
        }
        updateForwardAndBackwardScrollability();
        requestChildrenUpdate();
    }
@@ -5162,6 +5171,13 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
        requestChildrenUpdate();
    }

    /**
     * Set a listener to when scrolling changes.
     */
    public void setOnScrollListener(Consumer<Integer> listener) {
        mScrollListener = listener;
    }

    /**
     * A listener that is notified when the empty space below the notifications is clicked on
     */
Loading