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

Commit 39fe64c1 authored by András Kurucz's avatar András Kurucz
Browse files

Add translateY animation to the removed HUNs animating away

When a HUN is being removed, the StackScrollAlgorithm doesn't find it to
update its translateY value, because it is already removed from its
parent. This CL forces to set the desired translateY value, and makes
sure to start animate to the new ViewState.

Fixes: 323400019
Test: post a HUN, click the action button to remove it, observe the
disapper animation
Flag: ACONFIG notifications_improved_hun_animation DEVELOPMENT

Change-Id: Ie6463dc878bc91c7a8c6c92e32ded92a9f4ae66c
parent 62c2e3f7
Loading
Loading
Loading
Loading
+27 −14
Original line number Diff line number Diff line
@@ -460,15 +460,8 @@ public class StackStateAnimator {
                mHeadsUpAppearChildren.add(changingView);

                mTmpState.copyFrom(changingView.getViewState());
                if (event.headsUpFromBottom) {
                    // start from the bottom of the screen
                    mTmpState.setYTranslation(
                            mHeadsUpAppearHeightBottom + mHeadsUpAppearStartAboveScreen);
                } else {
                    // start from the top of the screen
                    mTmpState.setYTranslation(
                            -mStackTopMargin - mHeadsUpAppearStartAboveScreen);
                }
                // translate the HUN in from the top, or the bottom of the screen
                mTmpState.setYTranslation(getHeadsUpYTranslationStart(event.headsUpFromBottom));
                // set the height and the initial position
                mTmpState.applyToView(changingView);
                mAnimationProperties.setCustomInterpolator(View.TRANSLATION_Y,
@@ -512,12 +505,20 @@ public class StackStateAnimator {
                    || event.animationType == ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK) {
                mHeadsUpDisappearChildren.add(changingView);
                Runnable endRunnable = null;
                mTmpState.copyFrom(changingView.getViewState());
                if (changingView.getParent() == null) {
                    // This notification was actually removed, so we need to add it
                    // transiently
                    mHostLayout.addTransientView(changingView, 0);
                    changingView.setTransientContainer(mHostLayout);
                    mTmpState.initFrom(changingView);
                    if (NotificationsImprovedHunAnimation.isEnabled()) {
                        // StackScrollAlgorithm cannot find this view because it has been removed
                        // from the NSSL. To correctly translate the view to the top or bottom of
                        // the screen (where it animated from), we need to update its translation.
                        mTmpState.setYTranslation(
                                getHeadsUpYTranslationStart(event.headsUpFromBottom)
                        );
                    }
                    endRunnable = changingView::removeFromTransientContainer;
                }

@@ -565,16 +566,19 @@ public class StackStateAnimator {
                            changingView.setInRemovalAnimation(true);
                        };
                    }
                    if (NotificationsImprovedHunAnimation.isEnabled()) {
                        mAnimationProperties.setCustomInterpolator(View.TRANSLATION_Y,
                                Interpolators.FAST_OUT_SLOW_IN_REVERSE);
                    }
                    long removeAnimationDelay = changingView.performRemoveAnimation(
                            ANIMATION_DURATION_HEADS_UP_DISAPPEAR,
                            0, 0.0f, true /* isHeadsUpAppear */,
                            startAnimation, postAnimation,
                            getGlobalAnimationFinishedListener());
                    mAnimationProperties.delay += removeAnimationDelay;
                    if (NotificationsImprovedHunAnimation.isEnabled()) {
                        mAnimationProperties.duration = ANIMATION_DURATION_HEADS_UP_DISAPPEAR;
                        mAnimationProperties.setCustomInterpolator(View.TRANSLATION_Y,
                                Interpolators.FAST_OUT_SLOW_IN_REVERSE);
                        mAnimationProperties.getAnimationFilter().animateY = true;
                        mTmpState.animateTo(changingView, mAnimationProperties);
                    }
                } else if (endRunnable != null) {
                    endRunnable.run();
                }
@@ -585,6 +589,15 @@ public class StackStateAnimator {
        return needsCustomAnimation;
    }

    private float getHeadsUpYTranslationStart(boolean headsUpFromBottom) {
        if (headsUpFromBottom) {
            // start from the bottom of the screen
            return mHeadsUpAppearHeightBottom + mHeadsUpAppearStartAboveScreen;
        }
        // start from the top of the screen
        return -mStackTopMargin - mHeadsUpAppearStartAboveScreen;
    }

    public void animateOverScrollToAmount(float targetAmount, final boolean onTop,
            final boolean isRubberbanded) {
        final float startOverScrollAmount = mHostLayout.getCurrentOverScrollAmount(onTop);
+2 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.statusbar.notification.stack

import android.platform.test.annotations.EnableFlags
import android.testing.AndroidTestingRunner
import android.testing.TestableLooper.RunWithLooper
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.statusbar.notification.row.ExpandableView
@@ -41,6 +42,7 @@ private const val VIEW_HEIGHT = 100

@SmallTest
@RunWith(AndroidTestingRunner::class)
@RunWithLooper
class StackStateAnimatorTest : SysuiTestCase() {

    private lateinit var stackStateAnimator: StackStateAnimator