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

Commit cd4e2bb5 authored by Yining Liu's avatar Yining Liu Committed by Android (Google) Code Review
Browse files

Merge "Heads up cycling animation" into main

parents e3ce3dde 6b8f56f8
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -285,6 +285,9 @@
    the amount by the view is positioned above the screen before the animation starts. -->
    <dimen name="heads_up_appear_y_above_screen">32dp</dimen>

    <!-- padding between the old and new heads up notifications for the hun cycling animation -->
    <dimen name="heads_up_cycling_padding">8dp</dimen>

    <!-- padding between the heads up and the statusbar -->
    <dimen name="heads_up_status_bar_padding">8dp</dimen>

+82 −20
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@
package com.android.systemui.statusbar.notification.row;

import static com.android.systemui.Flags.notificationBackgroundTintOptimization;
import static com.android.systemui.statusbar.notification.row.ExpandableView.ClipSide.BOTTOM;
import static com.android.systemui.statusbar.notification.row.ExpandableView.ClipSide.TOP;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
@@ -43,6 +45,7 @@ import com.android.systemui.statusbar.NotificationShelf;
import com.android.systemui.statusbar.notification.FakeShadowView;
import com.android.systemui.statusbar.notification.NotificationUtils;
import com.android.systemui.statusbar.notification.SourceType;
import com.android.systemui.statusbar.notification.shared.NotificationHeadsUpCycling;
import com.android.systemui.statusbar.notification.shared.NotificationIconContainerRefactor;
import com.android.systemui.statusbar.notification.shared.NotificationsImprovedHunAnimation;
import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout;
@@ -354,12 +357,13 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
    @Override
    public long performRemoveAnimation(long duration, long delay, float translationDirection,
            boolean isHeadsUpAnimation, Runnable onStartedRunnable, Runnable onFinishedRunnable,
            AnimatorListenerAdapter animationListener) {
            AnimatorListenerAdapter animationListener, ClipSide clipSide) {
        enableAppearDrawing(true);
        mIsHeadsUpAnimation = isHeadsUpAnimation;
        if (mDrawingAppearAnimation) {
            startAppearAnimation(false /* isAppearing */, translationDirection,
                    delay, duration, onStartedRunnable, onFinishedRunnable, animationListener);
                    delay, duration, onStartedRunnable, onFinishedRunnable, animationListener,
                    clipSide);
        } else {
            if (onStartedRunnable != null) {
                onStartedRunnable.run();
@@ -378,13 +382,13 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
        mIsHeadsUpAnimation = isHeadsUpAppear;
        if (mDrawingAppearAnimation) {
            startAppearAnimation(true /* isAppearing */, isHeadsUpAppear ? 0.0f : -1.0f, delay,
                    duration, null, null, null);
                    duration, null, null, null, ClipSide.BOTTOM);
        }
    }

    private void startAppearAnimation(boolean isAppearing, float translationDirection, long delay,
            long duration, final Runnable onStartedRunnable, final Runnable onFinishedRunnable,
            AnimatorListenerAdapter animationListener) {
            AnimatorListenerAdapter animationListener, ClipSide clipSide) {
        mAnimationTranslationY = translationDirection * getActualHeight();
        cancelAppearAnimation();
        if (mAppearAnimationFraction == -1.0f) {
@@ -406,9 +410,16 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
            mCurrentAppearInterpolator = Interpolators.FAST_OUT_SLOW_IN_REVERSE;
            targetValue = 0.0f;
        }

        if (NotificationHeadsUpCycling.isEnabled()) {
            // TODO(b/316404716): add avalanche filtering
            mCurrentAppearInterpolator = Interpolators.LINEAR;
        }

        mAppearAnimator = ValueAnimator.ofFloat(mAppearAnimationFraction,
                targetValue);
        if (NotificationsImprovedHunAnimation.isEnabled()) {
        if (NotificationsImprovedHunAnimation.isEnabled()
                || NotificationHeadsUpCycling.isEnabled()) {
            mAppearAnimator.setInterpolator(mCurrentAppearInterpolator);
        } else {
            mAppearAnimator.setInterpolator(Interpolators.LINEAR);
@@ -418,7 +429,12 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
        mAppearAnimator.addUpdateListener(animation -> {
            mAppearAnimationFraction = (float) animation.getAnimatedValue();
            updateAppearAnimationAlpha();
            if (NotificationHeadsUpCycling.isEnabled()) {
                // For cycling out, we want the HUN to be clipped from the top.
                updateAppearRect(clipSide);
            } else {
                updateAppearRect();
            }
            invalidate();
        });
        if (animationListener != null) {
@@ -426,7 +442,11 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
        }
        // we need to apply the initial state already to avoid drawn frames in the wrong state
        updateAppearAnimationAlpha();
        if (NotificationHeadsUpCycling.isEnabled()) {
            updateAppearRect(clipSide);
        } else {
            updateAppearRect();
        }
        mAppearAnimator.addListener(new AnimatorListenerAdapter() {
            private boolean mRunWithoutInterruptions;

@@ -508,14 +528,18 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
        enableAppearDrawing(false);
    }

    private void updateAppearRect() {
    /**
     * Update the View's Rect clipping to fit the appear animation
     * @param clipSide Which side if view we want to clip from
     */
    private void updateAppearRect(ClipSide clipSide) {
        float interpolatedFraction =
                NotificationsImprovedHunAnimation.isEnabled() ? mAppearAnimationFraction
                NotificationsImprovedHunAnimation.isEnabled()
                        || NotificationHeadsUpCycling.isEnabled() ? mAppearAnimationFraction
                        : mCurrentAppearInterpolator.getInterpolation(mAppearAnimationFraction);
        mAppearAnimationTranslation = (1.0f - interpolatedFraction) * mAnimationTranslationY;
        final int actualHeight = getActualHeight();
        float bottom = actualHeight * interpolatedFraction;

        final int fullHeight = getActualHeight();
        float height = fullHeight * interpolatedFraction;
        if (mTargetPoint != null) {
            int width = getWidth();
            float fraction = 1 - mAppearAnimationFraction;
@@ -524,13 +548,26 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
                    mAnimationTranslationY
                            + (mAnimationTranslationY - mTargetPoint.y) * fraction,
                    width - (width - mTargetPoint.x) * fraction,
                    actualHeight - (actualHeight - mTargetPoint.y) * fraction);
                    fullHeight - (fullHeight - mTargetPoint.y) * fraction);
        } else {
            if (clipSide == TOP) {
                setOutlineRect(
                        0,
                        /* top= */ fullHeight - height,
                        getWidth(),
                        /* bottom= */ fullHeight
                );
            } else if (clipSide == BOTTOM) {
                setOutlineRect(0, mAppearAnimationTranslation, getWidth(),
                    bottom + mAppearAnimationTranslation);
                        height + mAppearAnimationTranslation);
            }
        }
    }

    private void updateAppearRect() {
        updateAppearRect(ClipSide.BOTTOM);
    }

    private float getInterpolatedAppearAnimationFraction() {

        if (mAppearAnimationFraction >= 0) {
@@ -540,11 +577,36 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
    }

    private void updateAppearAnimationAlpha() {
        float contentAlphaProgress = MathUtils.constrain(mAppearAnimationFraction,
                ALPHA_APPEAR_START_FRACTION, ALPHA_APPEAR_END_FRACTION);
        float range = ALPHA_APPEAR_END_FRACTION - ALPHA_APPEAR_START_FRACTION;
        float alpha = (contentAlphaProgress - ALPHA_APPEAR_START_FRACTION) / range;
        setContentAlpha(Interpolators.ALPHA_IN.getInterpolation(alpha));
        updateAppearAnimationContentAlpha(
                mAppearAnimationFraction,
                ALPHA_APPEAR_START_FRACTION,
                ALPHA_APPEAR_END_FRACTION,
                Interpolators.ALPHA_IN
        );
    }

    /**
     * Update the alpha value of the content view during the appear animation. We suppose that the
     * content alpha changes from 0 to 1 during some part of the appear animation.
     * @param appearFraction the current appearFraction, should be in the range of [0, 1], where
     *                       1 represents fully appeared
     * @param startFraction the appear fraction when the content view should be
     *      *                    fully transparent
     * @param endFraction the appear fraction when the content view should be
     *                    fully in-transparent, should be greater or equals to startFraction
     * @param interpolator the interpolator to update the alpha
     */
    private void updateAppearAnimationContentAlpha(
            float appearFraction,
            float startFraction,
            float endFraction,
            Interpolator interpolator
    ) {
        float contentAlphaProgress = MathUtils.constrain(appearFraction, startFraction,
                endFraction);
        float range = endFraction - startFraction;
        float alpha = (contentAlphaProgress - startFraction) / range;
        setContentAlpha(interpolator.getInterpolation(alpha));
    }

    private void setContentAlpha(float contentAlpha) {
+4 −3
Original line number Diff line number Diff line
@@ -3076,7 +3076,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
            boolean isHeadsUpAnimation,
            Runnable onStartedRunnable,
            Runnable onFinishedRunnable,
            AnimatorListenerAdapter animationListener) {
            AnimatorListenerAdapter animationListener, ClipSide clipSide) {
        if (mMenuRow != null && mMenuRow.isMenuVisible()) {
            Animator anim = getTranslateViewAnimator(0f, null /* listener */);
            if (anim != null) {
@@ -3092,7 +3092,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
                    public void onAnimationEnd(Animator animation) {
                        ExpandableNotificationRow.super.performRemoveAnimation(
                                duration, delay, translationDirection, isHeadsUpAnimation,
                                null, onFinishedRunnable, animationListener);
                                null, onFinishedRunnable, animationListener, ClipSide.BOTTOM);
                    }
                });
                anim.start();
@@ -3100,7 +3100,8 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
            }
        }
        return super.performRemoveAnimation(duration, delay, translationDirection,
                isHeadsUpAnimation, onStartedRunnable, onFinishedRunnable, animationListener);
                isHeadsUpAnimation, onStartedRunnable, onFinishedRunnable, animationListener,
                clipSide);
    }

    @Override
