1 /*
2  * Copyright (C) 2021 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 package com.android.wm.shell.common.split;
17 
18 import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
19 import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
20 import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
21 import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW;
22 import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
23 
24 import android.annotation.IntDef;
25 
26 import com.android.wm.shell.shared.TransitionUtil;
27 
28 /** Helper utility class of methods and constants that are available to be imported in Launcher. */
29 public class SplitScreenConstants {
30     /** Duration used for every split fade-in or fade-out. */
31     public static final int FADE_DURATION = 133;
32 
33     /** Key for passing in widget intents when invoking split from launcher workspace. */
34     public static final String KEY_EXTRA_WIDGET_INTENT = "key_extra_widget_intent";
35 
36     ///////////////
37     // IMPORTANT for the following SPLIT_POSITION and SNAP_TO constants:
38     // These int values must not be changed -- they are persisted to user-defined app pairs, and
39     // will break things if changed.
40     //
41 
42     /**
43      * Split position isn't specified normally meaning to use what ever it is currently set to.
44      */
45     public static final int SPLIT_POSITION_UNDEFINED = -1;
46 
47     /**
48      * Specifies that a split is positioned at the top half of the screen if
49      * in portrait mode or at the left half of the screen if in landscape mode.
50      */
51     public static final int SPLIT_POSITION_TOP_OR_LEFT = 0;
52 
53     /**
54      * Specifies that a split is positioned at the bottom half of the screen if
55      * in portrait mode or at the right half of the screen if in landscape mode.
56      */
57     public static final int SPLIT_POSITION_BOTTOM_OR_RIGHT = 1;
58 
59     @IntDef(prefix = {"SPLIT_POSITION_"}, value = {
60             SPLIT_POSITION_UNDEFINED,
61             SPLIT_POSITION_TOP_OR_LEFT,
62             SPLIT_POSITION_BOTTOM_OR_RIGHT
63     })
64     public @interface SplitPosition {
65     }
66 
67     /** A snap target in the first half of the screen, where the split is roughly 30-70. */
68     public static final int SNAP_TO_30_70 = 0;
69 
70     /** The 50-50 snap target */
71     public static final int SNAP_TO_50_50 = 1;
72 
73     /** A snap target in the latter half of the screen, where the split is roughly 70-30. */
74     public static final int SNAP_TO_70_30 = 2;
75 
76     /**
77      * These snap targets are used for split pairs in a stable, non-transient state. They may be
78      * persisted in Launcher when the user saves an app pair. They are a subset of
79      * {@link SnapPosition}.
80      */
81     @IntDef(prefix = { "SNAP_TO_" }, value = {
82             SNAP_TO_30_70,
83             SNAP_TO_50_50,
84             SNAP_TO_70_30
85     })
86     public @interface PersistentSnapPosition {}
87 
88     /**
89      * Checks if the snapPosition in question is a {@link PersistentSnapPosition}.
90      */
isPersistentSnapPosition(@napPosition int snapPosition)91     public static boolean isPersistentSnapPosition(@SnapPosition int snapPosition) {
92         return snapPosition == SNAP_TO_30_70
93                 || snapPosition == SNAP_TO_50_50
94                 || snapPosition == SNAP_TO_70_30;
95     }
96 
97     /** The divider doesn't snap to any target and is freely placeable. */
98     public static final int SNAP_TO_NONE = 10;
99 
100     /** If the divider reaches this value, the left/top task should be dismissed. */
101     public static final int SNAP_TO_START_AND_DISMISS = 11;
102 
103     /** If the divider reaches this value, the right/bottom task should be dismissed. */
104     public static final int SNAP_TO_END_AND_DISMISS = 12;
105 
106     /** A snap target positioned near the screen edge for a minimized task */
107     public static final int SNAP_TO_MINIMIZE = 13;
108 
109     @IntDef(prefix = { "SNAP_TO_" }, value = {
110             SNAP_TO_30_70,
111             SNAP_TO_50_50,
112             SNAP_TO_70_30,
113             SNAP_TO_NONE,
114             SNAP_TO_START_AND_DISMISS,
115             SNAP_TO_END_AND_DISMISS,
116             SNAP_TO_MINIMIZE
117     })
118     public @interface SnapPosition {}
119 
120     ///////////////
121 
122     public static final int[] CONTROLLED_ACTIVITY_TYPES = {ACTIVITY_TYPE_STANDARD};
123     public static final int[] CONTROLLED_WINDOWING_MODES =
124             {WINDOWING_MODE_FULLSCREEN, WINDOWING_MODE_UNDEFINED};
125     public static final int[] CONTROLLED_WINDOWING_MODES_WHEN_ACTIVE =
126             {WINDOWING_MODE_FULLSCREEN, WINDOWING_MODE_UNDEFINED, WINDOWING_MODE_MULTI_WINDOW,
127             WINDOWING_MODE_FREEFORM};
128 
129     /** Flag applied to a transition change to identify it as a divider bar for animation. */
130     public static final int FLAG_IS_DIVIDER_BAR = TransitionUtil.FLAG_IS_DIVIDER_BAR;
131 
splitPositionToString(@plitPosition int pos)132     public static final String splitPositionToString(@SplitPosition int pos) {
133         switch (pos) {
134             case SPLIT_POSITION_UNDEFINED:
135                 return "SPLIT_POSITION_UNDEFINED";
136             case SPLIT_POSITION_TOP_OR_LEFT:
137                 return "SPLIT_POSITION_TOP_OR_LEFT";
138             case SPLIT_POSITION_BOTTOM_OR_RIGHT:
139                 return "SPLIT_POSITION_BOTTOM_OR_RIGHT";
140             default:
141                 return "UNKNOWN";
142         }
143     }
144 }
145