/**
* Starts the delete animation for the specified {@link TaskView}.
*/
- public void startDeleteTaskAnimation(final TaskView deleteTaskView,
+ public void startDeleteTaskAnimation(final TaskView deleteTaskView, boolean gridLayout,
final ReferenceCountedTrigger postAnimationTrigger) {
- TaskStackViewTouchHandler touchHandler = mStackView.getTouchHandler();
- touchHandler.onBeginManualDrag(deleteTaskView);
-
- postAnimationTrigger.increment();
- postAnimationTrigger.addLastDecrementRunnable(() -> {
- touchHandler.onChildDismissed(deleteTaskView);
- });
-
- 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();
- }
- });
- animator.start();
+ if (gridLayout) {
+ startTaskGridDeleteTaskAnimation(deleteTaskView, postAnimationTrigger);
+ } else {
+ startTaskStackDeleteTaskAnimation(deleteTaskView, postAnimationTrigger);
+ }
}
/**
* Starts the delete animation for all the {@link TaskView}s.
*/
- public void startDeleteAllTasksAnimation(final List<TaskView> taskViews,
- final ReferenceCountedTrigger postAnimationTrigger) {
- TaskStackLayoutAlgorithm stackLayout = mStackView.getStackAlgorithm();
-
- int offscreenXOffset = mStackView.getMeasuredWidth() - stackLayout.getTaskRect().left;
-
- int taskViewCount = taskViews.size();
- for (int i = taskViewCount - 1; i >= 0; i--) {
- TaskView tv = taskViews.get(i);
- int taskIndexFromFront = taskViewCount - i - 1;
- int startDelay = taskIndexFromFront * DOUBLE_FRAME_OFFSET_MS;
-
- // Disabling clipping with the stack while the view is animating away
- tv.setClipViewInStack(false);
-
- // Compose the new animation and transform and star the animation
- AnimationProps taskAnimation = new AnimationProps(startDelay,
- DISMISS_ALL_TASKS_DURATION, DISMISS_ALL_TRANSLATION_INTERPOLATOR,
- new AnimatorListenerAdapter() {
- @Override
- public void onAnimationEnd(Animator animation) {
- postAnimationTrigger.decrement();
-
- // Re-enable clipping with the stack (we will reuse this view)
- tv.setClipViewInStack(true);
- }
- });
- postAnimationTrigger.increment();
-
- mTmpTransform.fillIn(tv);
- mTmpTransform.rect.offset(offscreenXOffset, 0);
- mStackView.updateTaskViewToTransform(tv, mTmpTransform, taskAnimation);
+ public void startDeleteAllTasksAnimation(final List<TaskView> taskViews, boolean gridLayout,
+ final ReferenceCountedTrigger postAnimationTrigger) {
+ if (gridLayout) {
+ for (int i = 0; i < taskViews.size(); i++) {
+ startTaskGridDeleteTaskAnimation(taskViews.get(i), postAnimationTrigger);
+ }
+ } else {
+ startTaskStackDeleteAllTasksAnimation(taskViews, postAnimationTrigger);
}
}
private int calculateStaggeredAnimDuration(int i) {
return Math.max(100, 100 + ((i - 1) * 50));
}
+
+ private void startTaskGridDeleteTaskAnimation(final TaskView deleteTaskView,
+ final ReferenceCountedTrigger postAnimationTrigger) {
+ postAnimationTrigger.increment();
+ postAnimationTrigger.addLastDecrementRunnable(() -> {
+ mStackView.getTouchHandler().onChildDismissed(deleteTaskView);
+ });
+ deleteTaskView.animate().setDuration(300).scaleX(0).scaleY(0).alpha(0).setListener(
+ new AnimatorListenerAdapter() {
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ postAnimationTrigger.decrement();
+ }}).start();
+ }
+
+ private void startTaskStackDeleteTaskAnimation(final TaskView deleteTaskView,
+ final ReferenceCountedTrigger postAnimationTrigger) {
+ TaskStackViewTouchHandler touchHandler = mStackView.getTouchHandler();
+ touchHandler.onBeginManualDrag(deleteTaskView);
+
+ postAnimationTrigger.increment();
+ postAnimationTrigger.addLastDecrementRunnable(() -> {
+ touchHandler.onChildDismissed(deleteTaskView);
+ });
+
+ 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();
+ }
+ });
+ animator.start();
+ }
+
+ private void startTaskStackDeleteAllTasksAnimation(final List<TaskView> taskViews,
+ final ReferenceCountedTrigger postAnimationTrigger) {
+ TaskStackLayoutAlgorithm stackLayout = mStackView.getStackAlgorithm();
+
+ int offscreenXOffset = mStackView.getMeasuredWidth() - stackLayout.getTaskRect().left;
+
+ int taskViewCount = taskViews.size();
+ for (int i = taskViewCount - 1; i >= 0; i--) {
+ TaskView tv = taskViews.get(i);
+ int taskIndexFromFront = taskViewCount - i - 1;
+ int startDelay = taskIndexFromFront * DOUBLE_FRAME_OFFSET_MS;
+
+ // Disabling clipping with the stack while the view is animating away
+ tv.setClipViewInStack(false);
+
+ // Compose the new animation and transform and star the animation
+ AnimationProps taskAnimation = new AnimationProps(startDelay,
+ DISMISS_ALL_TASKS_DURATION, DISMISS_ALL_TRANSLATION_INTERPOLATOR,
+ new AnimatorListenerAdapter() {
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ postAnimationTrigger.decrement();
+
+ // Re-enable clipping with the stack (we will reuse this view)
+ tv.setClipViewInStack(true);
+ }
+ });
+ postAnimationTrigger.increment();
+
+ mTmpTransform.fillIn(tv);
+ mTmpTransform.rect.offset(offscreenXOffset, 0);
+ mStackView.updateTaskViewToTransform(tv, mTmpTransform, taskAnimation);
+ }
+ }
}