1 /* 2 * Copyright (C) 2018 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.quickstep; 18 19 import static com.android.launcher3.util.MainThreadInitializedObject.forOverride; 20 21 import android.graphics.Matrix; 22 import android.view.View; 23 24 import com.android.launcher3.BaseActivity; 25 import com.android.launcher3.BaseDraggingActivity; 26 import com.android.launcher3.R; 27 import com.android.launcher3.util.MainThreadInitializedObject; 28 import com.android.launcher3.util.ResourceBasedOverride; 29 import com.android.quickstep.views.TaskThumbnailView; 30 import com.android.quickstep.views.TaskView; 31 import com.android.systemui.shared.recents.model.Task; 32 import com.android.systemui.shared.recents.model.ThumbnailData; 33 34 import java.util.ArrayList; 35 import java.util.List; 36 37 /** 38 * Factory class to create and add an overlays on the TaskView 39 */ 40 public class TaskOverlayFactory implements ResourceBasedOverride { 41 42 /** Note that these will be shown in order from top to bottom, if available for the task. */ 43 private static final TaskSystemShortcut[] MENU_OPTIONS = new TaskSystemShortcut[]{ 44 new TaskSystemShortcut.AppInfo(), 45 new TaskSystemShortcut.SplitScreen(), 46 new TaskSystemShortcut.Pin(), 47 new TaskSystemShortcut.Install(), 48 new TaskSystemShortcut.Freeform() 49 }; 50 51 public static final MainThreadInitializedObject<TaskOverlayFactory> INSTANCE = 52 forOverride(TaskOverlayFactory.class, R.string.task_overlay_factory_class); 53 getEnabledShortcuts(TaskView taskView)54 public List<TaskSystemShortcut> getEnabledShortcuts(TaskView taskView) { 55 final ArrayList<TaskSystemShortcut> shortcuts = new ArrayList<>(); 56 final BaseDraggingActivity activity = BaseActivity.fromContext(taskView.getContext()); 57 for (TaskSystemShortcut menuOption : MENU_OPTIONS) { 58 View.OnClickListener onClickListener = 59 menuOption.getOnClickListener(activity, taskView); 60 if (onClickListener != null) { 61 shortcuts.add(menuOption); 62 } 63 } 64 return shortcuts; 65 } 66 createOverlay(TaskThumbnailView thumbnailView)67 public TaskOverlay createOverlay(TaskThumbnailView thumbnailView) { 68 return new TaskOverlay(); 69 } 70 71 public static class TaskOverlay { 72 73 /** 74 * Called when the current task is interactive for the user 75 */ initOverlay(Task task, ThumbnailData thumbnail, Matrix matrix)76 public void initOverlay(Task task, ThumbnailData thumbnail, Matrix matrix) { } 77 78 /** 79 * Called when the overlay is no longer used. 80 */ reset()81 public void reset() { } 82 } 83 } 84