• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.wm.shell.windowdecor
18 
19 import android.app.ActivityManager.RunningTaskInfo
20 import android.content.Context
21 import android.graphics.Point
22 import android.view.View
23 import android.view.WindowManager
24 import android.window.TaskSnapshot
25 import androidx.compose.ui.graphics.toArgb
26 import com.android.wm.shell.R
27 import com.android.wm.shell.shared.desktopmode.DesktopModeStatus
28 import com.android.wm.shell.shared.multiinstance.ManageWindowsViewContainer
29 import com.android.wm.shell.splitscreen.SplitScreenController
30 import com.android.wm.shell.windowdecor.additionalviewcontainer.AdditionalSystemViewContainer
31 import com.android.wm.shell.windowdecor.additionalviewcontainer.AdditionalViewContainer
32 import com.android.wm.shell.windowdecor.common.calculateMenuPosition
33 import com.android.wm.shell.windowdecor.common.DecorThemeUtil
34 
35 /**
36  * Implementation of [ManageWindowsViewContainer] meant to be used in desktop header and app
37  * handle.
38  */
39 class DesktopHandleManageWindowsMenu(
40     private val callerTaskInfo: RunningTaskInfo,
41     private val splitScreenController: SplitScreenController,
42     private val captionX: Int,
43     private val captionWidth: Int,
44     private val windowManagerWrapper: WindowManagerWrapper,
45     context: Context,
46     snapshotList: List<Pair<Int, TaskSnapshot?>>,
47     onIconClickListener: ((Int) -> Unit),
48     onOutsideClickListener: (() -> Unit)
49 ) : ManageWindowsViewContainer(
50     context,
51     DecorThemeUtil(context).getColorScheme(callerTaskInfo).background.toArgb()
52 ) {
53     private var menuViewContainer: AdditionalViewContainer? = null
54 
55     init {
56         createMenu(snapshotList, onIconClickListener, onOutsideClickListener)
57         animateOpen()
58     }
59 
calculateMenuPositionnull60     private fun calculateMenuPosition(): Point {
61         return calculateMenuPosition(
62             splitScreenController,
63             callerTaskInfo,
64             marginStart = 0,
65             marginTop = context.resources.getDimensionPixelSize(
66                 R.dimen.desktop_mode_handle_menu_margin_top
67             ),
68             captionX,
69             0,
70             captionWidth,
71             menuView.menuWidth,
72             context.isRtl()
73         )
74     }
75 
addToContainernull76     override fun addToContainer(menuView: ManageWindowsView) {
77         val menuPosition = calculateMenuPosition()
78         menuViewContainer = AdditionalSystemViewContainer(
79             windowManagerWrapper = windowManagerWrapper,
80             taskId = callerTaskInfo.taskId,
81             x = menuPosition.x,
82             y = menuPosition.y,
83             width = menuView.menuWidth,
84             height = menuView.menuHeight,
85             flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or
86                     WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
87             view = menuView.rootView,
88             ignoreCutouts = DesktopModeStatus.canEnterDesktopModeOrShowAppHandle(context),
89         )
90     }
91 
removeFromContainernull92     override fun removeFromContainer() {
93         menuViewContainer?.releaseView()
94     }
95 
Contextnull96     private fun Context.isRtl() =
97         resources.configuration.layoutDirection == View.LAYOUT_DIRECTION_RTL
98 }
99