• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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 
17 package com.android.wm.shell;
18 
19 import android.annotation.UiContext;
20 import android.content.Context;
21 
22 import com.android.wm.shell.common.ShellExecutor;
23 import com.android.wm.shell.common.annotations.ExternalThread;
24 import com.android.wm.shell.common.annotations.ShellMainThread;
25 
26 import java.util.concurrent.Executor;
27 import java.util.function.Consumer;
28 
29 /** Factory controller which can create {@link TaskView} */
30 public class TaskViewFactoryController {
31     private final ShellTaskOrganizer mTaskOrganizer;
32     private final ShellExecutor mShellExecutor;
33     private final TaskViewFactory mImpl = new TaskViewFactoryImpl();
34 
TaskViewFactoryController(ShellTaskOrganizer taskOrganizer, ShellExecutor shellExecutor)35     public TaskViewFactoryController(ShellTaskOrganizer taskOrganizer,
36             ShellExecutor shellExecutor) {
37         mTaskOrganizer = taskOrganizer;
38         mShellExecutor = shellExecutor;
39     }
40 
asTaskViewFactory()41     public TaskViewFactory asTaskViewFactory() {
42         return mImpl;
43     }
44 
45     /** Creates an {@link TaskView} */
create(@iContext Context context, Executor executor, Consumer<TaskView> onCreate)46     public void create(@UiContext Context context, Executor executor, Consumer<TaskView> onCreate) {
47         TaskView taskView = new TaskView(context, mTaskOrganizer);
48         executor.execute(() -> {
49             onCreate.accept(taskView);
50         });
51     }
52 
53     private class TaskViewFactoryImpl implements TaskViewFactory {
54         @ExternalThread
create(@iContext Context context, Executor executor, Consumer<TaskView> onCreate)55         public void create(@UiContext Context context,
56                 Executor executor, Consumer<TaskView> onCreate) {
57             mShellExecutor.execute(() -> {
58                 TaskViewFactoryController.this.create(context, executor, onCreate);
59             });
60         }
61     }
62 }
63