1 /* 2 * Copyright (C) 2024 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 17 package com.android.launcher3.statemanager; 18 19 20 import static com.android.launcher3.LauncherState.FLAG_CLOSE_POPUPS; 21 import static com.android.launcher3.statemanager.BaseState.FLAG_NON_INTERACTIVE; 22 23 import androidx.annotation.CallSuper; 24 25 import com.android.launcher3.AbstractFloatingView; 26 import com.android.launcher3.views.ActivityContext; 27 28 import java.util.List; 29 30 /** 31 * Interface for a container that can be managed by a state manager. 32 * 33 * @param <STATE_TYPE> The type of state that the container can be in. 34 */ 35 public interface StatefulContainer<STATE_TYPE extends BaseState<STATE_TYPE>> extends 36 ActivityContext { 37 38 /** 39 * Creates a factory for atomic state animations 40 */ createAtomicAnimationFactory()41 default StateManager.AtomicAnimationFactory<STATE_TYPE> createAtomicAnimationFactory() { 42 return new StateManager.AtomicAnimationFactory<>(0); 43 } 44 45 /** 46 * Create handlers to control the property changes for this activity 47 */ collectStateHandlers(List<StateManager.StateHandler<STATE_TYPE>> out)48 void collectStateHandlers(List<StateManager.StateHandler<STATE_TYPE>> out); 49 50 /** 51 * Retrieves state manager for given container 52 */ getStateManager()53 StateManager<STATE_TYPE, ?> getStateManager(); 54 55 /** 56 * Called when transition to state ends 57 * @param state current state of State_Type 58 */ onStateSetEnd(STATE_TYPE state)59 default void onStateSetEnd(STATE_TYPE state) { } 60 61 /** 62 * Called when transition to state starts 63 * @param state current state of State_Type 64 */ 65 @CallSuper onStateSetStart(STATE_TYPE state)66 default void onStateSetStart(STATE_TYPE state) { 67 if (state.hasFlag(FLAG_CLOSE_POPUPS)) { 68 AbstractFloatingView.closeAllOpenViews(this, !state.hasFlag(FLAG_NON_INTERACTIVE)); 69 } 70 } 71 72 /** 73 * Returns true if the activity is in the provided state 74 * @param state current state of State_Type 75 */ isInState(STATE_TYPE state)76 default boolean isInState(STATE_TYPE state) { 77 return getStateManager().getState() == state; 78 } 79 80 /** 81 * Returns true if state change should transition with animation 82 */ shouldAnimateStateChange()83 boolean shouldAnimateStateChange(); 84 } 85