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
This commit is contained in:
Chet Haase
2012-03-16 16:32:26 -07:00
parent 55ba267c09
commit c6ffab3241

View File

@@ -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) {