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
This commit is contained in:
Winson
2016-04-28 10:59:30 -07:00
parent 95ee8736da
commit aa0dea7a4a
3 changed files with 25 additions and 18 deletions

View File

@@ -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();
TaskStackViewTouchHandler touchHandler = mStackView.getTouchHandler();
touchHandler.onBeginDrag(deleteTaskView);
int offscreenXOffset = mStackView.getMeasuredWidth() - stackLayout.mTaskRect.left;
postAnimationTrigger.increment();
postAnimationTrigger.addLastDecrementRunnable(() -> {
touchHandler.onChildDismissed(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);
// 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;

View File

@@ -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.
*/

View File

@@ -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());
}
}