DO NOT MERGE Use spring-y progress in back to home animation.

Bug: 241788651
Test: m -j. Visual inspection.

Change-Id: If2b0218367680853ae4ee89c5ecff224ab9b6f04
This commit is contained in:
Shan Huang committed 2022-10-21 22:14:38 +00:00
1 parent b9b7c38d55
commit f31bf4e1e3
1 file changed
+31 -25
@@ -36,6 +36,7 @@ import android.view.SurfaceControl;
import android.view.animation.AnimationUtils; import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator; import android.view.animation.Interpolator;
import android.window.BackEvent; import android.window.BackEvent;
import android.window.BackProgressAnimator;
import android.window.IOnBackInvokedCallback; import android.window.IOnBackInvokedCallback;
import com.android.launcher3.AbstractFloatingView; import com.android.launcher3.AbstractFloatingView;
@@ -90,6 +91,7 @@ public class LauncherBackAnimationController {
private float mBackProgress = 0; private float mBackProgress = 0;
private boolean mBackInProgress = false; private boolean mBackInProgress = false;
private IOnBackInvokedCallback mBackCallback; private IOnBackInvokedCallback mBackCallback;
private BackProgressAnimator mProgressAnimator = new BackProgressAnimator();
public LauncherBackAnimationController( public LauncherBackAnimationController(
QuickstepLauncher launcher, QuickstepLauncher launcher,
@@ -118,30 +120,41 @@ public class LauncherBackAnimationController {
mBackCallback = new IOnBackInvokedCallback.Stub() { mBackCallback = new IOnBackInvokedCallback.Stub() {
@Override @Override
public void onBackCancelled() { public void onBackCancelled() {
handler.post(() -> resetPositionAnimated()); handler.post(() -> {
resetPositionAnimated();
mProgressAnimator.reset();
});
} }
@Override @Override
public void onBackInvoked() { public void onBackInvoked() {
handler.post(() -> startTransition()); handler.post(() -> {
startTransition();
mProgressAnimator.reset();
});
} }
@Override @Override
public void onBackProgressed(BackEvent backEvent) { public void onBackProgressed(BackEvent backEvent) {
mBackProgress = backEvent.getProgress(); handler.post(() -> {
// TODO: Update once the interpolation curve spec is finalized. mProgressAnimator.onBackProgressed(backEvent);
mBackProgress = });
1 - (1 - mBackProgress) * (1 - mBackProgress) * (1
- mBackProgress);
if (!mBackInProgress) {
startBack(backEvent);
} else {
updateBackProgress(mBackProgress, backEvent);
}
} }
@Override @Override
public void onBackStarted() { } public void onBackStarted(BackEvent backEvent) {
handler.post(() -> {
startBack(backEvent);
mProgressAnimator.onBackStarted(backEvent, event -> {
mBackProgress = event.getProgress();
// TODO: Update once the interpolation curve spec is finalized.
mBackProgress =
1 - (1 - mBackProgress) * (1 - mBackProgress) * (1
- mBackProgress);
updateBackProgress(mBackProgress, event);
});
});
}
}; };
SystemUiProxy.INSTANCE.get(mLauncher).setBackToLauncherCallback(mBackCallback); SystemUiProxy.INSTANCE.get(mLauncher).setBackToLauncherCallback(mBackCallback);
} }
@@ -169,6 +182,7 @@ public class LauncherBackAnimationController {
if (mBackCallback != null) { if (mBackCallback != null) {
SystemUiProxy.INSTANCE.get(mLauncher).clearBackToLauncherCallback(mBackCallback); SystemUiProxy.INSTANCE.get(mLauncher).clearBackToLauncherCallback(mBackCallback);
} }
mProgressAnimator.reset();
mBackCallback = null; mBackCallback = null;
} }
@@ -187,28 +201,20 @@ public class LauncherBackAnimationController {
// TODO(b/218916755): Offset start rectangle in multiwindow mode. // TODO(b/218916755): Offset start rectangle in multiwindow mode.
mStartRect.set(mBackTarget.windowConfiguration.getMaxBounds()); mStartRect.set(mBackTarget.windowConfiguration.getMaxBounds());
mCurrentRect.set(mStartRect);
} }
private void updateBackProgress(float progress, BackEvent event) { private void updateBackProgress(float progress, BackEvent event) {
if (mBackTarget == null) { if (!mBackInProgress || mBackTarget == null) {
return; return;
} }
float screenWidth = mStartRect.width(); float screenWidth = mStartRect.width();
float screenHeight = mStartRect.height(); float screenHeight = mStartRect.height();
float dX = Math.abs(event.getTouchX() - mInitialTouchPos.x); float width = Utilities.mapRange(progress, 1, MIN_WINDOW_SCALE) * screenWidth;
// The 'follow width' is the width of the window if it completely matches
// the gesture displacement.
float followWidth = screenWidth - dX;
// The 'progress width' is the width of the window if it strictly linearly interpolates
// to minimum scale base on progress.
float progressWidth = Utilities.mapRange(progress, 1, MIN_WINDOW_SCALE) * screenWidth;
// The final width is derived from interpolating between the follow with and progress width
// using gesture progress.
float width = Utilities.mapRange(progress, followWidth, progressWidth);
float height = screenHeight / screenWidth * width; float height = screenHeight / screenWidth * width;
float deltaYRatio = (event.getTouchY() - mInitialTouchPos.y) / screenHeight; float deltaYRatio = (event.getTouchY() - mInitialTouchPos.y) / screenHeight;
// Base the window movement in the Y axis on the touch movement in the Y axis. // Base the window movement in the Y axis on the touch movement in the Y axis.
float deltaY = (float) Math.sin(deltaYRatio * Math.PI * 0.5f) * mWindowMaxDeltaY; float deltaY = (float) Math.sin(deltaYRatio * Math.PI * 0.5f) * mWindowMaxDeltaY * progress;
// Move the window along the Y axis. // Move the window along the Y axis.
float top = (screenHeight - height) * 0.5f + deltaY; float top = (screenHeight - height) * 0.5f + deltaY;
// Move the window along the X axis. // Move the window along the X axis.