1 /* 2 * Copyright (C) 2024 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 android.view.View 20 import com.android.launcher3.AbstractFloatingViewHelper 21 import com.android.launcher3.R 22 import com.android.launcher3.logging.StatsLogManager.LauncherEvent 23 import com.android.launcher3.popup.SystemShortcut 24 import com.android.quickstep.views.RecentsView 25 import com.android.quickstep.views.RecentsViewContainer 26 import com.android.quickstep.views.TaskView.TaskContainer 27 import com.android.wm.shell.common.desktopmode.DesktopModeTransitionSource 28 import com.android.wm.shell.shared.DesktopModeStatus 29 30 /** A menu item, "Desktop", that allows the user to bring the current app into Desktop Windowing. */ 31 class DesktopSystemShortcut( 32 container: RecentsViewContainer, 33 private val taskContainer: TaskContainer, 34 abstractFloatingViewHelper: AbstractFloatingViewHelper 35 ) : 36 SystemShortcut<RecentsViewContainer>( 37 R.drawable.ic_caption_desktop_button_foreground, 38 R.string.recent_task_option_desktop, 39 container, 40 taskContainer.itemInfo, 41 taskContainer.taskView, 42 abstractFloatingViewHelper 43 ) { onClicknull44 override fun onClick(view: View) { 45 dismissTaskMenuView() 46 val recentsView = mTarget.getOverviewPanel<RecentsView<*, *>>() 47 recentsView.moveTaskToDesktop( 48 taskContainer, 49 DesktopModeTransitionSource.APP_FROM_OVERVIEW 50 ) { 51 mTarget.statsLogManager 52 .logger() 53 .withItemInfo(taskContainer.itemInfo) 54 .log(LauncherEvent.LAUNCHER_SYSTEM_SHORTCUT_DESKTOP_TAP) 55 } 56 } 57 58 companion object { 59 /** Creates a factory for creating Desktop system shortcuts. */ 60 @JvmOverloads createFactorynull61 fun createFactory( 62 abstractFloatingViewHelper: AbstractFloatingViewHelper = AbstractFloatingViewHelper() 63 ): TaskShortcutFactory { 64 return object : TaskShortcutFactory { 65 override fun getShortcuts( 66 container: RecentsViewContainer, 67 taskContainer: TaskContainer 68 ): List<DesktopSystemShortcut>? { 69 return if (!DesktopModeStatus.canEnterDesktopMode(container.asContext())) null 70 else if (!taskContainer.task.isDockable) null 71 else 72 listOf( 73 DesktopSystemShortcut( 74 container, 75 taskContainer, 76 abstractFloatingViewHelper 77 ) 78 ) 79 } 80 81 override fun showForGroupedTask() = true 82 } 83 } 84 } 85 } 86