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