From 78cc96af8ca9ef4f2edccbb1b5d494b3a357782d Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Tue, 12 Aug 2014 13:56:03 -0700 Subject: [PATCH] Anchoring the front most task to make the dismiss animation more stable. (Bug 16939699) Change-Id: I49aa14bbc7fdb2fb0884a8255af385dbbbe656f8 --- .../systemui/recents/views/TaskStackView.java | 22 ++++++++++++++++++- .../views/TaskStackViewLayoutAlgorithm.java | 2 +- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java index 21b62e9c32970..aee558f88f65f 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java +++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java @@ -395,7 +395,7 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal // Scroll the view into position (just center it in the curve) if (scrollToNewPosition) { - float newScroll = mLayoutAlgorithm.getStackScrollForTaskIndex(t) - 0.5f; + float newScroll = mLayoutAlgorithm.getStackScrollForTask(t) - 0.5f; newScroll = mStackScroller.getBoundedStackScroll(newScroll); mStackScroller.animateScroll(mStackScroller.getStackScroll(), newScroll, postScrollRunnable); } else { @@ -681,8 +681,28 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal // Notify the callback that we've removed the task and it can clean up after it mCb.onTaskViewDismissed(removedTask); + // Get the stack scroll of the task to anchor to (since we are removing something, the front + // most task will be our anchor task) + Task anchorTask = null; + float prevAnchorTaskScroll = 0; + boolean pullStackForward = stack.getTaskCount() > 0; + if (pullStackForward) { + anchorTask = mStack.getFrontMostTask(); + prevAnchorTaskScroll = mLayoutAlgorithm.getStackScrollForTask(anchorTask); + } + // Update the min/max scroll and animate other task views into their new positions updateMinMaxScroll(true, mConfig.launchedWithAltTab, mConfig.launchedFromHome); + + // Offset the stack by as much as the anchor task would otherwise move back + if (pullStackForward) { + float anchorTaskScroll = mLayoutAlgorithm.getStackScrollForTask(anchorTask); + mStackScroller.setStackScroll(mStackScroller.getStackScroll() + (anchorTaskScroll + - prevAnchorTaskScroll)); + mStackScroller.boundScroll(); + } + + // Animate all the tasks into place requestSynchronizeStackViewsWithModel(200); // Update the new front most task diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackViewLayoutAlgorithm.java b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackViewLayoutAlgorithm.java index 495d00b1fa313..667faa7dfbc9d 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackViewLayoutAlgorithm.java +++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackViewLayoutAlgorithm.java @@ -202,7 +202,7 @@ public class TaskStackViewLayoutAlgorithm { /** * Returns the scroll to such task top = 1f; */ - float getStackScrollForTaskIndex(Task t) { + float getStackScrollForTask(Task t) { return mTaskProgressMap.get(t.key); }