From 180979f76b0c99cd7053a44692f6408721b74bce Mon Sep 17 00:00:00 2001 From: John Spurlock Date: Fri, 15 Nov 2013 17:10:03 -0500 Subject: [PATCH] Fix logic problems in AnimationDrawable and View. 1. View now checks both queues when unscheduling runnables, fixing the case where work was scheduled pre-attach, and unscheduled post-attach. 2. AnimationDrawable avoids posting duplicate runnables when rescheduling itself. 3. Decouple is-animation-running state from current frame pointer in AnimationDrawable. Some calls init to the first frame, but do not kick off the animation. 4. Remove workaround in SystemUI's AnimatedImageView (status bar icon) now that the underlying framework issues are fixed. Bug:11694594 Change-Id: I77ca6bd80262f7edcf980b2d7efc2592f8051f29 --- core/java/android/view/View.java | 8 +++----- .../android/graphics/drawable/AnimationDrawable.java | 9 ++++++--- .../android/systemui/statusbar/AnimatedImageView.java | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index fc957241f4eb2..2734abc3edc53 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -11325,10 +11325,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback, attachInfo.mHandler.removeCallbacks(action); attachInfo.mViewRootImpl.mChoreographer.removeCallbacks( Choreographer.CALLBACK_ANIMATION, action, null); - } else { - // Assume that post will succeed later - ViewRootImpl.getRunQueue().removeCallbacks(action); } + // Assume that post will succeed later + ViewRootImpl.getRunQueue().removeCallbacks(action); } return true; } @@ -15103,9 +15102,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, if (mAttachInfo != null) { mAttachInfo.mViewRootImpl.mChoreographer.removeCallbacks( Choreographer.CALLBACK_ANIMATION, what, who); - } else { - ViewRootImpl.getRunQueue().removeCallbacks(what); } + ViewRootImpl.getRunQueue().removeCallbacks(what); } } diff --git a/graphics/java/android/graphics/drawable/AnimationDrawable.java b/graphics/java/android/graphics/drawable/AnimationDrawable.java index bde978d0a111f..02b2588334a66 100644 --- a/graphics/java/android/graphics/drawable/AnimationDrawable.java +++ b/graphics/java/android/graphics/drawable/AnimationDrawable.java @@ -81,6 +81,7 @@ import android.util.AttributeSet; public class AnimationDrawable extends DrawableContainer implements Runnable, Animatable { private final AnimationState mAnimationState; private int mCurFrame = -1; + private boolean mAnimating; private boolean mMutated; public AnimationDrawable() { @@ -137,7 +138,7 @@ public class AnimationDrawable extends DrawableContainer implements Runnable, An * @return true if the animation is running, false otherwise */ public boolean isRunning() { - return mCurFrame > -1; + return mAnimating; } /** @@ -153,6 +154,7 @@ public class AnimationDrawable extends DrawableContainer implements Runnable, An @Override public void unscheduleSelf(Runnable what) { mCurFrame = -1; + mAnimating = false; super.unscheduleSelf(what); } @@ -222,12 +224,13 @@ public class AnimationDrawable extends DrawableContainer implements Runnable, An } mCurFrame = frame; selectDrawable(frame); - if (unschedule) { + if (unschedule || animate) { unscheduleSelf(this); } if (animate) { - // Unscheduling may have clobbered this value; restore it to record that we're animating + // Unscheduling may have clobbered these values; restore them mCurFrame = frame; + mAnimating = true; scheduleSelf(this, SystemClock.uptimeMillis() + mAnimationState.mDurations[frame]); } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/AnimatedImageView.java b/packages/SystemUI/src/com/android/systemui/statusbar/AnimatedImageView.java index 7d3e870c1a8f6..9839fe9e6f4d6 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/AnimatedImageView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/AnimatedImageView.java @@ -38,7 +38,7 @@ public class AnimatedImageView extends ImageView { } private void updateAnim() { - Drawable drawable = mAttached ? getDrawable() : null; + Drawable drawable = getDrawable(); if (mAttached && mAnim != null) { mAnim.stop(); }