• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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.quickstep.fallback;
17 
18 import static com.android.launcher3.LauncherState.FLAG_CLOSE_POPUPS;
19 import static com.android.launcher3.uioverrides.states.BackgroundAppState.getOverviewScaleAndOffsetForBackgroundState;
20 import static com.android.launcher3.uioverrides.states.OverviewModalTaskState.getOverviewScaleAndOffsetForModalState;
21 
22 import android.content.Context;
23 import android.graphics.Color;
24 
25 import com.android.launcher3.DeviceProfile;
26 import com.android.launcher3.R;
27 import com.android.launcher3.statemanager.BaseState;
28 import com.android.launcher3.util.Themes;
29 import com.android.quickstep.RecentsActivity;
30 
31 /**
32  * State definition for Fallback recents
33  */
34 public class RecentsState implements BaseState<RecentsState> {
35 
36     private static final int FLAG_MODAL = BaseState.getFlag(0);
37     private static final int FLAG_CLEAR_ALL_BUTTON = BaseState.getFlag(1);
38     private static final int FLAG_FULL_SCREEN = BaseState.getFlag(2);
39     private static final int FLAG_OVERVIEW_ACTIONS = BaseState.getFlag(3);
40     private static final int FLAG_SHOW_AS_GRID = BaseState.getFlag(4);
41     private static final int FLAG_SCRIM = BaseState.getFlag(5);
42     private static final int FLAG_LIVE_TILE = BaseState.getFlag(6);
43     private static final int FLAG_OVERVIEW_UI = BaseState.getFlag(7);
44     private static final int FLAG_TASK_THUMBNAIL_SPLASH = BaseState.getFlag(8);
45 
46     public static final RecentsState DEFAULT = new RecentsState(0,
47             FLAG_DISABLE_RESTORE | FLAG_CLEAR_ALL_BUTTON | FLAG_OVERVIEW_ACTIONS | FLAG_SHOW_AS_GRID
48                     | FLAG_SCRIM | FLAG_LIVE_TILE | FLAG_OVERVIEW_UI);
49     public static final RecentsState MODAL_TASK = new ModalState(1,
50             FLAG_DISABLE_RESTORE | FLAG_CLEAR_ALL_BUTTON | FLAG_OVERVIEW_ACTIONS | FLAG_MODAL
51                     | FLAG_SHOW_AS_GRID | FLAG_SCRIM | FLAG_LIVE_TILE | FLAG_OVERVIEW_UI);
52     public static final RecentsState BACKGROUND_APP = new BackgroundAppState(2,
53             FLAG_DISABLE_RESTORE | FLAG_NON_INTERACTIVE | FLAG_FULL_SCREEN | FLAG_OVERVIEW_UI
54                     | FLAG_TASK_THUMBNAIL_SPLASH);
55     public static final RecentsState HOME = new RecentsState(3, 0);
56     public static final RecentsState BG_LAUNCHER = new LauncherState(4, 0);
57     public static final RecentsState OVERVIEW_SPLIT_SELECT = new RecentsState(5,
58             FLAG_SHOW_AS_GRID | FLAG_SCRIM | FLAG_OVERVIEW_UI | FLAG_CLOSE_POPUPS
59                     | FLAG_DISABLE_RESTORE);
60 
61     public final int ordinal;
62     private final int mFlags;
63 
64     private static final float NO_OFFSET = 0;
65     private static final float NO_SCALE = 1;
66 
RecentsState(int id, int flags)67     public RecentsState(int id, int flags) {
68         this.ordinal = id;
69         this.mFlags = flags;
70     }
71 
72 
73     @Override
toString()74     public String toString() {
75         return "Ordinal-" + ordinal;
76     }
77 
78     @Override
hasFlag(int mask)79     public final boolean hasFlag(int mask) {
80         return (mFlags & mask) != 0;
81     }
82 
83     @Override
getTransitionDuration(Context context, boolean isToState)84     public int getTransitionDuration(Context context, boolean isToState) {
85         return 250;
86     }
87 
88     @Override
getHistoryForState(RecentsState previousState)89     public RecentsState getHistoryForState(RecentsState previousState) {
90         return DEFAULT;
91     }
92 
93     /**
94      * For this state, how modal should over view been shown. 0 modalness means all tasks drawn,
95      * 1 modalness means the current task is show on its own.
96      */
getOverviewModalness()97     public float getOverviewModalness() {
98         return hasFlag(FLAG_MODAL) ? 1 : 0;
99     }
100 
isFullScreen()101     public boolean isFullScreen() {
102         return hasFlag(FLAG_FULL_SCREEN);
103     }
104 
105     /**
106      * For this state, whether clear all button should be shown.
107      */
hasClearAllButton()108     public boolean hasClearAllButton() {
109         return hasFlag(FLAG_CLEAR_ALL_BUTTON);
110     }
111 
112     /**
113      * For this state, whether overview actions should be shown.
114      */
hasOverviewActions()115     public boolean hasOverviewActions() {
116         return hasFlag(FLAG_OVERVIEW_ACTIONS);
117     }
118 
119     /**
120      * For this state, whether live tile should be shown.
121      */
hasLiveTile()122     public boolean hasLiveTile() {
123         return hasFlag(FLAG_LIVE_TILE);
124     }
125 
126     /**
127      * For this state, what color scrim should be drawn behind overview.
128      */
getScrimColor(RecentsActivity activity)129     public int getScrimColor(RecentsActivity activity) {
130         return hasFlag(FLAG_SCRIM) ? Themes.getAttrColor(activity, R.attr.overviewScrimColor)
131                 : Color.TRANSPARENT;
132     }
133 
getOverviewScaleAndOffset(RecentsActivity activity)134     public float[] getOverviewScaleAndOffset(RecentsActivity activity) {
135         return new float[] { NO_SCALE, NO_OFFSET };
136     }
137 
138     /**
139      * For this state, whether tasks should layout as a grid rather than a list.
140      */
displayOverviewTasksAsGrid(DeviceProfile deviceProfile)141     public boolean displayOverviewTasksAsGrid(DeviceProfile deviceProfile) {
142         return hasFlag(FLAG_SHOW_AS_GRID) && deviceProfile.isTablet;
143     }
144 
145     @Override
showTaskThumbnailSplash()146     public boolean showTaskThumbnailSplash() {
147         return hasFlag(FLAG_TASK_THUMBNAIL_SPLASH);
148     }
149 
150     /**
151      * True if the state has overview panel visible.
152      */
overviewUi()153     public boolean overviewUi() {
154         return hasFlag(FLAG_OVERVIEW_UI);
155     }
156 
157     private static class ModalState extends RecentsState {
158 
ModalState(int id, int flags)159         public ModalState(int id, int flags) {
160             super(id, flags);
161         }
162 
163         @Override
getOverviewScaleAndOffset(RecentsActivity activity)164         public float[] getOverviewScaleAndOffset(RecentsActivity activity) {
165             return getOverviewScaleAndOffsetForModalState(activity);
166         }
167     }
168 
169     private static class BackgroundAppState extends RecentsState {
BackgroundAppState(int id, int flags)170         public BackgroundAppState(int id, int flags) {
171             super(id, flags);
172         }
173 
174         @Override
getOverviewScaleAndOffset(RecentsActivity activity)175         public float[] getOverviewScaleAndOffset(RecentsActivity activity) {
176             return getOverviewScaleAndOffsetForBackgroundState(activity);
177         }
178     }
179 
180     private static class LauncherState extends RecentsState {
LauncherState(int id, int flags)181         LauncherState(int id, int flags) {
182             super(id, flags);
183         }
184 
185         @Override
getOverviewScaleAndOffset(RecentsActivity activity)186         public float[] getOverviewScaleAndOffset(RecentsActivity activity) {
187             return new float[] { NO_SCALE, 1 };
188         }
189     }
190 }
191