• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.quickstep;
17 
18 import static com.android.quickstep.TaskAdapter.TASKS_START_POSITION;
19 import static com.android.quickstep.TaskUtils.getLaunchComponentKeyForTask;
20 
21 import android.app.ActivityOptions;
22 import android.view.View;
23 
24 import androidx.annotation.NonNull;
25 
26 import com.android.launcher3.logging.StatsLogManager;
27 import com.android.quickstep.views.TaskItemView;
28 import com.android.systemui.shared.recents.model.Task;
29 import com.android.systemui.shared.recents.model.Task.TaskKey;
30 import com.android.systemui.shared.system.ActivityManagerWrapper;
31 
32 /**
33  * Controller that provides logic for task-related commands on recents and updating the model/view
34  * as appropriate.
35  */
36 public final class TaskActionController {
37 
38     private final TaskListLoader mLoader;
39     private final TaskAdapter mAdapter;
40     private final StatsLogManager mStatsLogManager;
41 
TaskActionController(TaskListLoader loader, TaskAdapter adapter, StatsLogManager logManager)42     public TaskActionController(TaskListLoader loader, TaskAdapter adapter,
43             StatsLogManager logManager) {
44         mLoader = loader;
45         mAdapter = adapter;
46         mStatsLogManager = logManager;
47     }
48 
49     /**
50      * Launch the task associated with the task holder, animating into the app from the task view.
51      *
52      * @param viewHolder the task view holder to launch
53      */
launchTaskFromView(@onNull TaskHolder viewHolder)54     public void launchTaskFromView(@NonNull TaskHolder viewHolder) {
55         if (!viewHolder.getTask().isPresent()) {
56             return;
57         }
58         TaskItemView itemView = (TaskItemView) (viewHolder.itemView);
59         View v = itemView.getThumbnailView();
60         int left = 0;
61         int top = 0;
62         int width = v.getMeasuredWidth();
63         int height = v.getMeasuredHeight();
64 
65         TaskKey key = viewHolder.getTask().get().key;
66         ActivityOptions opts = ActivityOptions.makeClipRevealAnimation(v, left, top, width, height);
67         ActivityManagerWrapper.getInstance().startActivityFromRecentsAsync(key, opts,
68                 null /* resultCallback */, null /* resultCallbackHandler */);
69         mStatsLogManager.logTaskLaunch(null /* view */, getLaunchComponentKeyForTask(key));
70     }
71 
72     /**
73      * Launch the task directly with a basic animation.
74      *
75      * @param task the task to launch
76      */
launchTask(@onNull Task task)77     public void launchTask(@NonNull Task task) {
78         ActivityOptions opts = ActivityOptions.makeBasic();
79         ActivityManagerWrapper.getInstance().startActivityFromRecentsAsync(task.key, opts,
80                 null /* resultCallback */, null /* resultCallbackHandler */);
81         mStatsLogManager.logTaskLaunch(null /* view */, getLaunchComponentKeyForTask(task.key));
82     }
83 
84     /**
85      * Removes the task holder and the task, updating the model and the view.
86      *
87      * @param viewHolder the task view holder to remove
88      */
removeTask(TaskHolder viewHolder)89     public void removeTask(TaskHolder viewHolder) {
90         if (!viewHolder.getTask().isPresent()) {
91             return;
92         }
93         int position = viewHolder.getAdapterPosition();
94         Task task = viewHolder.getTask().get();
95         ActivityManagerWrapper.getInstance().removeTask(task.key.id);
96         mLoader.removeTask(task);
97         mAdapter.notifyItemRemoved(position);
98         // TODO(b/131840601): Add logging point for removal.
99     }
100 
101     /**
102      * Clears all tasks and updates the model and view.
103      */
clearAllTasks()104     public void clearAllTasks() {
105         int count = mAdapter.getItemCount();
106         ActivityManagerWrapper.getInstance().removeAllRecentTasks();
107         mLoader.clearAllTasks();
108         mAdapter.notifyItemRangeRemoved(TASKS_START_POSITION /* positionStart */, count);
109     }
110 }
111