Fix bugs with quickstep springs.

* Listeners weren't getting called properly. We add one listener to the
SpringbjectAnimator and then use that to dispatch to the other listeners.

* We fast finish on both double swipe cases to prevent the shelf from
  ending in an invalid state. This causes a visual jump but this can be
  addressed in follow up CL.

Bug: 111698021
Change-Id: Ifeb55da9dd253d062122a8e1577f94044f688641
This commit is contained in:
Jon Miranda
2019-01-28 15:00:46 -08:00
parent e0c5f5d0ab
commit f82fd49244
3 changed files with 50 additions and 7 deletions

View File

@@ -80,6 +80,9 @@ public abstract class AnimatorPlaybackController implements ValueAnimator.Animat
private OnAnimationEndDispatcher mEndListener;
private DynamicAnimation.OnAnimationEndListener mSpringEndListener;
// We need this variable to ensure the end listener is called immediately, otherwise we run into
// issues where the callback interferes with the states of the swipe detector.
private boolean mSkipToEnd = false;
protected AnimatorPlaybackController(AnimatorSet anim, long duration,
Runnable onCancelRunnable) {
@@ -232,7 +235,11 @@ public abstract class AnimatorPlaybackController implements ValueAnimator.Animat
}
private void dispatchOnStartRecursively(Animator animator) {
for (AnimatorListener l : nonNullList(animator.getListeners())) {
List<AnimatorListener> listeners = animator instanceof SpringObjectAnimator
? nonNullList(((SpringObjectAnimator) animator).getSuperListeners())
: nonNullList(animator.getListeners());
for (AnimatorListener l : listeners) {
l.onAnimationStart(animator);
}
@@ -280,6 +287,17 @@ public abstract class AnimatorPlaybackController implements ValueAnimator.Animat
return mOnCancelRunnable;
}
public void skipToEnd() {
mSkipToEnd = true;
for (SpringAnimation spring : mSprings) {
if (spring.canSkipToEnd()) {
spring.skipToEnd();
}
}
mAnimationPlayer.end();
mSkipToEnd = false;
}
public static class AnimatorPlaybackControllerVL extends AnimatorPlaybackController {
private final ValueAnimator[] mChildAnimations;
@@ -343,19 +361,34 @@ public abstract class AnimatorPlaybackController implements ValueAnimator.Animat
*/
private class OnAnimationEndDispatcher extends AnimationSuccessListener {
boolean mAnimatorDone = false;
boolean mSpringsDone = false;
boolean mDispatched = false;
@Override
public void onAnimationStart(Animator animation) {
mCancelled = false;
mDispatched = false;
}
@Override
public void onAnimationSuccess(Animator animator) {
if (mSprings.isEmpty()) {
mSpringsDone = mAnimatorDone = true;
}
if (isAnySpringRunning()) {
mAnimatorDone = true;
} else {
mSpringsDone = true;
}
// We wait for the spring (if any) to finish running before completing the end callback.
if (mSprings.isEmpty() || !isAnySpringRunning()) {
if (!mDispatched && (mSkipToEnd || (mAnimatorDone && mSpringsDone))) {
dispatchOnEndRecursively(mAnim);
if (mEndAction != null) {
mEndAction.run();
}
mDispatched = true;
}
}