diff --git a/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchController.java b/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchController.java index cd38e5e285..48cb91148c 100644 --- a/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchController.java +++ b/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchController.java @@ -269,7 +269,7 @@ public final class KeyboardQuickSwitchController implements DesktopTask desktopTask = findDesktopTask(tasks); if (desktopTask != null) { - mTasks = desktopTask.tasks.stream() + mTasks = desktopTask.getTasks().stream() .map(GroupTask::new) .filter(task -> !shouldExcludeTask(task, taskIdsToExclude)) .collect(Collectors.toList()); diff --git a/quickstep/src/com/android/quickstep/util/DesktopTask.java b/quickstep/src/com/android/quickstep/util/DesktopTask.java deleted file mode 100644 index fc4fc4df78..0000000000 --- a/quickstep/src/com/android/quickstep/util/DesktopTask.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.quickstep.util; - -import androidx.annotation.NonNull; - -import com.android.quickstep.views.TaskViewType; -import com.android.systemui.shared.recents.model.Task; - -import java.util.List; -import java.util.Objects; - -/** - * A {@link Task} container that can contain N number of tasks that are part of the desktop in - * recent tasks list. - */ -public class DesktopTask extends GroupTask { - - @NonNull - public final List tasks; - - public DesktopTask(@NonNull List tasks) { - super(tasks.get(0), null, null, TaskViewType.DESKTOP); - this.tasks = tasks; - } - - @Override - public boolean containsTask(int taskId) { - for (Task task : tasks) { - if (task.key.id == taskId) { - return true; - } - } - return false; - } - - @Override - public boolean hasMultipleTasks() { - return tasks.size() > 1; - } - - @Override - public boolean supportsMultipleTasks() { - return true; - } - - @Override - @NonNull - public List getTasks() { - return tasks; - } - - @Override - public DesktopTask copy() { - return new DesktopTask(tasks); - } - - @Override - public String toString() { - return "type=" + taskViewType + " tasks=" + tasks; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof DesktopTask that)) return false; - if (!super.equals(o)) return false; - return Objects.equals(tasks, that.tasks); - } - - @Override - public int hashCode() { - return Objects.hash(super.hashCode(), tasks); - } -} diff --git a/quickstep/src/com/android/quickstep/util/DesktopTask.kt b/quickstep/src/com/android/quickstep/util/DesktopTask.kt new file mode 100644 index 0000000000..1cee2d2115 --- /dev/null +++ b/quickstep/src/com/android/quickstep/util/DesktopTask.kt @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.quickstep.util + +import com.android.quickstep.views.TaskViewType +import com.android.systemui.shared.recents.model.Task +import java.util.Objects + +/** + * A [Task] container that can contain N number of tasks that are part of the desktop in recent + * tasks list. + */ +class DesktopTask(override val tasks: List) : + GroupTask(tasks[0], null, null, TaskViewType.DESKTOP) { + + override fun containsTask(taskId: Int) = tasks.any { it.key.id == taskId } + + override fun hasMultipleTasks() = tasks.size > 1 + + override fun supportsMultipleTasks() = true + + override fun copy() = DesktopTask(tasks) + + override fun toString() = "type=$taskViewType tasks=$tasks" + + override fun equals(o: Any?): Boolean { + if (this === o) return true + if (o !is DesktopTask) return false + if (!super.equals(o)) return false + return tasks == o.tasks + } + + override fun hashCode() = Objects.hash(super.hashCode(), tasks) +} diff --git a/quickstep/src/com/android/quickstep/util/GroupTask.java b/quickstep/src/com/android/quickstep/util/GroupTask.java deleted file mode 100644 index 7aeeb2fc32..0000000000 --- a/quickstep/src/com/android/quickstep/util/GroupTask.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.quickstep.util; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import com.android.launcher3.util.SplitConfigurationOptions.SplitBounds; -import com.android.quickstep.views.TaskViewType; -import com.android.systemui.shared.recents.model.Task; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Objects; - -/** - * A {@link Task} container that can contain one or two tasks, depending on if the two tasks - * are represented as an app-pair in the recents task list. - */ -public class GroupTask { - @NonNull - public final Task task1; - @Nullable - public final Task task2; - @Nullable - public final SplitBounds mSplitBounds; - public final TaskViewType taskViewType; - - public GroupTask(@NonNull Task task) { - this(task, null, null); - } - - public GroupTask(@NonNull Task t1, @Nullable Task t2, @Nullable SplitBounds splitBounds) { - this(t1, t2, splitBounds, t2 != null ? TaskViewType.GROUPED : TaskViewType.SINGLE); - } - - protected GroupTask(@NonNull Task t1, @Nullable Task t2, @Nullable SplitBounds splitBounds, - TaskViewType taskViewType) { - task1 = t1; - task2 = t2; - mSplitBounds = splitBounds; - this.taskViewType = taskViewType; - } - - public boolean containsTask(int taskId) { - return task1.key.id == taskId || (task2 != null && task2.key.id == taskId); - } - - public boolean hasMultipleTasks() { - return task2 != null; - } - - /** - * Returns whether this task supports multiple tasks or not. - */ - public boolean supportsMultipleTasks() { - return taskViewType == TaskViewType.GROUPED; - } - - /** - * Returns a List of all the Tasks in this GroupTask - */ - public List getTasks() { - if (task2 == null) { - return Collections.singletonList(task1); - } else { - return Arrays.asList(task1, task2); - } - } - - /** - * Create a copy of this instance - */ - public GroupTask copy() { - return new GroupTask( - new Task(task1), - task2 != null ? new Task(task2) : null, - mSplitBounds); - } - - @Override - public String toString() { - return "type=" + taskViewType + " task1=" + task1 + " task2=" + task2; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof GroupTask that)) return false; - return taskViewType == that.taskViewType && Objects.equals(task1, - that.task1) && Objects.equals(task2, that.task2) - && Objects.equals(mSplitBounds, that.mSplitBounds); - } - - @Override - public int hashCode() { - return Objects.hash(task1, task2, mSplitBounds, taskViewType); - } -} diff --git a/quickstep/src/com/android/quickstep/util/GroupTask.kt b/quickstep/src/com/android/quickstep/util/GroupTask.kt new file mode 100644 index 0000000000..1dd8d18ab9 --- /dev/null +++ b/quickstep/src/com/android/quickstep/util/GroupTask.kt @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.quickstep.util + +import androidx.annotation.VisibleForTesting +import com.android.launcher3.util.SplitConfigurationOptions +import com.android.quickstep.views.TaskViewType +import com.android.systemui.shared.recents.model.Task +import java.util.Objects + +/** + * A [Task] container that can contain one or two tasks, depending on if the two tasks are + * represented as an app-pair in the recents task list. + */ +open class GroupTask +@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED) +constructor( + @JvmField val task1: Task, + @JvmField val task2: Task?, + @JvmField val mSplitBounds: SplitConfigurationOptions.SplitBounds?, + @JvmField val taskViewType: TaskViewType, +) { + constructor(task: Task) : this(task, null, null) + + constructor( + t1: Task, + t2: Task?, + splitBounds: SplitConfigurationOptions.SplitBounds?, + ) : this(t1, t2, splitBounds, if (t2 != null) TaskViewType.GROUPED else TaskViewType.SINGLE) + + open fun containsTask(taskId: Int) = + task1.key.id == taskId || (task2 != null && task2.key.id == taskId) + + open fun hasMultipleTasks() = task2 != null + + /** Returns whether this task supports multiple tasks or not. */ + open fun supportsMultipleTasks() = taskViewType == TaskViewType.GROUPED + + /** Returns a List of all the Tasks in this GroupTask */ + open val tasks: List + get() = listOfNotNull(task1, task2) + + /** Creates a copy of this instance */ + open fun copy() = GroupTask(Task(task1), if (task2 != null) Task(task2) else null, mSplitBounds) + + override fun toString() = "type=$taskViewType task1=$task1 task2=$task2" + + override fun equals(o: Any?): Boolean { + if (this === o) return true + if (o !is GroupTask) return false + return taskViewType == o.taskViewType && + task1 == o.task1 && + task2 == o.task2 && + mSplitBounds == o.mSplitBounds + } + + override fun hashCode() = Objects.hash(task1, task2, mSplitBounds, taskViewType) +} diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java index 045b823ea3..eac33bc677 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/src/com/android/quickstep/views/RecentsView.java @@ -209,7 +209,6 @@ import com.android.quickstep.recents.viewmodel.RecentsViewData; import com.android.quickstep.recents.viewmodel.RecentsViewModel; import com.android.quickstep.util.ActiveGestureProtoLogProxy; import com.android.quickstep.util.AnimUtils; -import com.android.quickstep.util.DesktopTask; import com.android.quickstep.util.GroupTask; import com.android.quickstep.util.LayoutUtils; import com.android.quickstep.util.RecentsAtomicAnimationFactory; @@ -1971,7 +1970,7 @@ public abstract class RecentsView< } else if (taskView instanceof DesktopTaskView) { // Minimized tasks should not be shown in Overview List nonMinimizedTasks = - ((DesktopTask) groupTask).tasks.stream() + groupTask.getTasks().stream() .filter(task -> !task.isMinimized) .toList(); ((DesktopTaskView) taskView).bind(nonMinimizedTasks, mOrientationState,