Merge "Skip fling anim if it is a no-op, to save a frame of aniamtion" into ub-launcher3-rvc-dev

This commit is contained in:
Tony Wickham
2020-06-12 21:10:29 +00:00
committed by Android (Google) Code Review
@@ -35,6 +35,7 @@ public class FlingSpringAnim {
private final FlingAnimation mFlingAnim;
private SpringAnimation mSpringAnim;
private final boolean mSkipFlingAnim;
private float mTargetPosition;
@@ -57,6 +58,10 @@ public class FlingSpringAnim {
.setMaxValue(maxValue);
mTargetPosition = targetPosition;
// We are already past the fling target, so skip it to avoid losing a frame of the spring.
mSkipFlingAnim = startPosition <= minValue && startVelocity < 0
|| startPosition >= maxValue && startVelocity > 0;
mFlingAnim.addEndListener(((animation, canceled, value, velocity) -> {
mSpringAnim = new SpringAnimation(object, property)
.setStartValue(value)
@@ -84,6 +89,9 @@ public class FlingSpringAnim {
public void start() {
mFlingAnim.start();
if (mSkipFlingAnim) {
mFlingAnim.cancel();
}
}
public void end() {