Merge "Use spring to update window/icon scale for swipe up animation." into ub-launcher3-qt-dev
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/util/RectFSpringAnim.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/util/RectFSpringAnim.java
index 3f4ad58..77dc6f3 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/util/RectFSpringAnim.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/util/RectFSpringAnim.java
@@ -16,26 +16,22 @@
package com.android.quickstep.util;
import android.animation.Animator;
-import android.animation.ObjectAnimator;
-import android.animation.PropertyValuesHolder;
-import android.animation.ValueAnimator;
import android.content.res.Resources;
import android.graphics.PointF;
import android.graphics.RectF;
-import android.util.FloatProperty;
import androidx.dynamicanimation.animation.DynamicAnimation.OnAnimationEndListener;
import androidx.dynamicanimation.animation.FloatPropertyCompat;
+import androidx.dynamicanimation.animation.SpringAnimation;
+import androidx.dynamicanimation.animation.SpringForce;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
-import com.android.launcher3.anim.AnimationSuccessListener;
import com.android.launcher3.anim.FlingSpringAnim;
import java.util.ArrayList;
import java.util.List;
-import static com.android.launcher3.anim.Interpolators.DEACCEL;
/**
* Applies spring forces to animate from a starting rect to a target rect,
@@ -43,14 +39,6 @@
*/
public class RectFSpringAnim {
- /**
- * Although the rect position animation takes an indefinite amount of time since it depends on
- * the initial velocity and applied forces, scaling from the starting rect to the target rect
- * can be done in parallel at a fixed duration. Update callbacks are sent based on the progress
- * of this animation, while the end callback is sent after all animations finish.
- */
- private static final long RECT_SCALE_DURATION = 250;
-
private static final FloatPropertyCompat<RectFSpringAnim> RECT_CENTER_X =
new FloatPropertyCompat<RectFSpringAnim>("rectCenterXSpring") {
@Override
@@ -79,17 +67,17 @@
}
};
- private static final FloatProperty<RectFSpringAnim> RECT_SCALE_PROGRESS =
- new FloatProperty<RectFSpringAnim>("rectScaleProgress") {
+ private static final FloatPropertyCompat<RectFSpringAnim> RECT_SCALE_PROGRESS =
+ new FloatPropertyCompat<RectFSpringAnim>("rectScaleProgress") {
@Override
- public Float get(RectFSpringAnim anim) {
- return anim.mCurrentScaleProgress;
+ public float getValue(RectFSpringAnim object) {
+ return object.mCurrentScaleProgress;
}
@Override
- public void setValue(RectFSpringAnim anim, float currentScaleProgress) {
- anim.mCurrentScaleProgress = currentScaleProgress;
- anim.onUpdate();
+ public void setValue(RectFSpringAnim object, float value) {
+ object.mCurrentScaleProgress = value;
+ object.onUpdate();
}
};
@@ -106,7 +94,7 @@
private float mCurrentScaleProgress;
private FlingSpringAnim mRectXAnim;
private FlingSpringAnim mRectYAnim;
- private ValueAnimator mRectScaleAnim;
+ private SpringAnimation mRectScaleAnim;
private boolean mAnimsStarted;
private boolean mRectXAnimEnded;
private boolean mRectYAnimEnded;
@@ -177,17 +165,18 @@
mRectYAnim = new FlingSpringAnim(this, RECT_Y, startY, endY, startVelocityY,
mMinVisChange, minYValue, maxYValue, springVelocityFactor, onYEndListener);
- mRectScaleAnim = ObjectAnimator.ofPropertyValuesHolder(this,
- PropertyValuesHolder.ofFloat(RECT_SCALE_PROGRESS, 1))
- .setDuration(RECT_SCALE_DURATION);
- mRectScaleAnim.setInterpolator(DEACCEL);
- mRectScaleAnim.addListener(new AnimationSuccessListener() {
- @Override
- public void onAnimationSuccess(Animator animator) {
- mRectScaleAnimEnded = true;
- maybeOnEnd();
- }
- });
+ float minVisibleChange = 1f / mStartRect.height();
+ mRectScaleAnim = new SpringAnimation(this, RECT_SCALE_PROGRESS)
+ .setSpring(new SpringForce(1f)
+ .setDampingRatio(SpringForce.DAMPING_RATIO_LOW_BOUNCY)
+ .setStiffness(SpringForce.STIFFNESS_LOW))
+ .setStartVelocity(velocityPxPerMs.y * minVisibleChange)
+ .setMaxValue(1f)
+ .setMinimumVisibleChange(minVisibleChange)
+ .addEndListener((animation, canceled, value, velocity) -> {
+ mRectScaleAnimEnded = true;
+ maybeOnEnd();
+ });
mRectXAnim.start();
mRectYAnim.start();
@@ -202,7 +191,9 @@
if (mAnimsStarted) {
mRectXAnim.end();
mRectYAnim.end();
- mRectScaleAnim.end();
+ if (mRectScaleAnim.canSkipToEnd()) {
+ mRectScaleAnim.skipToEnd();
+ }
}
}