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