diff options
author | Chet Haase <chet@google.com> | 2012-04-17 13:18:14 -0700 |
---|---|---|
committer | Chet Haase <chet@google.com> | 2012-04-17 13:58:44 -0700 |
commit | 17cf42cb85c22b50ecfa8d21efc992f99d20fc45 (patch) | |
tree | d8ba7cef26d25a01aeab9adee69cf731cc367421 /core/java/android/animation | |
parent | df1423e28ccb867c323c7b821bb2af1b6481ac07 (diff) | |
download | frameworks_base-17cf42cb85c22b50ecfa8d21efc992f99d20fc45.zip frameworks_base-17cf42cb85c22b50ecfa8d21efc992f99d20fc45.tar.gz frameworks_base-17cf42cb85c22b50ecfa8d21efc992f99d20fc45.tar.bz2 |
Fix logic of animator start/cancel/end callbacks
The callbacks for animators in some corner cases were not being
called correctly. For example, startDelayed animators that were
started and then ended didn't send out the proper events.
This CL fixes that logic. Specifically:
- An animator that is end()'d will implicitly start() itself and then
assign an end value. This was already the case, but listeners were not
getting notified. Now this situation causes callbacks to listeners for
both the start and end events.
- startDelayed animators that are end()'d or cancel()'d prior to finishing
the startDelay phase will send out events (start and cancel/end, as appropriate)
to listeners.
Change-Id: I40a0f2fdb19d9ec7c3726a91363686c6ecb7d915
Diffstat (limited to 'core/java/android/animation')
-rw-r--r-- | core/java/android/animation/LayoutTransition.java | 2 | ||||
-rwxr-xr-x | core/java/android/animation/ValueAnimator.java | 50 |
2 files changed, 35 insertions, 17 deletions
diff --git a/core/java/android/animation/LayoutTransition.java b/core/java/android/animation/LayoutTransition.java index 871bb2c..c643137 100644 --- a/core/java/android/animation/LayoutTransition.java +++ b/core/java/android/animation/LayoutTransition.java @@ -1005,6 +1005,8 @@ public class LayoutTransition { anim.start(); anim.end(); } + // listeners should clean up the currentChangingAnimations list, but just in case... + currentChangingAnimations.clear(); } /** diff --git a/core/java/android/animation/ValueAnimator.java b/core/java/android/animation/ValueAnimator.java index fade20c..2154b14 100755 --- a/core/java/android/animation/ValueAnimator.java +++ b/core/java/android/animation/ValueAnimator.java @@ -150,6 +150,13 @@ public class ValueAnimator extends Animator { private boolean mStarted = false; /** + * Tracks whether we've notified listeners of the onAnimationSTart() event. This can be + * complex to keep track of since we notify listeners at different times depending on + * startDelay and whether start() was called before end(). + */ + private boolean mStartListenersCalled = false; + + /** * Flag that denotes whether the animation is set up and ready to go. Used to * set up animation that has not yet been started. */ @@ -885,6 +892,18 @@ public class ValueAnimator extends Animator { } } + private void notifyStartListeners() { + if (mListeners != null && !mStartListenersCalled) { + ArrayList<AnimatorListener> tmpListeners = + (ArrayList<AnimatorListener>) mListeners.clone(); + int numListeners = tmpListeners.size(); + for (int i = 0; i < numListeners; ++i) { + tmpListeners.get(i).onAnimationStart(this); + } + } + mStartListenersCalled = true; + } + /** * Start the animation playing. This version of start() takes a boolean flag that indicates * whether the animation should play in reverse. The flag is usually false, but may be set @@ -914,15 +933,7 @@ public class ValueAnimator extends Animator { setCurrentPlayTime(getCurrentPlayTime()); mPlayingState = STOPPED; mRunning = true; - - if (mListeners != null) { - ArrayList<AnimatorListener> tmpListeners = - (ArrayList<AnimatorListener>) mListeners.clone(); - int numListeners = tmpListeners.size(); - for (int i = 0; i < numListeners; ++i) { - tmpListeners.get(i).onAnimationStart(this); - } - } + notifyStartListeners(); } animationHandler.sendEmptyMessage(ANIMATION_START); } @@ -941,7 +952,11 @@ public class ValueAnimator extends Animator { || handler.mPendingAnimations.contains(this) || handler.mDelayedAnims.contains(this)) { // Only notify listeners if the animator has actually started - if (mRunning && mListeners != null) { + if ((mStarted || mRunning) && mListeners != null) { + if (!mRunning) { + // If it's not yet running, then start listeners weren't called. Call them now. + notifyStartListeners(); + } ArrayList<AnimatorListener> tmpListeners = (ArrayList<AnimatorListener>) mListeners.clone(); for (AnimatorListener listener : tmpListeners) { @@ -959,6 +974,7 @@ public class ValueAnimator extends Animator { // Special case if the animation has not yet started; get it ready for ending mStartedDelay = false; startAnimation(handler); + mStarted = true; } else if (!mInitialized) { initAnimation(); } @@ -1010,7 +1026,11 @@ public class ValueAnimator extends Animator { handler.mPendingAnimations.remove(this); handler.mDelayedAnims.remove(this); mPlayingState = STOPPED; - if (mRunning && mListeners != null) { + if ((mStarted || mRunning) && mListeners != null) { + if (!mRunning) { + // If it's not yet running, then start listeners weren't called. Call them now. + notifyStartListeners(); + } ArrayList<AnimatorListener> tmpListeners = (ArrayList<AnimatorListener>) mListeners.clone(); int numListeners = tmpListeners.size(); @@ -1020,6 +1040,7 @@ public class ValueAnimator extends Animator { } mRunning = false; mStarted = false; + mStartListenersCalled = false; } /** @@ -1032,12 +1053,7 @@ public class ValueAnimator extends Animator { if (mStartDelay > 0 && mListeners != null) { // Listeners were already notified in start() if startDelay is 0; this is // just for delayed animations - ArrayList<AnimatorListener> tmpListeners = - (ArrayList<AnimatorListener>) mListeners.clone(); - int numListeners = tmpListeners.size(); - for (int i = 0; i < numListeners; ++i) { - tmpListeners.get(i).onAnimationStart(this); - } + notifyStartListeners(); } } |