summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorDoris Liu <tianliu@google.com>2015-05-11 15:18:45 -0700
committerDoris Liu <tianliu@google.com>2015-05-12 10:07:25 -0700
commit56ef127df75164243a21df10771e7c77c8ef2e24 (patch)
tree8d1971bc35e9a28c0a2d7321424619ec9d9cfd85 /graphics
parent729d0a06eaaa40f5be4d9dc5bd580f525ba8360e (diff)
downloadframeworks_base-56ef127df75164243a21df10771e7c77c8ef2e24.zip
frameworks_base-56ef127df75164243a21df10771e7c77c8ef2e24.tar.gz
frameworks_base-56ef127df75164243a21df10771e7c77c8ef2e24.tar.bz2
Avoid setting mCurFrame to -1
Use the dedicated flag mRunning to check whether the DrawableAnimation is running, rather than comparing mCurFrame with -1. This CL aims to simplify the use of mCurFrame. Bug: 17112962 Change-Id: I15f9e4c102f504b8c806f029949fe9ec872479a5
Diffstat (limited to 'graphics')
-rw-r--r--graphics/java/android/graphics/drawable/AnimationDrawable.java11
1 files changed, 5 insertions, 6 deletions
diff --git a/graphics/java/android/graphics/drawable/AnimationDrawable.java b/graphics/java/android/graphics/drawable/AnimationDrawable.java
index 5ccb165..871715e 100644
--- a/graphics/java/android/graphics/drawable/AnimationDrawable.java
+++ b/graphics/java/android/graphics/drawable/AnimationDrawable.java
@@ -87,8 +87,8 @@ import android.util.AttributeSet;
public class AnimationDrawable extends DrawableContainer implements Runnable, Animatable {
private AnimationState mAnimationState;
- /** The current frame, may be -1 when not animating. */
- private int mCurFrame = -1;
+ /** The current frame, ranging from 0 to {@link #mAnimationState#getChildCount() - 1} */
+ private int mCurFrame = 0;
/** Whether the drawable has an animation callback posted. */
private boolean mRunning;
@@ -120,7 +120,7 @@ public class AnimationDrawable extends DrawableContainer implements Runnable, An
final boolean changed = super.setVisible(visible, restart);
if (visible) {
if (restart || changed) {
- boolean startFromZero = restart || mCurFrame < 0 ||
+ boolean startFromZero = restart || !mRunning ||
mCurFrame >= mAnimationState.getChildCount();
setFrame(startFromZero ? 0 : mCurFrame, true, mAnimating);
}
@@ -194,7 +194,7 @@ public class AnimationDrawable extends DrawableContainer implements Runnable, An
@Override
public void unscheduleSelf(Runnable what) {
- mCurFrame = -1;
+ mCurFrame = 0;
mRunning = false;
super.unscheduleSelf(what);
}
@@ -245,7 +245,7 @@ public class AnimationDrawable extends DrawableContainer implements Runnable, An
*/
public void addFrame(@NonNull Drawable frame, int duration) {
mAnimationState.addFrame(frame, duration);
- if (mCurFrame < 0) {
+ if (!mRunning) {
setFrame(0, true, false);
}
}
@@ -272,7 +272,6 @@ public class AnimationDrawable extends DrawableContainer implements Runnable, An
selectDrawable(frame);
if (unschedule || animate) {
unscheduleSelf(this);
- mRunning = false;
}
if (animate) {
// Unscheduling may have clobbered these values; restore them