diff options
| author | 2016-02-15 17:43:01 -0800 | |
|---|---|---|
| committer | 2016-02-15 17:43:01 -0800 | |
| commit | 23b0d3f66e8280c8638d8b0954edc0409d14de7f (patch) | |
| tree | bdc9f8feb3c8760b13785d6f8622514ec2b1cd0f | |
| parent | be8f35747c11e2be642c65b4d387458c373702c4 (diff) | |
Better focus handling after dismissing task/scrolling.
- When there is no focused task, focus the next task closest to the
stack scroll in the focus direction.
- Fixing small regression where no task would focus when alt-tabbing
because the index was out of bounds.
Change-Id: I2555c9340f40affc371f52d51d88af0eeda53b2e
3 files changed, 24 insertions, 5 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivityLaunchState.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivityLaunchState.java index 82e786140e77..aa1437b28ee8 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivityLaunchState.java +++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivityLaunchState.java @@ -75,7 +75,7 @@ public class RecentsActivityLaunchState { } // If coming from another app, focus the next task - return numTasks - 2; + return Math.max(0, numTasks - 2); } else { if (!launchState.launchedWithAltTab && debugFlags.isFastToggleRecentsEnabled()) { // If fast toggling, defer focusing until the next tap (which will automatically 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 0ee9caf5be72..1707c4f4ccd0 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java +++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java @@ -964,10 +964,26 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal newIndex = (newIndex + (forward ? -1 : 1) + taskCount) % taskCount; } } else { - // We don't have a focused task, so focus the first visible task view - TaskView tv = getFrontMostTaskView(stackTasksOnly); - if (tv != null) { - newIndex = mStack.indexOfStackTask(tv.getTask()); + // We don't have a focused task + float stackScroll = mStackScroller.getStackScroll(); + ArrayList<Task> tasks = mStack.getStackTasks(); + int taskCount = tasks.size(); + if (forward) { + // Walk backwards and focus the next task smaller than the current stack scroll + for (newIndex = taskCount - 1; newIndex >= 0; newIndex--) { + float taskP = mLayoutAlgorithm.getStackScrollForTask(tasks.get(newIndex)); + if (Float.compare(taskP, stackScroll) <= 0) { + break; + } + } + } else { + // Walk forwards and focus the next task larger than the current stack scroll + for (newIndex = 0; newIndex < taskCount; newIndex++) { + float taskP = mLayoutAlgorithm.getStackScrollForTask(tasks.get(newIndex)); + if (Float.compare(taskP, stackScroll) >= 0) { + break; + } + } } } if (newIndex != -1) { diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackViewTouchHandler.java b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackViewTouchHandler.java index 47072ba96b6b..fe504fefef26 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackViewTouchHandler.java +++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackViewTouchHandler.java @@ -280,6 +280,9 @@ class TaskStackViewTouchHandler implements SwipeHelper.Callback { mOverscrollSize); mSv.invalidate(); } + + // Reset the focused task after the user has scrolled + mSv.resetFocusedTask(mSv.getFocusedTask()); } else if (mActiveTaskView == null) { // This tap didn't start on a task. maybeHideRecentsFromBackgroundTap((int) ev.getX(), (int) ev.getY()); |