Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 23b0d3f6 authored by Winson's avatar Winson
Browse files

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
parent be8f3574
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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
+20 −4
Original line number Diff line number Diff line
@@ -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) {
+3 −0
Original line number Diff line number Diff line
@@ -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());