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 22 /** 23 * Interface representing a state of a StatefulActivity 24 */ 25 public interface BaseState<T extends BaseState> { 26 27 // Flag to indicate that Launcher is non-interactive in this state 28 int FLAG_NON_INTERACTIVE = 1 << 0; 29 int FLAG_DISABLE_RESTORE = 1 << 1; 30 getFlag(int index)31 static int getFlag(int index) { 32 // reserve few spots to base flags 33 return 1 << (index + 2); 34 } 35 36 /** 37 * @return How long the animation to this state should take (or from this state to NORMAL). 38 */ getTransitionDuration(Context context)39 int getTransitionDuration(Context context); 40 41 /** 42 * Returns the state to go back to from this state 43 */ getHistoryForState(T previousState)44 T getHistoryForState(T previousState); 45 46 /** 47 * @return true if the state can be persisted across activity restarts. 48 */ shouldDisableRestore()49 default boolean shouldDisableRestore() { 50 return hasFlag(FLAG_DISABLE_RESTORE); 51 } 52 53 /** 54 * Returns if the state has the provided flag 55 */ hasFlag(int flagMask)56 boolean hasFlag(int flagMask); 57 58 /** 59 * For this state, whether tasks should layout as a grid rather than a list. 60 */ displayOverviewTasksAsGrid(DeviceProfile deviceProfile)61 default boolean displayOverviewTasksAsGrid(DeviceProfile deviceProfile) { 62 return false; 63 } 64 } 65