• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.uioverrides;
18 
19 import android.animation.ValueAnimator;
20 
21 import com.android.launcher3.Launcher;
22 import com.android.launcher3.LauncherState;
23 import com.android.launcher3.LauncherStateManager;
24 import com.android.launcher3.anim.AnimatorSetBuilder;
25 import com.android.quickstep.OverviewInteractionState;
26 
27 public class BackButtonAlphaHandler implements LauncherStateManager.StateHandler {
28 
29     private static final String TAG = "BackButtonAlphaHandler";
30 
31     private final Launcher mLauncher;
32     private final OverviewInteractionState mOverviewInteractionState;
33 
BackButtonAlphaHandler(Launcher launcher)34     public BackButtonAlphaHandler(Launcher launcher) {
35         mLauncher = launcher;
36         mOverviewInteractionState = OverviewInteractionState.getInstance(mLauncher);
37     }
38 
39     @Override
setState(LauncherState state)40     public void setState(LauncherState state) {
41         UiFactory.onLauncherStateOrFocusChanged(mLauncher);
42     }
43 
44     @Override
setStateWithAnimation(LauncherState toState, AnimatorSetBuilder builder, LauncherStateManager.AnimationConfig config)45     public void setStateWithAnimation(LauncherState toState,
46             AnimatorSetBuilder builder, LauncherStateManager.AnimationConfig config) {
47         if (!config.playNonAtomicComponent()) {
48             return;
49         }
50         float fromAlpha = mOverviewInteractionState.getBackButtonAlpha();
51         float toAlpha = toState.hideBackButton ? 0 : 1;
52         if (Float.compare(fromAlpha, toAlpha) != 0) {
53             ValueAnimator anim = ValueAnimator.ofFloat(fromAlpha, toAlpha);
54             anim.setDuration(config.duration);
55             anim.addUpdateListener(valueAnimator -> {
56                 final float alpha = (float) valueAnimator.getAnimatedValue();
57                 mOverviewInteractionState.setBackButtonAlpha(alpha, false);
58             });
59             builder.play(anim);
60         }
61     }
62 }
63