Merge "Introduce a function getFristTaskView()" into main

This commit is contained in:
Treehugger Robot
2024-12-10 01:51:26 +00:00
committed by Android (Google) Code Review
8 changed files with 28 additions and 24 deletions
@@ -601,7 +601,7 @@ public class QuickstepLauncher extends Launcher implements RecentsViewContainer,
case QUICK_SWITCH_STATE_ORDINAL: {
RecentsView rv = getOverviewPanel();
TaskView currentPageTask = rv.getCurrentPageTaskView();
TaskView fallbackTask = rv.getTaskViewAt(0);
TaskView fallbackTask = rv.getFirstTaskView();
if (currentPageTask != null || fallbackTask != null) {
TaskView taskToLaunch = currentPageTask;
if (currentPageTask == null) {
@@ -50,7 +50,7 @@ public final class PortraitOverviewStateTouchHelper {
boolean canInterceptTouch(MotionEvent ev) {
if (mRecentsView.getTaskViewCount() > 0) {
// Allow swiping up in the gap between the hotseat and overview.
return ev.getY() >= mRecentsView.getTaskViewAt(0).getBottom();
return ev.getY() >= mRecentsView.getFirstTaskView().getBottom();
} else {
// If there are no tasks, we only intercept if we're below the hotseat height.
return isTouchOverHotseat(mLauncher, ev);
@@ -149,7 +149,7 @@ public class QuickSwitchTouchController extends AbstractStateChangeTouchControll
mOverviewPanel.setFullscreenProgress(progress);
if (progress > UPDATE_SYSUI_FLAGS_THRESHOLD) {
int sysuiFlags = 0;
TaskView tv = mOverviewPanel.getTaskViewAt(0);
TaskView tv = mOverviewPanel.getFirstTaskView();
if (tv != null) {
sysuiFlags = tv.getTaskContainers().getFirst().getSysUiStatusNavFlags();
}
@@ -66,7 +66,7 @@ public abstract class TaskViewTouchController<CONTAINER extends Context & Recent
protected final CONTAINER mContainer;
private final SingleAxisSwipeDetector mDetector;
private final RecentsView mRecentsView;
private final RecentsView<?, ?> mRecentsView;
private final Rect mTempRect = new Rect();
private final boolean mIsRtl;
@@ -157,17 +157,15 @@ public abstract class TaskViewTouchController<CONTAINER extends Context & Recent
} else {
mTaskBeingDragged = null;
for (int i = 0; i < mRecentsView.getTaskViewCount(); i++) {
TaskView view = mRecentsView.getTaskViewAt(i);
if (mRecentsView.isTaskViewVisible(view) && mContainer.getDragLayer()
.isEventOverView(view, ev)) {
for (TaskView taskView : mRecentsView.getTaskViews()) {
if (mRecentsView.isTaskViewVisible(taskView) && mContainer.getDragLayer()
.isEventOverView(taskView, ev)) {
// Disable swiping up and down if the task overlay is modal.
if (isRecentsModal()) {
mTaskBeingDragged = null;
break;
}
mTaskBeingDragged = view;
mTaskBeingDragged = taskView;
int upDirection = mRecentsView.getPagedOrientationHandler()
.getUpDirection(mIsRtl);
@@ -179,10 +177,10 @@ public abstract class TaskViewTouchController<CONTAINER extends Context & Recent
// - We support gestures to enter overview
// - It's the focused task if in grid view
// - The task is snapped
mAllowGoingDown = i == mRecentsView.getCurrentPage()
mAllowGoingDown = taskView == mRecentsView.getCurrentPageTaskView()
&& DisplayController.getNavigationMode(mContainer).hasGestures
&& (!mRecentsView.showAsGrid() || mTaskBeingDragged.isLargeTile())
&& mRecentsView.isTaskInExpectedScrollPosition(i);
&& mRecentsView.isTaskInExpectedScrollPosition(taskView);
directionsToDetectScroll = mAllowGoingDown ? DIRECTION_BOTH : upDirection;
break;
@@ -317,7 +317,7 @@ public interface TaskShortcutFactory {
boolean hideForExistingMultiWindow = container.getDeviceProfile().isMultiWindowMode;
boolean isLargeTile = deviceProfile.isTablet && taskView.isLargeTile();
boolean isTaskInExpectedScrollPosition =
recentsView.isTaskInExpectedScrollPosition(recentsView.indexOfChild(taskView));
recentsView.isTaskInExpectedScrollPosition(taskView);
if (notEnoughTasksToSplit || isTaskSplitNotSupported || hideForExistingMultiWindow
|| (isLargeTile && isTaskInExpectedScrollPosition)) {
@@ -342,7 +342,7 @@ public interface TaskShortcutFactory {
final RecentsView recentsView = taskView.getRecentsView();
boolean isLargeTile = deviceProfile.isTablet && taskView.isLargeTile();
boolean isInExpectedScrollPosition =
recentsView.isTaskInExpectedScrollPosition(recentsView.indexOfChild(taskView));
recentsView.isTaskInExpectedScrollPosition(taskView);
boolean shouldShowActionsButtonInstead =
isLargeTile && isInExpectedScrollPosition;
@@ -108,7 +108,7 @@ public final class TaskViewUtils {
* opening remote target (which we don't get until onAnimationStart) will resolve to a TaskView.
*/
public static TaskView findTaskViewToLaunch(
RecentsView recentsView, View v, RemoteAnimationTarget[] targets) {
RecentsView<?, ?> recentsView, View v, RemoteAnimationTarget[] targets) {
if (v instanceof TaskView) {
TaskView taskView = (TaskView) v;
return recentsView.isTaskViewVisible(taskView) ? taskView : null;
@@ -121,8 +121,7 @@ public final class TaskViewUtils {
ComponentName componentName = itemInfo.getTargetComponent();
int userId = itemInfo.user.getIdentifier();
if (componentName != null) {
for (int i = 0; i < recentsView.getTaskViewCount(); i++) {
TaskView taskView = recentsView.getTaskViewAt(i);
for (TaskView taskView : recentsView.getTaskViews()) {
if (recentsView.isTaskViewVisible(taskView)) {
Task.TaskKey key = taskView.getFirstTask().key;
if (componentName.equals(key.getComponent()) && userId == key.userId) {
@@ -95,6 +95,9 @@ class RecentsViewUtils {
?: taskViews.firstOrNull { it !is DesktopTaskView }
?: taskViews.lastOrNull()
/** Returns the first TaskView if it exists, or null otherwise. */
fun getFirstTaskView(taskViews: Iterable<TaskView>): TaskView? = taskViews.firstOrNull()
/**
* Returns the first TaskView that is not large
*
@@ -846,6 +846,11 @@ public abstract class RecentsView<
private final Matrix mTmpMatrix = new Matrix();
@Nullable
public TaskView getFirstTaskView() {
return mUtils.getFirstTaskView(getTaskViews());
}
public RecentsView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
setEnableFreeScroll(true);
@@ -1493,17 +1498,16 @@ public abstract class RecentsView<
}
/**
* Returns true if the task is in expected scroll position.
*
* @param taskIndex the index of the task
* Returns true if the given TaskView is in expected scroll position.
*/
public boolean isTaskInExpectedScrollPosition(int taskIndex) {
return getScrollForPage(taskIndex) == getPagedOrientationHandler().getPrimaryScroll(this);
public boolean isTaskInExpectedScrollPosition(TaskView taskView) {
return getScrollForPage(indexOfChild(taskView))
== getPagedOrientationHandler().getPrimaryScroll(this);
}
private boolean isFocusedTaskInExpectedScrollPosition() {
TaskView focusedTask = getFocusedTaskView();
return focusedTask != null && isTaskInExpectedScrollPosition(indexOfChild(focusedTask));
return focusedTask != null && isTaskInExpectedScrollPosition(focusedTask);
}
/**
@@ -4717,7 +4721,7 @@ public abstract class RecentsView<
/**
* Returns the current list of [TaskView] children.
*/
private Iterable<TaskView> getTaskViews() {
public Iterable<TaskView> getTaskViews() {
return mUtils.getTaskViews(getTaskViewCount(), this::requireTaskViewAt);
}