From 754e24c52119877a9eb4a90c70974566d8d4f5cb Mon Sep 17 00:00:00 2001 From: minch Date: Mon, 10 Feb 2025 17:27:55 +0000 Subject: [PATCH] Indices correction inside RecentsView Audit all the functions inside RecentsView with the TaskView index as a parameter. Make sure the AddDesktopButton is considered while setting the value of these parameters. Flag: EXEMPT refactor Bug: 379942019 Test: m alt+tab to the "# more apps" button insde KQS view, the first hidden TaskView inside the RecentsView will be focused. Change-Id: I92cd3e38700e83e72d362dc47d3adae538695b60 --- .../quickstep/OverviewCommandHelper.kt | 20 +++++------ .../android/quickstep/views/RecentsView.java | 34 +++++++------------ .../quickstep/views/RecentsViewUtils.kt | 4 +-- 3 files changed, 24 insertions(+), 34 deletions(-) diff --git a/quickstep/src/com/android/quickstep/OverviewCommandHelper.kt b/quickstep/src/com/android/quickstep/OverviewCommandHelper.kt index 42aa86e9e0..afdb403897 100644 --- a/quickstep/src/com/android/quickstep/OverviewCommandHelper.kt +++ b/quickstep/src/com/android/quickstep/OverviewCommandHelper.kt @@ -293,10 +293,6 @@ constructor( val recentsView: RecentsView<*, *>? = recentsViewContainer?.getOverviewPanel() val deviceProfile = recentsViewContainer?.getDeviceProfile() val uiController = containerInterface.getTaskbarController() - val allowQuickSwitch = - uiController != null && - deviceProfile != null && - (deviceProfile.isTablet || deviceProfile.isTwoPanels) val focusedDisplayId = focusState.focusedDisplayId val focusedDisplayUIController: TaskbarUIController? = @@ -322,26 +318,26 @@ constructor( when (command.type) { HIDE -> { - if (!allowQuickSwitch) return true + if (uiController == null || deviceProfile?.isTablet == false) return true keyboardTaskFocusIndex = if ( enableAltTabKqsOnConnectedDisplays() && focusedDisplayUIController != null ) { focusedDisplayUIController.launchFocusedTask() } else { - uiController!!.launchFocusedTask() + uiController.launchFocusedTask() } if (keyboardTaskFocusIndex == -1) return true } KEYBOARD_INPUT -> - if (allowQuickSwitch) { + if (uiController != null && deviceProfile?.isTablet == true) { if ( enableAltTabKqsOnConnectedDisplays() && focusedDisplayUIController != null ) { focusedDisplayUIController.openQuickSwitchView() } else { - uiController!!.openQuickSwitchView() + uiController.openQuickSwitchView() } return true } else { @@ -365,7 +361,11 @@ constructor( TOGGLE -> {} } - recentsView?.setKeyboardTaskFocusIndex(keyboardTaskFocusIndex) + recentsView?.setKeyboardTaskFocusIndex( + recentsView.indexOfChild(recentsView.taskViews.elementAtOrNull(keyboardTaskFocusIndex)) + ?: -1 + ) + // Handle recents view focus when launching from home val animatorListener: Animator.AnimatorListener = object : AnimatorListenerAdapter() { @@ -526,7 +526,7 @@ constructor( // Stops requesting focused after first view gets focused. recentsView.getTaskViewAt(keyboardTaskFocusIndex).requestFocus() || recentsView.nextTaskView.requestFocus() || - recentsView.getFirstTaskView().requestFocus() || + recentsView.firstTaskView.requestFocus() || recentsView.requestFocus() } diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java index 58300d27cc..e6e8fa4d68 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/src/com/android/quickstep/views/RecentsView.java @@ -2013,7 +2013,7 @@ public abstract class RecentsView< } // If the list changed, maybe the focused task doesn't exist anymore. if (newFocusedTaskView == null) { - newFocusedTaskView = mUtils.getExpectedFocusedTask(); + newFocusedTaskView = mUtils.getFirstNonDesktopTaskView(); } } setFocusedTaskViewId( @@ -2119,15 +2119,6 @@ public abstract class RecentsView< return mTaskViewCount; } - /** - * Transverse RecentsView children to calculate the amount of DesktopTaskViews. - * - * @return Number of children that are instances of DesktopTaskView - */ - private int getDesktopTaskViewCount() { - return mUtils.getDesktopTaskViewCount(); - } - /** Counts {@link TaskView}s that are not {@link DesktopTaskView} instances. */ public int getNonDesktopTaskViewCount() { return mUtils.getNonDesktopTaskViewCount(); @@ -3067,7 +3058,7 @@ public abstract class RecentsView< focusedTaskViewId = INVALID_TASK_ID; } else if (enableLargeDesktopWindowingTile() && getRunningTaskView() instanceof DesktopTaskView) { - TaskView focusedTaskView = getTaskViewAt(getDesktopTaskViewCount()); + TaskView focusedTaskView = mUtils.getFirstNonDesktopTaskView(); focusedTaskViewId = focusedTaskView != null ? focusedTaskView.getTaskViewId() : INVALID_TASK_ID; } else { @@ -3936,9 +3927,9 @@ public abstract class RecentsView< int distanceFromDismissedTask = 1; int slidingTranslation = 0; if (isSlidingTasks) { - int nextSnappedPage = isStagingFocusedTask - ? indexOfChild(mUtils.getFirstSmallTaskView()) - : mUtils.getDesktopTaskViewCount(); + int nextSnappedPage = indexOfChild(isStagingFocusedTask + ? mUtils.getFirstSmallTaskView() + : mUtils.getFirstNonDesktopTaskView()); slidingTranslation = getPagedOrientationHandler().getPrimaryScroll(this) - getScrollForPage(nextSnappedPage); slidingTranslation += mIsRtl ? newClearAllShortTotalWidthTranslation @@ -3964,7 +3955,7 @@ public abstract class RecentsView< Math.abs(i - dismissedIndex), scrollDiff, anim, - splitTimings, i); + splitTimings); needsCurveUpdates = true; } } else if (child instanceof TaskView taskView) { @@ -4340,8 +4331,7 @@ public abstract class RecentsView< int indexDiff, int scrollDiffPerPage, PendingAnimation pendingAnimation, - SplitAnimationTimings splitTimings, - int index) { + SplitAnimationTimings splitTimings) { // No need to translate the AddDesktopButton on dismissing a TaskView, which should be // always at the right most position, even when dismissing the last TaskView. if (view instanceof AddDesktopButton) { @@ -6249,12 +6239,12 @@ public abstract class RecentsView< } @Override - protected int getChildVisibleSize(int index) { - final TaskView taskView = getTaskViewAt(index); + protected int getChildVisibleSize(int childIndex) { + final TaskView taskView = getTaskViewAt(childIndex); if (taskView == null) { - return super.getChildVisibleSize(index); + return super.getChildVisibleSize(childIndex); } - return (int) (super.getChildVisibleSize(index) * taskView.getSizeAdjustment( + return (int) (super.getChildVisibleSize(childIndex) * taskView.getSizeAdjustment( showAsFullscreen())); } @@ -6313,7 +6303,7 @@ public abstract class RecentsView< * Returns how many pixels the page is offset on the currently laid out dominant axis. */ private int getUnclampedScrollOffset(int pageIndex) { - if (pageIndex == -1) { + if (pageIndex == INVALID_PAGE) { return 0; } // Don't dampen the scroll (due to overscroll) if the adjacent tasks are offscreen, so that diff --git a/quickstep/src/com/android/quickstep/views/RecentsViewUtils.kt b/quickstep/src/com/android/quickstep/views/RecentsViewUtils.kt index 94e8c03360..f742ec3898 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsViewUtils.kt +++ b/quickstep/src/com/android/quickstep/views/RecentsViewUtils.kt @@ -73,7 +73,7 @@ class RecentsViewUtils(private val recentsView: RecentsView<*, *>) { } /** Counts [TaskView]s that are [DesktopTaskView] instances. */ - fun getDesktopTaskViewCount(): Int = taskViews.count { it is DesktopTaskView } + private fun getDesktopTaskViewCount(): Int = taskViews.count { it is DesktopTaskView } /** Counts [TaskView]s that are not [DesktopTaskView] instances. */ fun getNonDesktopTaskViewCount(): Int = taskViews.count { it !is DesktopTaskView } @@ -91,7 +91,7 @@ class RecentsViewUtils(private val recentsView: RecentsView<*, *>) { } /** Returns the expected focus task. */ - fun getExpectedFocusedTask(): TaskView? = + fun getFirstNonDesktopTaskView(): TaskView? = if (enableLargeDesktopWindowingTile()) taskViews.firstOrNull { it !is DesktopTaskView } else taskViews.firstOrNull()