• 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.uioverrides.states.BackgroundAppState.getOverviewScaleAndOffsetForBackgroundState;
19 import static com.android.launcher3.uioverrides.states.OverviewModalTaskState.getOverviewScaleAndOffsetForModalState;
20 
21 import android.content.Context;
22 import android.graphics.Color;
23 
24 import com.android.launcher3.DeviceProfile;
25 import com.android.launcher3.R;
26 import com.android.launcher3.config.FeatureFlags;
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 
44     public static final RecentsState DEFAULT = new RecentsState(0,
45             FLAG_CLEAR_ALL_BUTTON | FLAG_OVERVIEW_ACTIONS | FLAG_SHOW_AS_GRID | FLAG_SCRIM
46                     | FLAG_LIVE_TILE);
47     public static final RecentsState MODAL_TASK = new ModalState(1,
48             FLAG_DISABLE_RESTORE | FLAG_CLEAR_ALL_BUTTON | FLAG_OVERVIEW_ACTIONS | FLAG_MODAL
49                     | FLAG_SHOW_AS_GRID | FLAG_SCRIM | FLAG_LIVE_TILE);
50     public static final RecentsState BACKGROUND_APP = new BackgroundAppState(2,
51             FLAG_DISABLE_RESTORE | FLAG_NON_INTERACTIVE | FLAG_FULL_SCREEN);
52     public static final RecentsState HOME = new RecentsState(3, 0);
53     public static final RecentsState BG_LAUNCHER = new LauncherState(4, 0);
54 
55     public final int ordinal;
56     private final int mFlags;
57 
58     private static final float NO_OFFSET = 0;
59     private static final float NO_SCALE = 1;
60 
RecentsState(int id, int flags)61     public RecentsState(int id, int flags) {
62         this.ordinal = id;
63         this.mFlags = flags;
64     }
65 
66 
67     @Override
toString()68     public String toString() {
69         return "Ordinal-" + ordinal;
70     }
71 
72     @Override
hasFlag(int mask)73     public final boolean hasFlag(int mask) {
74         return (mFlags & mask) != 0;
75     }
76 
77     @Override
getTransitionDuration(Context context)78     public int getTransitionDuration(Context context) {
79         return 250;
80     }
81 
82     @Override
getHistoryForState(RecentsState previousState)83     public RecentsState getHistoryForState(RecentsState previousState) {
84         return DEFAULT;
85     }
86 
87     /**
88      * For this state, how modal should over view been shown. 0 modalness means all tasks drawn,
89      * 1 modalness means the current task is show on its own.
90      */
getOverviewModalness()91     public float getOverviewModalness() {
92         return hasFlag(FLAG_MODAL) ? 1 : 0;
93     }
94 
isFullScreen()95     public boolean isFullScreen() {
96         return hasFlag(FLAG_FULL_SCREEN);
97     }
98 
99     /**
100      * For this state, whether clear all button should be shown.
101      */
hasClearAllButton()102     public boolean hasClearAllButton() {
103         return hasFlag(FLAG_CLEAR_ALL_BUTTON);
104     }
105 
106     /**
107      * For this state, whether overview actions should be shown.
108      */
hasOverviewActions()109     public boolean hasOverviewActions() {
110         return hasFlag(FLAG_OVERVIEW_ACTIONS);
111     }
112 
113     /**
114      * For this state, whether live tile should be shown.
115      */
hasLiveTile()116     public boolean hasLiveTile() {
117         return hasFlag(FLAG_LIVE_TILE);
118     }
119 
120     /**
121      * For this state, what color scrim should be drawn behind overview.
122      */
getScrimColor(RecentsActivity activity)123     public int getScrimColor(RecentsActivity activity) {
124         return hasFlag(FLAG_SCRIM) ? Themes.getAttrColor(activity, R.attr.overviewScrimColor)
125                 : Color.TRANSPARENT;
126     }
127 
getOverviewScaleAndOffset(RecentsActivity activity)128     public float[] getOverviewScaleAndOffset(RecentsActivity activity) {
129         return new float[] { NO_SCALE, NO_OFFSET };
130     }
131 
132     /**
133      * For this state, whether tasks should layout as a grid rather than a list.
134      */
displayOverviewTasksAsGrid(DeviceProfile deviceProfile)135     public boolean displayOverviewTasksAsGrid(DeviceProfile deviceProfile) {
136         return hasFlag(FLAG_SHOW_AS_GRID) && showAsGrid(deviceProfile);
137     }
138 
showAsGrid(DeviceProfile deviceProfile)139     private boolean showAsGrid(DeviceProfile deviceProfile) {
140         return deviceProfile.isTablet && FeatureFlags.ENABLE_OVERVIEW_GRID.get();
141     }
142 
143     private static class ModalState extends RecentsState {
144 
ModalState(int id, int flags)145         public ModalState(int id, int flags) {
146             super(id, flags);
147         }
148 
149         @Override
getOverviewScaleAndOffset(RecentsActivity activity)150         public float[] getOverviewScaleAndOffset(RecentsActivity activity) {
151             return getOverviewScaleAndOffsetForModalState(activity);
152         }
153     }
154 
155     private static class BackgroundAppState extends RecentsState {
BackgroundAppState(int id, int flags)156         public BackgroundAppState(int id, int flags) {
157             super(id, flags);
158         }
159 
160         @Override
getOverviewScaleAndOffset(RecentsActivity activity)161         public float[] getOverviewScaleAndOffset(RecentsActivity activity) {
162             return getOverviewScaleAndOffsetForBackgroundState(activity);
163         }
164     }
165 
166     private static class LauncherState extends RecentsState {
LauncherState(int id, int flags)167         LauncherState(int id, int flags) {
168             super(id, flags);
169         }
170 
171         @Override
getOverviewScaleAndOffset(RecentsActivity activity)172         public float[] getOverviewScaleAndOffset(RecentsActivity activity) {
173             return new float[] { NO_SCALE, 1 };
174         }
175     }
176 }
177