• 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.launcher3.statemanager;
17 
18 import com.android.launcher3.DeviceProfile;
19 import com.android.launcher3.views.ActivityContext;
20 
21 /**
22  * Interface representing a state of a StatefulContainer
23  */
24 public interface BaseState<T> {
25 
26     // Flag to indicate that Launcher is non-interactive in this state
27     int FLAG_NON_INTERACTIVE = 1 << 0;
28     int FLAG_DISABLE_RESTORE = 1 << 1;
29 
getFlag(int index)30     static int getFlag(int index) {
31         // reserve few spots to base flags
32         return 1 << (index + 2);
33     }
34 
35     /**
36      * @return How long the animation to this state should take (or from this state to NORMAL).
37      */
getTransitionDuration(ActivityContext context, boolean isToState)38     int getTransitionDuration(ActivityContext context, boolean isToState);
39 
40     /**
41      * Returns the state to go back to from this state
42      */
getHistoryForState(T previousState)43     T getHistoryForState(T previousState);
44 
45     /**
46      * @return true if the state can be persisted across activity restarts.
47      */
shouldDisableRestore()48     default boolean shouldDisableRestore() {
49         return hasFlag(FLAG_DISABLE_RESTORE);
50     }
51 
52     /**
53      * Returns if the state has the provided flag
54      */
hasFlag(int flagMask)55     boolean hasFlag(int flagMask);
56 
57     /**
58      * For this state, whether tasks should layout as a grid rather than a list.
59      */
displayOverviewTasksAsGrid(DeviceProfile deviceProfile)60     default boolean displayOverviewTasksAsGrid(DeviceProfile deviceProfile) {
61         return false;
62     }
63 
64     /**
65      * For this state, whether tasks should show the thumbnail splash.
66      */
showTaskThumbnailSplash()67     default boolean showTaskThumbnailSplash() {
68         return false;
69     }
70 
71     /**
72      * For this state, whether we should show desktop exploded view in Overview.
73      */
showExplodedDesktopView()74     default boolean showExplodedDesktopView() {
75         return false;
76     }
77 
78     /**
79      * For this state, whether fullscreen and desktop quickswitch carousel are detached.
80      */
detachDesktopCarousel()81     default boolean detachDesktopCarousel() {
82         return true;
83     }
84 
85     /**
86      * For this state, whether member variables and other forms of data state should be preserved
87      * or wiped when the state is reapplied. (See {@link StateManager#reapplyState()})
88      */
shouldPreserveDataStateOnReapply()89     default boolean shouldPreserveDataStateOnReapply() {
90         return false;
91     }
92 }
93