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

Commit aa0dea7a authored by Winson's avatar Winson
Browse files

Pipe the dismiss button logic through the touch handler.

- This ensures that we perform the same dismiss animation when 
  dismissing via the button or via swipe.

Bug: 28443410
Change-Id: I309c38253e9c2dc78a5882dc663eec84a11619dd
parent 95ee8736
Loading
Loading
Loading
Loading
+17 −17
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.recents.views;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.TimeInterpolator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
@@ -384,29 +385,29 @@ public class TaskStackAnimationHelper {
     */
    public void startDeleteTaskAnimation(final TaskView deleteTaskView,
            final ReferenceCountedTrigger postAnimationTrigger) {
        Resources res = mStackView.getResources();
        TaskStackLayoutAlgorithm stackLayout = mStackView.getStackAlgorithm();

        int offscreenXOffset = mStackView.getMeasuredWidth() - stackLayout.mTaskRect.left;
        TaskStackViewTouchHandler touchHandler = mStackView.getTouchHandler();
        touchHandler.onBeginDrag(deleteTaskView);

        // Disabling clipping with the stack while the view is animating away, this will get
        // restored when the task is next picked up from the view pool
        deleteTaskView.setClipViewInStack(false);
        postAnimationTrigger.increment();
        postAnimationTrigger.addLastDecrementRunnable(() -> {
            touchHandler.onChildDismissed(deleteTaskView);
        });

        // Compose the new animation and transform and star the animation
        AnimationProps taskAnimation = new AnimationProps(DISMISS_TASK_DURATION,
                Interpolators.ALPHA_OUT, new AnimatorListenerAdapter() {
        final float dismissSize = touchHandler.getScaledDismissSize();
        ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f);
        animator.setDuration(400);
        animator.addUpdateListener((animation) -> {
            float progress = (Float) animation.getAnimatedValue();
            deleteTaskView.setTranslationX(progress * dismissSize);
            touchHandler.updateSwipeProgress(deleteTaskView, true, progress);
        });
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                postAnimationTrigger.decrement();
            }
        });
        postAnimationTrigger.increment();

        mTmpTransform.fillIn(deleteTaskView);
        mTmpTransform.alpha = 0f;
        mTmpTransform.rect.offset(offscreenXOffset, 0);
        mStackView.updateTaskViewToTransform(deleteTaskView, mTmpTransform, taskAnimation);
        animator.start();
    }

    /**
@@ -419,7 +420,6 @@ public class TaskStackAnimationHelper {
        int offscreenXOffset = mStackView.getMeasuredWidth() - stackLayout.mTaskRect.left;

        int taskViewCount = taskViews.size();

        for (int i = taskViewCount - 1; i >= 0; i--) {
            TaskView tv = taskViews.get(i);
            int taskIndexFromFront = taskViewCount - i - 1;
+7 −0
Original line number Diff line number Diff line
@@ -419,6 +419,13 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
        return mLayoutAlgorithm;
    }

    /**
     * Returns the touch handler for this task stack.
     */
    public TaskStackViewTouchHandler getTouchHandler() {
        return mTouchHandler;
    }

    /**
     * Adds a task to the ignored set.
     */
+1 −1
Original line number Diff line number Diff line
@@ -631,7 +631,7 @@ class TaskStackViewTouchHandler implements SwipeHelper.Callback {
    /**
     * Returns the scaled size used to calculate the dismiss fraction.
     */
    private float getScaledDismissSize() {
    public float getScaledDismissSize() {
        return 1.5f * Math.max(mSv.getWidth(), mSv.getHeight());
    }
}