+12 −7
Original line number Diff line number Diff line
@@ -362,6 +362,7 @@ public abstract class ExpandableView extends FrameLayout implements Dumpable, Ro

    /**
     * Perform a remove animation on this view.
     *
     * @param duration             The duration of the remove animation.
     * @param delay                The delay of the animation
     * @param translationDirection The direction value from [-1 ... 1] indicating in which the
@@ -372,7 +373,6 @@ public abstract class ExpandableView extends FrameLayout implements Dumpable, Ro
     * @param isHeadsUpAnimation   Is this a headsUp animation.
     * @param onFinishedRunnable   A runnable which should be run when the animation is finished.
     * @param animationListener    An animation listener to add to the animation.
     *
     * @return The additional delay, in milliseconds, that this view needs to add before the
     * animation starts.
     */
@@ -380,7 +380,12 @@ public abstract class ExpandableView extends FrameLayout implements Dumpable, Ro
            long delay, float translationDirection, boolean isHeadsUpAnimation,
            Runnable onStartedRunnable,
            Runnable onFinishedRunnable,
            AnimatorListenerAdapter animationListener);
            AnimatorListenerAdapter animationListener, ClipSide clipSide);

    public enum ClipSide {
        TOP,
        BOTTOM
    }

    public void performAddAnimation(long delay, long duration, boolean isHeadsUpAppear) {
        performAddAnimation(delay, duration, isHeadsUpAppear, null);
+1 −1
Original line number Diff line number Diff line
@@ -252,7 +252,7 @@ public abstract class StackScrollerDecorView extends ExpandableView {
            float translationDirection, boolean isHeadsUpAnimation,
            Runnable onStartedRunnable,
            Runnable onFinishedRunnable,
            AnimatorListenerAdapter animationListener) {
            AnimatorListenerAdapter animationListener, ClipSide clipSide) {
        // TODO: Use duration
        if (onStartedRunnable != null) {
            onStartedRunnable.run();
Loading