• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.taskbar;
17 
18 import static com.android.launcher3.LauncherState.TASKBAR;
19 import static com.android.launcher3.anim.Interpolators.ACCEL_DEACCEL;
20 import static com.android.launcher3.anim.Interpolators.LINEAR;
21 
22 import androidx.annotation.Nullable;
23 
24 import com.android.launcher3.BaseQuickstepLauncher;
25 import com.android.launcher3.LauncherState;
26 import com.android.launcher3.anim.PendingAnimation;
27 import com.android.launcher3.anim.PropertySetter;
28 import com.android.launcher3.statemanager.StateManager;
29 import com.android.launcher3.states.StateAnimationConfig;
30 import com.android.quickstep.AnimatedFloat;
31 
32 /**
33  * StateHandler to animate Taskbar according to Launcher's state machine. Does nothing if Taskbar
34  * isn't present (i.e. {@link #setAnimationController} is never called).
35  */
36 public class TaskbarStateHandler implements StateManager.StateHandler<LauncherState> {
37 
38     private final BaseQuickstepLauncher mLauncher;
39 
40     // Contains Taskbar-related methods and fields we should aniamte. If null, don't do anything.
41     private @Nullable TaskbarAnimationController mAnimationController = null;
42 
TaskbarStateHandler(BaseQuickstepLauncher launcher)43     public TaskbarStateHandler(BaseQuickstepLauncher launcher) {
44         mLauncher = launcher;
45     }
46 
setAnimationController(TaskbarAnimationController callbacks)47     public void setAnimationController(TaskbarAnimationController callbacks) {
48         mAnimationController = callbacks;
49     }
50 
51     @Override
setState(LauncherState state)52     public void setState(LauncherState state) {
53         setState(state, PropertySetter.NO_ANIM_PROPERTY_SETTER);
54     }
55 
56     @Override
setStateWithAnimation(LauncherState toState, StateAnimationConfig config, PendingAnimation animation)57     public void setStateWithAnimation(LauncherState toState, StateAnimationConfig config,
58             PendingAnimation animation) {
59         setState(toState, animation);
60     }
61 
setState(LauncherState toState, PropertySetter setter)62     private void setState(LauncherState toState, PropertySetter setter) {
63         if (mAnimationController == null) {
64             return;
65         }
66 
67         boolean isTaskbarVisible = (toState.getVisibleElements(mLauncher) & TASKBAR) != 0;
68         setter.setFloat(mAnimationController.getTaskbarVisibilityForLauncherState(),
69                 AnimatedFloat.VALUE, isTaskbarVisible ? 1f : 0f, LINEAR);
70         setter.setFloat(mAnimationController.getTaskbarScaleForLauncherState(),
71                 AnimatedFloat.VALUE, toState.getTaskbarScale(mLauncher), LINEAR);
72         setter.setFloat(mAnimationController.getTaskbarTranslationYForLauncherState(),
73                 AnimatedFloat.VALUE, toState.getTaskbarTranslationY(mLauncher), ACCEL_DEACCEL);
74     }
75 }
76