/**
* Sets whether this AnimationDrawable is visible.
* <p>
- * When the drawable becomes invisible, it will pause its animation. A
- * subsequent change to visible with <code>restart</code> set to true will
- * restart the animation from the first frame. If <code>restart</code> is
- * false, the animation will resume from the most recent frame.
+ * When the drawable becomes invisible, it will pause its animation. A subsequent change to
+ * visible with <code>restart</code> set to true will restart the animation from the
+ * first frame. If <code>restart</code> is false, the drawable will resume from the most recent
+ * frame. If the drawable has already reached the last frame, it will then loop back to the
+ * first frame, unless it's a one shot drawable (set through {@link #setOneShot(boolean)}),
+ * in which case, it will stay on the last frame.
*
* @param visible true if visible, false otherwise
* @param restart when visible, true to force the animation to restart
final boolean changed = super.setVisible(visible, restart);
if (visible) {
if (restart || changed) {
- boolean startFromZero = restart || !mRunning ||
+ boolean startFromZero = restart || (!mRunning && !mAnimationState.mOneShot) ||
mCurFrame >= mAnimationState.getChildCount();
setFrame(startFromZero ? 0 : mCurFrame, true, mAnimating);
}
}
/**
- * Starts the animation, looping if necessary. This method has no effect
+ * Starts the animation from the first frame, looping if necessary. This method has no effect
* if the animation is running.
* <p>
* <strong>Note:</strong> Do not call this in the
}
/**
- * Stops the animation. This method has no effect if the animation is not
+ * Stops the animation at the current frame. This method has no effect if the animation is not
* running.
*
* @see #isRunning()
mAnimating = false;
if (isRunning()) {
+ mCurFrame = 0;
unscheduleSelf(this);
}
}
@Override
public void unscheduleSelf(Runnable what) {
- mCurFrame = 0;
mRunning = false;
super.unscheduleSelf(what);
}