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.desktopmode
18 
19 import android.view.WindowManager.TransitionType
20 import com.android.wm.shell.common.desktopmode.DesktopModeTransitionSource
21 import com.android.wm.shell.transition.Transitions.TRANSIT_DESKTOP_MODE_TYPES
22 
23 /**
24  * Contains desktop mode [TransitionType]s (extended from [TRANSIT_DESKTOP_MODE_TYPES]) and helper
25  * methods.
26  */
27 object DesktopModeTransitionTypes {
28 
29     const val TRANSIT_ENTER_DESKTOP_FROM_APP_HANDLE_MENU_BUTTON = TRANSIT_DESKTOP_MODE_TYPES + 1
30     const val TRANSIT_ENTER_DESKTOP_FROM_APP_FROM_OVERVIEW = TRANSIT_DESKTOP_MODE_TYPES + 2
31     const val TRANSIT_ENTER_DESKTOP_FROM_KEYBOARD_SHORTCUT = TRANSIT_DESKTOP_MODE_TYPES + 3
32     const val TRANSIT_ENTER_DESKTOP_FROM_UNKNOWN = TRANSIT_DESKTOP_MODE_TYPES + 4
33     const val TRANSIT_EXIT_DESKTOP_MODE_TASK_DRAG = TRANSIT_DESKTOP_MODE_TYPES + 5
34     const val TRANSIT_EXIT_DESKTOP_MODE_HANDLE_MENU_BUTTON = TRANSIT_DESKTOP_MODE_TYPES + 6
35     const val TRANSIT_EXIT_DESKTOP_MODE_KEYBOARD_SHORTCUT = TRANSIT_DESKTOP_MODE_TYPES + 7
36     const val TRANSIT_EXIT_DESKTOP_MODE_UNKNOWN = TRANSIT_DESKTOP_MODE_TYPES + 8
37 
38     /** Return whether the [TransitionType] corresponds to a transition to enter desktop mode. */
39     @JvmStatic
isEnterDesktopModeTransitionnull40     fun @receiver:TransitionType Int.isEnterDesktopModeTransition(): Boolean {
41         return this in
42             listOf(
43                 TRANSIT_ENTER_DESKTOP_FROM_APP_HANDLE_MENU_BUTTON,
44                 TRANSIT_ENTER_DESKTOP_FROM_APP_FROM_OVERVIEW,
45                 TRANSIT_ENTER_DESKTOP_FROM_KEYBOARD_SHORTCUT,
46                 TRANSIT_ENTER_DESKTOP_FROM_UNKNOWN
47             )
48     }
49 
50     /**
51      * Returns corresponding desktop mode enter [TransitionType] for a
52      * [DesktopModeTransitionSource].
53      */
54     @JvmStatic
55     @TransitionType
getEnterTransitionTypenull56     fun DesktopModeTransitionSource.getEnterTransitionType(): Int {
57         return when (this) {
58             DesktopModeTransitionSource.APP_HANDLE_MENU_BUTTON ->
59                 TRANSIT_ENTER_DESKTOP_FROM_APP_HANDLE_MENU_BUTTON
60             DesktopModeTransitionSource.APP_FROM_OVERVIEW ->
61                 TRANSIT_ENTER_DESKTOP_FROM_APP_FROM_OVERVIEW
62             DesktopModeTransitionSource.KEYBOARD_SHORTCUT ->
63                 TRANSIT_ENTER_DESKTOP_FROM_KEYBOARD_SHORTCUT
64             else -> TRANSIT_ENTER_DESKTOP_FROM_UNKNOWN
65         }
66     }
67 
68     /** Return whether the [TransitionType] corresponds to a transition to exit desktop mode. */
69     @JvmStatic
isExitDesktopModeTransitionnull70     fun @receiver:TransitionType Int.isExitDesktopModeTransition(): Boolean {
71         return this in
72             listOf(
73                 TRANSIT_EXIT_DESKTOP_MODE_TASK_DRAG,
74                 TRANSIT_EXIT_DESKTOP_MODE_HANDLE_MENU_BUTTON,
75                 TRANSIT_EXIT_DESKTOP_MODE_KEYBOARD_SHORTCUT,
76                 TRANSIT_EXIT_DESKTOP_MODE_UNKNOWN
77             )
78     }
79 
80     /**
81      * Returns corresponding desktop mode exit [TransitionType] for a [DesktopModeTransitionSource].
82      */
83     @JvmStatic
84     @TransitionType
getExitTransitionTypenull85     fun DesktopModeTransitionSource.getExitTransitionType(): Int {
86         return when (this) {
87             DesktopModeTransitionSource.TASK_DRAG -> TRANSIT_EXIT_DESKTOP_MODE_TASK_DRAG
88             DesktopModeTransitionSource.APP_HANDLE_MENU_BUTTON ->
89                 TRANSIT_EXIT_DESKTOP_MODE_HANDLE_MENU_BUTTON
90             DesktopModeTransitionSource.KEYBOARD_SHORTCUT ->
91                 TRANSIT_EXIT_DESKTOP_MODE_KEYBOARD_SHORTCUT
92             else -> TRANSIT_EXIT_DESKTOP_MODE_UNKNOWN
93         }
94     }
95 }
96