Merge "Add spring animation when stashing transient taskbar." into tm-qpr-dev am: ba85154590

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/22178236

Change-Id: I87a3e770928564eb02ddd0802814ac1f896d78bb
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Jon Miranda
2023-03-22 03:09:40 +00:00
committed by Automerger Merge Worker
11 changed files with 156 additions and 3 deletions

View File

@@ -300,6 +300,8 @@
<dimen name="transient_taskbar_key_shadow_distance">10dp</dimen>
<dimen name="transient_taskbar_stashed_size">32dp</dimen>
<dimen name="transient_taskbar_all_apps_button_translation_x_offset">4dp</dimen>
<dimen name="transient_taskbar_stash_spring_velocity_dp_per_s">400dp</dimen>
<!-- An additional touch slop to prevent x-axis movement during the swipe up to show taskbar -->
<dimen name="transient_taskbar_clamped_offset_bound">16dp</dimen>
<!-- Taskbar swipe up thresholds -->

View File

@@ -84,6 +84,9 @@ public class StashedHandleViewController implements TaskbarControllers.LoggableT
private boolean mIsStashed;
private boolean mTaskbarHidden;
private float mTranslationYForSwipe;
private float mTranslationYForStash;
public StashedHandleViewController(TaskbarActivityContext activity,
StashedHandleView stashedHandleView) {
mActivity = activity;
@@ -254,7 +257,20 @@ public class StashedHandleViewController implements TaskbarControllers.LoggableT
* Sets the translation of the stashed handle during the swipe up gesture.
*/
protected void setTranslationYForSwipe(float transY) {
mStashedHandleView.setTranslationY(transY);
mTranslationYForSwipe = transY;
updateTranslationY();
}
/**
* Sets the translation of the stashed handle during the spring on stash animation.
*/
protected void setTranslationYForStash(float transY) {
mTranslationYForStash = transY;
updateTranslationY();
}
private void updateTranslationY() {
mStashedHandleView.setTranslationY(mTranslationYForSwipe + mTranslationYForStash);
}
/**

View File

@@ -233,6 +233,7 @@ public class TaskbarActivityContext extends BaseTaskbarContext {
new TaskbarInsetsController(this),
new VoiceInteractionWindowController(this),
new TaskbarTranslationController(this),
new TaskbarSpringOnStashController(this),
isDesktopMode
? new DesktopTaskbarRecentAppsController(this)
: TaskbarRecentAppsController.DEFAULT,

View File

@@ -35,6 +35,7 @@ class TaskbarBackgroundRenderer(context: TaskbarActivityContext) {
val lastDrawnTransientRect = RectF()
var backgroundHeight = context.deviceProfile.taskbarSize.toFloat()
var translationYForSwipe = 0f
var translationYForStash = 0f
private var maxBackgroundHeight = context.deviceProfile.taskbarSize.toFloat()
private val transientBackgroundBounds = context.transientTaskbarBounds
@@ -136,7 +137,9 @@ class TaskbarBackgroundRenderer(context: TaskbarActivityContext) {
val bottom =
canvas.height - bottomMargin +
bottomMarginProgress +
(-mapRange(1f - progress, 0f, stashedHandleHeight / 2f) + translationYForSwipe)
translationYForSwipe +
translationYForStash +
-mapRange(1f - progress, 0f, stashedHandleHeight / 2f)
// Draw shadow.
val shadowAlpha =

View File

@@ -57,6 +57,7 @@ public class TaskbarControllers {
public final VoiceInteractionWindowController voiceInteractionWindowController;
public final TaskbarRecentAppsController taskbarRecentAppsController;
public final TaskbarTranslationController taskbarTranslationController;
public final TaskbarSpringOnStashController taskbarSpringOnStashController;
public final TaskbarOverlayController taskbarOverlayController;
public final TaskbarEduTooltipController taskbarEduTooltipController;
public final KeyboardQuickSwitchController keyboardQuickSwitchController;
@@ -103,6 +104,7 @@ public class TaskbarControllers {
TaskbarInsetsController taskbarInsetsController,
VoiceInteractionWindowController voiceInteractionWindowController,
TaskbarTranslationController taskbarTranslationController,
TaskbarSpringOnStashController taskbarSpringOnStashController,
TaskbarRecentAppsController taskbarRecentAppsController,
TaskbarEduTooltipController taskbarEduTooltipController,
KeyboardQuickSwitchController keyboardQuickSwitchController) {
@@ -127,6 +129,7 @@ public class TaskbarControllers {
this.taskbarInsetsController = taskbarInsetsController;
this.voiceInteractionWindowController = voiceInteractionWindowController;
this.taskbarTranslationController = taskbarTranslationController;
this.taskbarSpringOnStashController = taskbarSpringOnStashController;
this.taskbarRecentAppsController = taskbarRecentAppsController;
this.taskbarEduTooltipController = taskbarEduTooltipController;
this.keyboardQuickSwitchController = keyboardQuickSwitchController;
@@ -149,6 +152,7 @@ public class TaskbarControllers {
taskbarScrimViewController.init(this);
taskbarUnfoldAnimationController.init(this);
taskbarKeyguardController.init(navbarButtonsViewController);
taskbarSpringOnStashController.init(this);
stashedHandleViewController.init(this);
taskbarStashController.init(this, sharedState.setupUIVisible);
taskbarEduController.init(this);

View File

@@ -184,6 +184,14 @@ public class TaskbarDragLayer extends BaseDragLayer<TaskbarActivityContext> {
invalidate();
}
/*
* Sets the translation of the background during the spring on stash animation.
*/
protected void setBackgroundTranslationYForStash(float translationY) {
mBackgroundRenderer.setTranslationYForStash(translationY);
invalidate();
}
/** Returns the bounds in DragLayer coordinates of where the transient background was drawn. */
protected RectF getLastDrawnTransientRect() {
return mBackgroundRenderer.getLastDrawnTransientRect();

View File

@@ -161,6 +161,13 @@ public class TaskbarDragLayerController implements TaskbarControllers.LoggableTa
mTaskbarDragLayer.setBackgroundTranslationYForSwipe(transY);
}
/**
* Sets the translation of the background during the spring on stash animation.
*/
public void setTranslationYForStash(float transY) {
mTaskbarDragLayer.setBackgroundTranslationYForStash(transY);
}
private void updateBackgroundOffset() {
mTaskbarDragLayer.setTaskbarBackgroundOffset(mBgOffset.value);

View File

@@ -0,0 +1,97 @@
/*
* Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.launcher3.taskbar;
import static com.android.launcher3.anim.AnimatedFloat.VALUE;
import android.animation.ValueAnimator;
import androidx.annotation.Nullable;
import androidx.dynamicanimation.animation.SpringForce;
import com.android.launcher3.R;
import com.android.launcher3.anim.AnimatedFloat;
import com.android.launcher3.anim.SpringAnimationBuilder;
import com.android.launcher3.taskbar.TaskbarControllers.LoggableTaskbarController;
import com.android.launcher3.util.DisplayController;
import java.io.PrintWriter;
/**
* Manages the spring animation when stashing the transient taskbar.
*/
public class TaskbarSpringOnStashController implements LoggableTaskbarController {
private final TaskbarActivityContext mContext;
private TaskbarControllers mControllers;
private final AnimatedFloat mTranslationForStash = new AnimatedFloat(
this::updateTranslationYForStash);
private final boolean mIsTransientTaskbar;
private final float mStartVelocityPxPerS;
public TaskbarSpringOnStashController(TaskbarActivityContext context) {
mContext = context;
mIsTransientTaskbar = DisplayController.isTransientTaskbar(mContext);
mStartVelocityPxPerS = context.getResources()
.getDimension(R.dimen.transient_taskbar_stash_spring_velocity_dp_per_s);
}
/**
* Initialization method.
*/
public void init(TaskbarControllers controllers) {
mControllers = controllers;
}
private void updateTranslationYForStash() {
if (!mIsTransientTaskbar) {
return;
}
float transY = mTranslationForStash.value;
mControllers.stashedHandleViewController.setTranslationYForStash(transY);
mControllers.taskbarViewController.setTranslationYForStash(transY);
mControllers.taskbarDragLayerController.setTranslationYForStash(transY);
}
/**
* Returns a spring animation to be used when stashing the transient taskbar.
*/
public @Nullable ValueAnimator createSpringToStash() {
if (!mIsTransientTaskbar) {
return null;
}
return new SpringAnimationBuilder(mContext)
.setStartValue(mTranslationForStash.value)
.setEndValue(0)
.setDampingRatio(SpringForce.DAMPING_RATIO_MEDIUM_BOUNCY)
.setStiffness(SpringForce.STIFFNESS_LOW)
.setStartVelocity(mStartVelocityPxPerS)
.build(mTranslationForStash, VALUE);
}
@Override
public void dumpLogs(String prefix, PrintWriter pw) {
pw.println(prefix + "TaskbarSpringOnStashController:");
pw.println(prefix + "\tmTranslationForStash=" + mTranslationForStash.value);
pw.println(prefix + "\tmStartVelocityPxPerS=" + mStartVelocityPxPerS);
}
}

View File

@@ -712,6 +712,9 @@ public class TaskbarStashController implements TaskbarControllers.LoggableTaskba
play(as, mTaskbarStashedHandleAlpha.animateToValue(1), alphaStartDelay,
Math.max(0, duration - alphaStartDelay), LINEAR);
play(as, mControllers.taskbarSpringOnStashController.createSpringToStash(), 0, duration,
LINEAR);
if (skipStashAnimation) {
skipInterpolator = INSTANT;
}

View File

@@ -103,6 +103,7 @@ public class TaskbarViewController implements TaskbarControllers.LoggableTaskbar
private AnimatedFloat mTaskbarNavButtonTranslationY;
private AnimatedFloat mTaskbarNavButtonTranslationYForInAppDisplay;
private float mTaskbarIconTranslationYForSwipe;
private float mTaskbarIconTranslationYForSpringOnStash;
private final int mTaskbarBottomMargin;
private final int mStashedHandleHeight;
@@ -291,10 +292,19 @@ public class TaskbarViewController implements TaskbarControllers.LoggableTaskbar
updateTranslationY();
}
/**
* Sets the translation of the TaskbarView during the spring on stash animation.
*/
public void setTranslationYForStash(float transY) {
mTaskbarIconTranslationYForSpringOnStash = transY;
updateTranslationY();
}
private void updateTranslationY() {
mTaskbarView.setTranslationY(mTaskbarIconTranslationYForHome.value
+ mTaskbarIconTranslationYForStash.value
+ mTaskbarIconTranslationYForSwipe);
+ mTaskbarIconTranslationYForSwipe
+ mTaskbarIconTranslationYForSpringOnStash);
}
/**

View File

@@ -50,6 +50,7 @@ abstract class TaskbarBaseTestCase {
@Mock lateinit var voiceInteractionWindowController: VoiceInteractionWindowController
@Mock lateinit var taskbarRecentAppsController: TaskbarRecentAppsController
@Mock lateinit var taskbarTranslationController: TaskbarTranslationController
@Mock lateinit var taskbarSpringOnStashController: TaskbarSpringOnStashController
@Mock lateinit var taskbarOverlayController: TaskbarOverlayController
@Mock lateinit var taskbarEduTooltipController: TaskbarEduTooltipController
@Mock lateinit var keyboardQuickSwitchController: KeyboardQuickSwitchController
@@ -89,6 +90,7 @@ abstract class TaskbarBaseTestCase {
taskbarInsetsController,
voiceInteractionWindowController,
taskbarTranslationController,
taskbarSpringOnStashController,
taskbarRecentAppsController,
taskbarEduTooltipController,
keyboardQuickSwitchController