• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.taskbar;
18 
19 import android.view.View;
20 
21 import com.android.launcher3.R;
22 import com.android.launcher3.taskbar.navbutton.NearestTouchFrame;
23 import com.android.systemui.shared.statusbar.phone.BarTransitions;
24 
25 import java.io.PrintWriter;
26 
27 /** Manages task bar transitions */
28 public class TaskbarTransitions extends BarTransitions implements
29         TaskbarControllers.LoggableTaskbarController {
30 
31     private final TaskbarActivityContext mContext;
32 
33     private boolean mWallpaperVisible;
34 
35     private boolean mLightsOut;
36     private boolean mAutoDim;
37     private View mNavButtons;
38     private float mDarkIntensity;
39 
40     private final NearestTouchFrame mView;
41 
TaskbarTransitions(TaskbarActivityContext context, NearestTouchFrame view)42     public TaskbarTransitions(TaskbarActivityContext context, NearestTouchFrame view) {
43         super(view, R.drawable.nav_background);
44 
45         mContext = context;
46         mView = view;
47     }
48 
init()49     void init() {
50         mView.addOnLayoutChangeListener(
51                 (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
52                     mNavButtons = mView.findViewById(R.id.end_nav_buttons);
53                     applyLightsOut(false, true);
54                 });
55         mNavButtons = mView.findViewById(R.id.end_nav_buttons);
56 
57         applyModeBackground(-1, getMode(), false /*animate*/);
58         applyLightsOut(false /*animate*/, true /*force*/);
59         if (mContext.isPhoneButtonNavMode()) {
60             mBarBackground.setOverrideAlpha(1);
61         }
62     }
63 
setWallpaperVisibility(boolean visible)64     void setWallpaperVisibility(boolean visible) {
65         mWallpaperVisible = visible;
66         applyLightsOut(true, false);
67     }
68 
69     @Override
setAutoDim(boolean autoDim)70     public void setAutoDim(boolean autoDim) {
71         // Ensure we aren't in gestural nav if we are triggering auto dim
72         if (autoDim && !mContext.isPhoneButtonNavMode()) {
73             return;
74         }
75         if (mAutoDim == autoDim) return;
76         mAutoDim = autoDim;
77         applyLightsOut(true, false);
78     }
79 
80     @Override
onTransition(int oldMode, int newMode, boolean animate)81     protected void onTransition(int oldMode, int newMode, boolean animate) {
82         super.onTransition(oldMode, newMode, animate);
83         applyLightsOut(animate, false /*force*/);
84     }
85 
applyLightsOut(boolean animate, boolean force)86     private void applyLightsOut(boolean animate, boolean force) {
87         // apply to lights out
88         applyLightsOut(isLightsOut(getMode()), animate, force);
89     }
90 
applyLightsOut(boolean lightsOut, boolean animate, boolean force)91     private void applyLightsOut(boolean lightsOut, boolean animate, boolean force) {
92         if (!force && lightsOut == mLightsOut) return;
93 
94         mLightsOut = lightsOut;
95         if (mNavButtons == null) return;
96 
97         // ok, everyone, stop it right there
98         mNavButtons.animate().cancel();
99 
100         // Bump percentage by 10% if dark.
101         float darkBump = mDarkIntensity / 10;
102         final float navButtonsAlpha = lightsOut ? 0.6f + darkBump : 1f;
103 
104         if (!animate) {
105             mNavButtons.setAlpha(navButtonsAlpha);
106         } else {
107             final int duration = lightsOut ? LIGHTS_OUT_DURATION : LIGHTS_IN_DURATION;
108             mNavButtons.animate()
109                     .alpha(navButtonsAlpha)
110                     .setDuration(duration)
111                     .start();
112         }
113     }
114 
onDarkIntensityChanged(float darkIntensity)115     void onDarkIntensityChanged(float darkIntensity) {
116         mDarkIntensity = darkIntensity;
117         if (mAutoDim) {
118             applyLightsOut(false, true);
119         }
120     }
121 
122     @Override
dumpLogs(String prefix, PrintWriter pw)123     public void dumpLogs(String prefix, PrintWriter pw) {
124         pw.println(prefix + "TaskbarTransitions:");
125 
126         pw.println(prefix + "\tmMode=" + getMode());
127         pw.println(prefix + "\tmAlwaysOpaque: " + isAlwaysOpaque());
128         pw.println(prefix + "\tmWallpaperVisible: " + mWallpaperVisible);
129         pw.println(prefix + "\tmLightsOut: " + mLightsOut);
130         pw.println(prefix + "\tmAutoDim: " + mAutoDim);
131         pw.println(prefix + "\tbg overrideAlpha: " + mBarBackground.getOverrideAlpha());
132         pw.println(prefix + "\tbg color: " + mBarBackground.getColor());
133         pw.println(prefix + "\tbg frame: " + mBarBackground.getFrame());
134     }
135 }
136