Animate taskbar background alpha and visibility alpha

Setup codepath to animate the Taskbar when going to and from Launcher,
primarily by listening for pause/resume signals but also hints from
gesture nav and AppToOverviewAnimationProvider.

Additionally, add TaskbarStateHandler to listen for Launcher state
changes if Taskbar is enabled. Combined, the end behavior is:

- Background alpha is 0 when Launcher is resumed, and 1 when Launcher
  is paused (we can make this animation more interesting later).
- Taskbar is always visible when Launcher is paused, otherwise its
  visibility is determined by multiple factors: LauncherState and
  whether the IME is showing.

Bug: 171917176
Change-Id: I7856fc979931c9d12d714dee11d179fd1b5a6968
This commit is contained in:
Tony Wickham
2020-12-23 16:12:18 -06:00
parent d462965698
commit d683d98b34
18 changed files with 392 additions and 11 deletions

View File

@@ -22,13 +22,22 @@ import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
import static com.android.systemui.shared.system.WindowManagerWrapper.ITYPE_BOTTOM_TAPPABLE_ELEMENT;
import static com.android.systemui.shared.system.WindowManagerWrapper.ITYPE_EXTRA_NAVIGATION_BAR;
import android.animation.Animator;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.view.Gravity;
import android.view.WindowManager;
import androidx.annotation.Nullable;
import com.android.launcher3.BaseQuickstepLauncher;
import com.android.launcher3.LauncherState;
import com.android.launcher3.QuickstepAppTransitionManagerImpl;
import com.android.launcher3.R;
import com.android.launcher3.anim.AlphaUpdateListener;
import com.android.launcher3.anim.PendingAnimation;
import com.android.launcher3.states.StateAnimationConfig;
import com.android.quickstep.AnimatedFloat;
import com.android.systemui.shared.system.WindowManagerWrapper;
/**
@@ -44,7 +53,10 @@ public class TaskbarController {
private final WindowManager mWindowManager;
// Layout width and height of the Taskbar in the default state.
private final Point mTaskbarSize;
private final TaskbarStateHandler mTaskbarStateHandler;
private final TaskbarVisibilityController mTaskbarVisibilityController;
// Initialized in init().
private WindowManager.LayoutParams mWindowLayoutParams;
public TaskbarController(BaseQuickstepLauncher launcher,
@@ -55,6 +67,24 @@ public class TaskbarController {
mWindowManager = mLauncher.getWindowManager();
mTaskbarSize = new Point(MATCH_PARENT,
mLauncher.getResources().getDimensionPixelSize(R.dimen.taskbar_size));
mTaskbarStateHandler = mLauncher.getTaskbarStateHandler();
mTaskbarVisibilityController = new TaskbarVisibilityController(mLauncher,
createTaskbarVisibilityControllerCallbacks());
}
private TaskbarVisibilityControllerCallbacks createTaskbarVisibilityControllerCallbacks() {
return new TaskbarVisibilityControllerCallbacks() {
@Override
public void updateTaskbarBackgroundAlpha(float alpha) {
mTaskbarView.setBackgroundAlpha(alpha);
}
@Override
public void updateTaskbarVisibilityAlpha(float alpha) {
mTaskbarContainerView.setAlpha(alpha);
AlphaUpdateListener.updateVisibility(mTaskbarContainerView);
}
};
}
/**
@@ -62,6 +92,17 @@ public class TaskbarController {
*/
public void init() {
addToWindowManager();
mTaskbarStateHandler.setTaskbarCallbacks(createTaskbarStateHandlerCallbacks());
mTaskbarVisibilityController.init();
}
private TaskbarStateHandlerCallbacks createTaskbarStateHandlerCallbacks() {
return new TaskbarStateHandlerCallbacks() {
@Override
public AnimatedFloat getAlphaTarget() {
return mTaskbarVisibilityController.getTaskbarVisibilityForLauncherState();
}
};
}
/**
@@ -69,6 +110,8 @@ public class TaskbarController {
*/
public void cleanup() {
removeFromWindowManager();
mTaskbarStateHandler.setTaskbarCallbacks(null);
mTaskbarVisibilityController.cleanup();
}
private void removeFromWindowManager() {
@@ -108,4 +151,58 @@ public class TaskbarController {
mWindowManager.addView(mTaskbarContainerView, mWindowLayoutParams);
}
/**
* Should be called from onResume() and onPause(), and animates the Taskbar accordingly.
*/
public void onLauncherResumedOrPaused(boolean isResumed) {
long duration = QuickstepAppTransitionManagerImpl.CONTENT_ALPHA_DURATION;
final Animator anim;
if (isResumed) {
anim = createAnimToLauncher(null, duration);
} else {
anim = createAnimToApp(duration);
}
anim.start();
}
/**
* Create Taskbar animation when going from an app to Launcher.
* @param toState If known, the state we will end up in when reaching Launcher.
*/
public Animator createAnimToLauncher(@Nullable LauncherState toState, long duration) {
PendingAnimation anim = new PendingAnimation(duration);
anim.add(mTaskbarVisibilityController.createAnimToBackgroundAlpha(0, duration));
if (toState != null) {
mTaskbarStateHandler.setStateWithAnimation(toState, new StateAnimationConfig(), anim);
}
return anim.buildAnim();
}
private Animator createAnimToApp(long duration) {
return mTaskbarVisibilityController.createAnimToBackgroundAlpha(1, duration);
}
/**
* Should be called when the IME visibility changes, so we can hide/show Taskbar accordingly.
*/
public void setIsImeVisible(boolean isImeVisible) {
mTaskbarVisibilityController.animateToVisibilityForIme(isImeVisible ? 0 : 1);
}
/**
* Contains methods that TaskbarStateHandler can call to interface with TaskbarController.
*/
protected interface TaskbarStateHandlerCallbacks {
AnimatedFloat getAlphaTarget();
}
/**
* Contains methods that TaskbarVisibilityController can call to interface with
* TaskbarController.
*/
protected interface TaskbarVisibilityControllerCallbacks {
void updateTaskbarBackgroundAlpha(float alpha);
void updateTaskbarVisibilityAlpha(float alpha);
}
}