From c6ffab32415a58bbb010dcd115684f9dbc249710 Mon Sep 17 00:00:00 2001 From: Chet Haase Date: Fri, 16 Mar 2012 16:32:26 -0700 Subject: [PATCH] Reduce redundant animation processing Starting several animations will place separate events onto the animation queue, which may cause the active animations to get processed more than once in any frame when one of those start messages is processed. This change moves the logic of starting pending animations into the animation frame processing itself. Now when a start event is processed, it only calls the animation frame logic if there are unstarted animations pending. Issue #6172602 Inconsistent animation callbacks Change-Id: I3a546f0c849f42b2dd998f099fcdfafd7d780ad9 --- .../java/android/animation/ValueAnimator.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/core/java/android/animation/ValueAnimator.java b/core/java/android/animation/ValueAnimator.java index f69120a7934c3..e2b8ce4c05819 100755 --- a/core/java/android/animation/ValueAnimator.java +++ b/core/java/android/animation/ValueAnimator.java @@ -557,12 +557,22 @@ public class ValueAnimator extends Animator { public void handleMessage(Message msg) { switch (msg.what) { case ANIMATION_START: - doAnimationStart(); + // If there are already active animations, or if another ANIMATION_START + // message was processed during this frame, then the pending list may already + // have been cleared. If that's the case, we've already processed the + // active animations for this frame - don't do it again. + if (mPendingAnimations.size() > 0) { + doAnimationFrame(); + } break; } } - private void doAnimationStart() { + private void doAnimationFrame() { + // currentTime holds the common time for all animations processed + // during this frame + long currentTime = AnimationUtils.currentAnimationTimeMillis(); + // mPendingAnimations holds any animations that have requested to be started // We're going to clear mPendingAnimations, but starting animation may // cause more to be added to the pending list (for example, if one animation @@ -583,15 +593,7 @@ public class ValueAnimator extends Animator { } } } - doAnimationFrame(); - } - - private void doAnimationFrame() { - // currentTime holds the common time for all animations processed - // during this frame - long currentTime = AnimationUtils.currentAnimationTimeMillis(); - - // First, process animations currently sitting on the delayed queue, adding + // Next, process animations currently sitting on the delayed queue, adding // them to the active animations if they are ready int numDelayedAnims = mDelayedAnims.size(); for (int i = 0; i < numDelayedAnims; ++i) {