Adding all-tasks dismiss animation
Bug: 72222505 Test: Manual Change-Id: Ib5ecf13682cb34cde9c3bc315538c14a6b39e6c3
This commit is contained in:
parent
152464dba7
commit
e5a265b9db
|
@ -312,7 +312,7 @@ public abstract class RecentsView<T extends BaseActivity>
|
||||||
}
|
}
|
||||||
|
|
||||||
private float calculateClearAllButtonAlpha() {
|
private float calculateClearAllButtonAlpha() {
|
||||||
if (mClearAllButton.getVisibility() != View.VISIBLE) return 0;
|
if (mClearAllButton.getVisibility() != View.VISIBLE || getChildCount() == 0) return 0;
|
||||||
|
|
||||||
// Current visible coordinate of the right border of the rightmost task.
|
// Current visible coordinate of the right border of the rightmost task.
|
||||||
final int carouselCurrentRight = getChildAt(getChildCount() - 1).getRight() - getScrollX();
|
final int carouselCurrentRight = getChildAt(getChildCount() - 1).getRight() - getScrollX();
|
||||||
|
@ -725,8 +725,23 @@ public abstract class RecentsView<T extends BaseActivity>
|
||||||
mIgnoreResetTaskViews.remove(taskView);
|
mIgnoreResetTaskViews.remove(taskView);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addDismissedTaskAnimations(View taskView, AnimatorSet anim, long duration) {
|
||||||
|
addAnim(ObjectAnimator.ofFloat(taskView, ALPHA, 0), duration, ACCEL_2, anim);
|
||||||
|
addAnim(ObjectAnimator.ofFloat(taskView, TRANSLATION_Y, -taskView.getHeight()),
|
||||||
|
duration, LINEAR, anim);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeTask(Task task, PendingAnimation.OnEndListener onEndListener) {
|
||||||
|
if (task != null) {
|
||||||
|
ActivityManagerWrapper.getInstance().removeTask(task.key.id);
|
||||||
|
mActivity.getUserEventDispatcher().logTaskLaunchOrDismiss(
|
||||||
|
onEndListener.logAction, Direction.UP,
|
||||||
|
TaskUtils.getComponentKeyForTask(task.key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public PendingAnimation createTaskDismissAnimation(TaskView taskView, boolean animateTaskView,
|
public PendingAnimation createTaskDismissAnimation(TaskView taskView, boolean animateTaskView,
|
||||||
boolean removeTask, long duration) {
|
boolean shouldRemoveTask, long duration) {
|
||||||
if (FeatureFlags.IS_DOGFOOD_BUILD && mPendingAnimation != null) {
|
if (FeatureFlags.IS_DOGFOOD_BUILD && mPendingAnimation != null) {
|
||||||
throw new IllegalStateException("Another pending animation is still running");
|
throw new IllegalStateException("Another pending animation is still running");
|
||||||
}
|
}
|
||||||
|
@ -758,9 +773,7 @@ public abstract class RecentsView<T extends BaseActivity>
|
||||||
View child = getChildAt(i);
|
View child = getChildAt(i);
|
||||||
if (child == taskView) {
|
if (child == taskView) {
|
||||||
if (animateTaskView) {
|
if (animateTaskView) {
|
||||||
addAnim(ObjectAnimator.ofFloat(taskView, ALPHA, 0), duration, ACCEL_2, anim);
|
addDismissedTaskAnimations(taskView, anim, duration);
|
||||||
addAnim(ObjectAnimator.ofFloat(taskView, TRANSLATION_Y, -taskView.getHeight()),
|
|
||||||
duration, LINEAR, anim);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// If we just take newScroll - oldScroll, everything to the right of dragged task
|
// If we just take newScroll - oldScroll, everything to the right of dragged task
|
||||||
|
@ -805,14 +818,8 @@ public abstract class RecentsView<T extends BaseActivity>
|
||||||
mPendingAnimation = pendingAnimation;
|
mPendingAnimation = pendingAnimation;
|
||||||
mPendingAnimation.addEndListener((onEndListener) -> {
|
mPendingAnimation.addEndListener((onEndListener) -> {
|
||||||
if (onEndListener.isSuccess) {
|
if (onEndListener.isSuccess) {
|
||||||
if (removeTask) {
|
if (shouldRemoveTask) {
|
||||||
Task task = taskView.getTask();
|
removeTask(taskView.getTask(), onEndListener);
|
||||||
if (task != null) {
|
|
||||||
ActivityManagerWrapper.getInstance().removeTask(task.key.id);
|
|
||||||
mActivity.getUserEventDispatcher().logTaskLaunchOrDismiss(
|
|
||||||
onEndListener.logAction, Direction.UP,
|
|
||||||
TaskUtils.getComponentKeyForTask(task.key));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
int pageToSnapTo = mCurrentPage;
|
int pageToSnapTo = mCurrentPage;
|
||||||
if (draggedIndex < pageToSnapTo) {
|
if (draggedIndex < pageToSnapTo) {
|
||||||
|
@ -831,6 +838,33 @@ public abstract class RecentsView<T extends BaseActivity>
|
||||||
return pendingAnimation;
|
return pendingAnimation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PendingAnimation createAllTasksDismissAnimation(long duration) {
|
||||||
|
if (FeatureFlags.IS_DOGFOOD_BUILD && mPendingAnimation != null) {
|
||||||
|
throw new IllegalStateException("Another pending animation is still running");
|
||||||
|
}
|
||||||
|
AnimatorSet anim = new AnimatorSet();
|
||||||
|
PendingAnimation pendingAnimation = new PendingAnimation(anim);
|
||||||
|
|
||||||
|
int count = getChildCount();
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
addDismissedTaskAnimations(getChildAt(i), anim, duration);
|
||||||
|
}
|
||||||
|
|
||||||
|
mPendingAnimation = pendingAnimation;
|
||||||
|
mPendingAnimation.addEndListener((onEndListener) -> {
|
||||||
|
if (onEndListener.isSuccess) {
|
||||||
|
while (getChildCount() != 0) {
|
||||||
|
TaskView taskView = getPageAt(getChildCount() - 1);
|
||||||
|
removeTask(taskView.getTask(), onEndListener);
|
||||||
|
removeView(taskView);
|
||||||
|
}
|
||||||
|
onAllTasksRemoved();
|
||||||
|
}
|
||||||
|
mPendingAnimation = null;
|
||||||
|
});
|
||||||
|
return pendingAnimation;
|
||||||
|
}
|
||||||
|
|
||||||
private static void addAnim(ObjectAnimator anim, long duration,
|
private static void addAnim(ObjectAnimator anim, long duration,
|
||||||
TimeInterpolator interpolator, AnimatorSet set) {
|
TimeInterpolator interpolator, AnimatorSet set) {
|
||||||
anim.setDuration(duration).setInterpolator(interpolator);
|
anim.setDuration(duration).setInterpolator(interpolator);
|
||||||
|
@ -854,9 +888,7 @@ public abstract class RecentsView<T extends BaseActivity>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dismissTask(TaskView taskView, boolean animateTaskView, boolean removeTask) {
|
private void runDismissAnimation(PendingAnimation pendingAnim) {
|
||||||
PendingAnimation pendingAnim = createTaskDismissAnimation(taskView, animateTaskView,
|
|
||||||
removeTask, DISMISS_TASK_DURATION);
|
|
||||||
AnimatorPlaybackController controller = AnimatorPlaybackController.wrap(
|
AnimatorPlaybackController controller = AnimatorPlaybackController.wrap(
|
||||||
pendingAnim.anim, DISMISS_TASK_DURATION);
|
pendingAnim.anim, DISMISS_TASK_DURATION);
|
||||||
controller.dispatchOnStart();
|
controller.dispatchOnStart();
|
||||||
|
@ -865,6 +897,15 @@ public abstract class RecentsView<T extends BaseActivity>
|
||||||
controller.start();
|
controller.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void dismissTask(TaskView taskView, boolean animateTaskView, boolean removeTask) {
|
||||||
|
runDismissAnimation(createTaskDismissAnimation(taskView, animateTaskView, removeTask,
|
||||||
|
DISMISS_TASK_DURATION));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dismissAllTasks() {
|
||||||
|
runDismissAnimation(createAllTasksDismissAnimation(DISMISS_TASK_DURATION));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||||
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||||
|
@ -1171,16 +1212,6 @@ public abstract class RecentsView<T extends BaseActivity>
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dismissAllTasks() {
|
|
||||||
for (int i = 0; i < getChildCount(); ++i) {
|
|
||||||
Task task = getPageAt(i).getTask();
|
|
||||||
if (task != null) {
|
|
||||||
ActivityManagerWrapper.getInstance().removeTask(task.key.id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
onAllTasksRemoved();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int computeMaxScrollX() {
|
protected int computeMaxScrollX() {
|
||||||
if (!DEBUG_SHOW_CLEAR_ALL_BUTTON || getChildCount() == 0) {
|
if (!DEBUG_SHOW_CLEAR_ALL_BUTTON || getChildCount() == 0) {
|
||||||
|
|
Loading…
Reference in New Issue