summaryrefslogtreecommitdiffstats
path: root/go/quickstep/src/com/android/quickstep/TaskActionController.java
blob: 0e921c0db1ba2e2b7355e98c4d2a43cecb527cc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
 * Copyright (C) 2019 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;

import static com.android.quickstep.TaskAdapter.TASKS_START_POSITION;

import android.app.ActivityOptions;
import android.view.View;

import androidx.annotation.NonNull;

import com.android.quickstep.views.TaskItemView;
import com.android.systemui.shared.recents.model.Task;
import com.android.systemui.shared.system.ActivityManagerWrapper;

/**
 * Controller that provides logic for task-related commands on recents and updating the model/view
 * as appropriate.
 */
public final class TaskActionController {

    private final TaskListLoader mLoader;
    private final TaskAdapter mAdapter;

    public TaskActionController(TaskListLoader loader, TaskAdapter adapter) {
        mLoader = loader;
        mAdapter = adapter;
    }

    /**
     * Launch the task associated with the task holder, animating into the app from the task view.
     *
     * @param viewHolder the task view holder to launch
     */
    public void launchTaskFromView(@NonNull TaskHolder viewHolder) {
        if (!viewHolder.getTask().isPresent()) {
            return;
        }
        TaskItemView itemView = (TaskItemView) (viewHolder.itemView);
        View v = itemView.getThumbnailView();
        int left = 0;
        int top = 0;
        int width = v.getMeasuredWidth();
        int height = v.getMeasuredHeight();

        ActivityOptions opts = ActivityOptions.makeClipRevealAnimation(v, left, top, width, height);
        ActivityManagerWrapper.getInstance().startActivityFromRecentsAsync(
                viewHolder.getTask().get().key, opts, null /* resultCallback */,
                null /* resultCallbackHandler */);
    }

    /**
     * Launch the task directly with a basic animation.
     *
     * @param task the task to launch
     */
    public void launchTask(@NonNull Task task) {
        ActivityOptions opts = ActivityOptions.makeBasic();
        ActivityManagerWrapper.getInstance().startActivityFromRecentsAsync(task.key, opts,
                null /* resultCallback */, null /* resultCallbackHandler */);
    }

    /**
     * Removes the task holder and the task, updating the model and the view.
     *
     * @param viewHolder the task view holder to remove
     */
    public void removeTask(TaskHolder viewHolder) {
        if (!viewHolder.getTask().isPresent()) {
            return;
        }
        int position = viewHolder.getAdapterPosition();
        Task task = viewHolder.getTask().get();
        ActivityManagerWrapper.getInstance().removeTask(task.key.id);
        mLoader.removeTask(task);
        mAdapter.notifyItemRemoved(position);
    }

    /**
     * Clears all tasks and updates the model and view.
     */
    public void clearAllTasks() {
        int count = mAdapter.getItemCount();
        ActivityManagerWrapper.getInstance().removeAllRecentTasks();
        mLoader.clearAllTasks();
        mAdapter.notifyItemRangeRemoved(TASKS_START_POSITION /* positionStart */, count);
    }
}