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

Commit 0f145252 authored by Jay Aliomer's avatar Jay Aliomer
Browse files

Animation reveal animation for HUN and Shelf

Test: visual
Fixes: b/187175147
Fixes: b/186892139

Change-Id: Ieea6531aecdaae81f681f1c46c6f8f6936655ee2
parent 79ce03a8
Loading
Loading
Loading
Loading
+2 −5
Original line number Diff line number Diff line
@@ -20,14 +20,11 @@ import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Rect;
import android.os.SystemProperties;
import android.util.AttributeSet;
import android.util.MathUtils;
import android.view.DisplayCutout;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.WindowInsets;
import android.view.accessibility.AccessibilityNodeInfo;

import com.android.internal.annotations.VisibleForTesting;
+39 −61
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.systemui.statusbar.notification.row;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Canvas;
@@ -83,7 +82,16 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
     * or {@link #setOverrideTintColor(int, float)}.
     */
    protected static final int NO_COLOR = 0;

    /**
     * The content of the view should start showing at animation progress value of
     * #ALPHA_APPEAR_START_FRACTION.
     */
    private static final float ALPHA_APPEAR_START_FRACTION = .4f;
    /**
     * The content should show fully with progress at #ALPHA_APPEAR_END_FRACTION
     * The start of the animation is at #ALPHA_APPEAR_START_FRACTION
     */
    private static final float ALPHA_APPEAR_END_FRACTION = 1;
    private static final Interpolator ACTIVATE_INVERSE_INTERPOLATOR
            = new PathInterpolator(0.6f, 0, 0.5f, 1);
    private static final Interpolator ACTIVATE_INVERSE_ALPHA_INTERPOLATOR
@@ -105,10 +113,8 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
    private final Interpolator mSlowOutFastInInterpolator;
    private final Interpolator mSlowOutLinearInInterpolator;
    private Interpolator mCurrentAppearInterpolator;
    private Interpolator mCurrentAlphaInterpolator;

    NotificationBackgroundView mBackgroundNormal;
    private ObjectAnimator mBackgroundAnimator;
    private RectF mAppearAnimationRect = new RectF();
    private float mAnimationTranslationY;
    private boolean mDrawingAppearAnimation;
@@ -474,8 +480,8 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
    private void startAppearAnimation(boolean isAppearing, float translationDirection, long delay,
            long duration, final Runnable onFinishedRunnable,
            AnimatorListenerAdapter animationListener) {
        cancelAppearAnimation();
        mAnimationTranslationY = translationDirection * getActualHeight();
        cancelAppearAnimation();
        if (mAppearAnimationFraction == -1.0f) {
            // not initialized yet, we start anew
            if (isAppearing) {
@@ -491,15 +497,9 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
        float targetValue;
        if (isAppearing) {
            mCurrentAppearInterpolator = mSlowOutFastInInterpolator;
            mCurrentAlphaInterpolator = Interpolators.LINEAR_OUT_SLOW_IN;
            targetValue = 1.0f;
            if (!mIsHeadsUpAnimation && isChildInGroup()) {
                // slower fade in of children to avoid visibly overlapping with other children
                mCurrentAlphaInterpolator = Interpolators.SLOW_OUT_LINEAR_IN;
            }
        } else {
            mCurrentAppearInterpolator = Interpolators.FAST_OUT_SLOW_IN;
            mCurrentAlphaInterpolator = mSlowOutLinearInInterpolator;
            targetValue = 0.0f;
        }
        mAppearAnimator = ValueAnimator.ofFloat(mAppearAnimationFraction,
@@ -586,61 +586,23 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
        float translationFraction = mCurrentAppearInterpolator.getInterpolation(inverseFraction);
        float translateYTotalAmount = translationFraction * mAnimationTranslationY;
        mAppearAnimationTranslation = translateYTotalAmount;
        final int actualHeight = getActualHeight();
        float bottom = actualHeight * mAppearAnimationFraction;

        // handle width animation
        float widthFraction = (inverseFraction - (1.0f - HORIZONTAL_ANIMATION_START))
                / (HORIZONTAL_ANIMATION_START - HORIZONTAL_ANIMATION_END);
        widthFraction = Math.min(1.0f, Math.max(0.0f, widthFraction));
        widthFraction = mCurrentAppearInterpolator.getInterpolation(widthFraction);
        float startWidthFraction = HORIZONTAL_COLLAPSED_REST_PARTIAL;
        if (mIsHeadsUpAnimation && !mIsAppearing) {
            startWidthFraction = 0;
        }
        if (mIsAppearing && !mIsHeadsUpAnimation && isChildInGroup()) {
            // Children in a group (when not heads up) should simply fade in.
            startWidthFraction = 1;
        }
        float width = MathUtils.lerp(startWidthFraction, 1.0f, 1.0f - widthFraction)
                        * getWidth();
        float left;
        float right;
        if (mIsHeadsUpAnimation) {
            left = MathUtils.lerp(mHeadsUpLocation, 0, 1.0f - widthFraction);
            right = left + width;
        } else {
            left = getWidth() * 0.5f - width / 2.0f;
            right = getWidth() - left;
        setOutlineRect(0, mAppearAnimationTranslation,
                getWidth(), bottom + mAppearAnimationTranslation);
    }

        // handle top animation
        float heightFraction = (inverseFraction - (1.0f - VERTICAL_ANIMATION_START)) /
                VERTICAL_ANIMATION_START;
        heightFraction = Math.max(0.0f, heightFraction);
        heightFraction = mCurrentAppearInterpolator.getInterpolation(heightFraction);

        float top;
        float bottom;
        final int actualHeight = getActualHeight();
        if (mAnimationTranslationY > 0.0f) {
            bottom = actualHeight - heightFraction * mAnimationTranslationY * 0.1f
                    - translateYTotalAmount;
            top = bottom * heightFraction;
        } else {
            top = heightFraction * (actualHeight + mAnimationTranslationY) * 0.1f -
                    translateYTotalAmount;
            bottom = actualHeight * (1 - heightFraction) + top * heightFraction;
        }
        mAppearAnimationRect.set(left, top, right, bottom);
        setOutlineRect(left, top + mAppearAnimationTranslation, right,
                bottom + mAppearAnimationTranslation);
    private float getAppearAnimationFraction() {
        return mAppearAnimationFraction >= 0 ? mAppearAnimationFraction : 1;
    }

    private void updateAppearAnimationAlpha() {
        float contentAlphaProgress = mAppearAnimationFraction;
        contentAlphaProgress = contentAlphaProgress / (1.0f - ALPHA_ANIMATION_END);
        contentAlphaProgress = Math.min(1.0f, contentAlphaProgress);
        contentAlphaProgress = mCurrentAlphaInterpolator.getInterpolation(contentAlphaProgress);
        setContentAlpha(contentAlphaProgress);
        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));
    }

    private void setContentAlpha(float contentAlpha) {
@@ -663,6 +625,22 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
                getCurrentBackgroundRadiusBottom());
    }

    @Override
    public float getCurrentBackgroundRadiusTop() {
        float fraction = getAppearAnimationFraction();
        return isHeadsUpAnimatingAway() || isHeadsUp()
                ? mOutlineRadius * fraction
                : super.getCurrentBackgroundRadiusTop();
    }

    @Override
    public float getCurrentBackgroundRadiusBottom() {
        float fraction = getAppearAnimationFraction();
        return isHeadsUpAnimatingAway() || isHeadsUp()
                ? mOutlineRadius * fraction
                : super.getCurrentBackgroundRadiusBottom();
    }

    private void applyBackgroundRoundness(float topRadius, float bottomRadius) {
        mBackgroundNormal.setRadius(topRadius, bottomRadius);
    }
+0 −17
Original line number Diff line number Diff line
@@ -1998,23 +1998,6 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        return false;
    }

    @Override
    public float getCurrentTopRoundness() {
        if (mExpandAnimationRunning) {
            return mTopRoundnessDuringExpandAnimation;
        }

        return super.getCurrentTopRoundness();
    }

    @Override
    public float getCurrentBottomRoundness() {
        if (mExpandAnimationRunning) {
            return mBottomRoundnessDuringExpandAnimation;
        }

        return super.getCurrentBottomRoundness();
    }

    public void applyExpandAnimationParams(ExpandAnimationParameters params) {
        if (params == null) {
+0 −10
Original line number Diff line number Diff line
@@ -117,16 +117,6 @@ public class AnimationFilter {
                    NotificationStackScrollLayout.AnimationEvent.ANIMATION_TYPE_GO_TO_FULL_SHADE) {
                hasGoToFullShadeEvent = true;
            }
            if (ev.animationType == NotificationStackScrollLayout.AnimationEvent
                    .ANIMATION_TYPE_HEADS_UP_DISAPPEAR) {
                customDelay = StackStateAnimator.ANIMATION_DELAY_HEADS_UP;
            } else if (ev.animationType == NotificationStackScrollLayout.AnimationEvent
                    .ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK) {
                // We need both timeouts when clicking, one to delay it and one for the animation
                // to look nice
                customDelay = StackStateAnimator.ANIMATION_DELAY_HEADS_UP_CLICKED
                        + StackStateAnimator.ANIMATION_DELAY_HEADS_UP;
            }
        }
    }

+2 −1
Original line number Diff line number Diff line
@@ -556,7 +556,7 @@ public class StackScrollAlgorithm {
                continue;
            }
            ExpandableNotificationRow row = (ExpandableNotificationRow) child;
            if (!row.isHeadsUp()) {
            if (!(row.isHeadsUp() || row.isHeadsUpAnimatingAway())) {
                continue;
            }
            ExpandableViewState childState = row.getViewState();
@@ -603,6 +603,7 @@ public class StackScrollAlgorithm {
                }
            }
            if (row.isHeadsUpAnimatingAway()) {
                childState.yTranslation = Math.max(childState.yTranslation, mHeadsUpInset);
                childState.hidden = false;
            }
        }
Loading