• 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.Animator;
20 import android.animation.AnimatorListenerAdapter;
21 import android.animation.ValueAnimator;
22 
23 import com.android.launcher3.Launcher;
24 import com.android.launcher3.LauncherState;
25 import com.android.launcher3.LauncherStateManager;
26 import com.android.launcher3.anim.AnimatorSetBuilder;
27 import com.android.quickstep.OverviewInteractionState;
28 
29 public class BackButtonAlphaHandler implements LauncherStateManager.StateHandler {
30 
31     private static final String TAG = "BackButtonAlphaHandler";
32 
33     private final Launcher mLauncher;
34     private final OverviewInteractionState mOverviewInteractionState;
35 
BackButtonAlphaHandler(Launcher launcher)36     public BackButtonAlphaHandler(Launcher launcher) {
37         mLauncher = launcher;
38         mOverviewInteractionState = OverviewInteractionState.INSTANCE.get(mLauncher);
39     }
40 
41     @Override
setState(LauncherState state)42     public void setState(LauncherState state) {
43         UiFactory.onLauncherStateOrFocusChanged(mLauncher);
44     }
45 
46     @Override
setStateWithAnimation(LauncherState toState, AnimatorSetBuilder builder, LauncherStateManager.AnimationConfig config)47     public void setStateWithAnimation(LauncherState toState,
48             AnimatorSetBuilder builder, LauncherStateManager.AnimationConfig config) {
49         if (!config.playNonAtomicComponent()) {
50             return;
51         }
52         float fromAlpha = mOverviewInteractionState.getBackButtonAlpha();
53         float toAlpha = toState.hideBackButton ? 0 : 1;
54         if (Float.compare(fromAlpha, toAlpha) != 0) {
55             ValueAnimator anim = ValueAnimator.ofFloat(fromAlpha, toAlpha);
56             anim.setDuration(config.duration);
57             anim.addUpdateListener(valueAnimator -> {
58                 final float alpha = (float) valueAnimator.getAnimatedValue();
59                 mOverviewInteractionState.setBackButtonAlpha(alpha, false);
60             });
61             anim.addListener(new AnimatorListenerAdapter() {
62                 @Override
63                 public void onAnimationEnd(Animator animation) {
64                     // Reapply the final alpha in case some state (e.g. window focus) changed.
65                     UiFactory.onLauncherStateOrFocusChanged(mLauncher);
66                 }
67             });
68             builder.play(anim);
69         }
70     }
71 }
72