@@ -522,8 +522,7 @@ public long getCurrentPlayTime() {
522522 * animations possible.
523523 *
524524 */
525- private static class AnimationHandler extends Handler
526- implements Choreographer .OnAnimateListener {
525+ private static class AnimationHandler extends Handler implements Runnable {
527526 // The per-thread list of all active animations
528527 private final ArrayList <ValueAnimator > mAnimations = new ArrayList <ValueAnimator >();
529528
@@ -539,7 +538,7 @@ private static class AnimationHandler extends Handler
539538 private final ArrayList <ValueAnimator > mReadyAnims = new ArrayList <ValueAnimator >();
540539
541540 private final Choreographer mChoreographer ;
542- private boolean mIsChoreographed ;
541+ private boolean mAnimationScheduled ;
543542
544543 private AnimationHandler () {
545544 mChoreographer = Choreographer .getInstance ();
@@ -644,22 +643,17 @@ private void doAnimationFrame() {
644643
645644 // If there are still active or delayed animations, schedule a future call to
646645 // onAnimate to process the next frame of the animations.
647- if (!mAnimations .isEmpty () || !mDelayedAnims .isEmpty ()) {
648- if (!mIsChoreographed ) {
649- mIsChoreographed = true ;
650- mChoreographer .addOnAnimateListener (this );
651- }
652- mChoreographer .scheduleAnimation ();
653- } else {
654- if (mIsChoreographed ) {
655- mIsChoreographed = false ;
656- mChoreographer .removeOnAnimateListener (this );
657- }
646+ if (!mAnimationScheduled
647+ && (!mAnimations .isEmpty () || !mDelayedAnims .isEmpty ())) {
648+ mChoreographer .postAnimationCallback (this );
649+ mAnimationScheduled = true ;
658650 }
659651 }
660652
653+ // Called by the Choreographer.
661654 @ Override
662- public void onAnimate () {
655+ public void run () {
656+ mAnimationScheduled = false ;
663657 doAnimationFrame ();
664658 }
665659 }
0 commit comments