Class AnimationDrawable
java.lang.Object
icyllis.modernui.graphics.drawable.Drawable
icyllis.modernui.graphics.drawable.DrawableContainer
icyllis.modernui.graphics.drawable.AnimationDrawable
- All Implemented Interfaces:
Animatable
,Drawable.Callback
,Runnable
An object used to create frame-by-frame animations, defined by a series of
Drawable objects, which can be used as a View object's background.
-
Nested Class Summary
Nested classes/interfaces inherited from class icyllis.modernui.graphics.drawable.DrawableContainer
DrawableContainer.DrawableContainerState
Nested classes/interfaces inherited from class icyllis.modernui.graphics.drawable.Drawable
Drawable.Callback, Drawable.ConstantState
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a frame to the animationint
getDuration
(int i) getFrame
(int index) int
boolean
boolean
Indicates whether the animation is currently running or not.mutate()
Make this drawable mutable.void
run()
This method exists for implementation purpose only and should not be called directly.protected void
void
setOneShot
(boolean oneShot) Sets whether the animation should play once or repeat.boolean
setVisible
(boolean visible, boolean restart) Sets whether this AnimationDrawable is visible.void
start()
Starts the animation from the first frame, looping if necessary.void
stop()
Stops the animation at the current frame.void
unscheduleSelf
(Runnable what) Use the currentDrawable.Callback
implementation to have this Drawable unscheduled.Methods inherited from class icyllis.modernui.graphics.drawable.DrawableContainer
draw, getAlpha, getConstantState, getCurrent, getCurrentIndex, getHotspotBounds, getIntrinsicHeight, getIntrinsicWidth, getMinimumHeight, getMinimumWidth, getOutline, getPadding, hasFocusStateSpecified, invalidateDrawable, isAutoMirrored, isStateful, jumpToCurrentState, onBoundsChange, onLayoutDirectionChanged, onLevelChange, onStateChange, scheduleDrawable, selectDrawable, setAlpha, setAutoMirrored, setEnterFadeDuration, setExitFadeDuration, setHotspot, setHotspotBounds, setTintBlendMode, setTintList, unscheduleDrawable
Methods inherited from class icyllis.modernui.graphics.drawable.Drawable
applyTheme, canApplyTheme, copyBounds, copyBounds, getBounds, getCallback, getChangingConfigurations, getColorFilter, getDirtyBounds, getLayoutDirection, getLevel, getState, invalidateSelf, isVisible, scaleFromDensity, scaleFromDensity, scheduleSelf, setBounds, setBounds, setCallback, setChangingConfigurations, setColorFilter, setLayoutDirection, setLevel, setState, setTint
-
Constructor Details
-
AnimationDrawable
public AnimationDrawable()
-
-
Method Details
-
setVisible
public boolean setVisible(boolean visible, boolean restart) Sets whether this AnimationDrawable is visible.When the drawable becomes invisible, it will pause its animation. A subsequent change to visible with
restart
set to true will restart the animation from the first frame. Ifrestart
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 throughsetOneShot(boolean)
), in which case, it will stay on the last frame.- Overrides:
setVisible
in classDrawableContainer
- Parameters:
visible
- true if visible, false otherwiserestart
- when visible, true to force the animation to restart from the first frame- Returns:
- true if the new visibility is different than its previous state
-
start
public void start()Starts the animation from the first frame, looping if necessary. This method has no effect if the animation is running.You may want to call this from
Fragment.onViewCreated(icyllis.modernui.view.View, icyllis.modernui.util.DataSet)
- Specified by:
start
in interfaceAnimatable
- See Also:
-
stop
public void stop()Stops the animation at the current frame. This method has no effect if the animation is not running.- Specified by:
stop
in interfaceAnimatable
- See Also:
-
isRunning
public boolean isRunning()Indicates whether the animation is currently running or not.- Specified by:
isRunning
in interfaceAnimatable
- Returns:
- true if the animation is running, false otherwise
-
run
public void run()This method exists for implementation purpose only and should not be called directly. Invokestart()
instead. -
unscheduleSelf
Description copied from class:Drawable
Use the currentDrawable.Callback
implementation to have this Drawable unscheduled. Does nothing if there is no Callback attached to the Drawable.- Overrides:
unscheduleSelf
in classDrawable
- Parameters:
what
- The runnable that you no longer want called.- See Also:
-
getNumberOfFrames
public int getNumberOfFrames()- Returns:
- The number of frames in the animation
-
getFrame
- Returns:
- The Drawable at the specified frame index
-
getDuration
public int getDuration(int i) - Returns:
- The duration in milliseconds of the frame at the specified index
-
isOneShot
public boolean isOneShot()- Returns:
- True of the animation will play once, false otherwise
-
setOneShot
public void setOneShot(boolean oneShot) Sets whether the animation should play once or repeat.- Parameters:
oneShot
- Pass true if the animation should only play once
-
addFrame
Adds a frame to the animation- Parameters:
frame
- The frame to addduration
- How long in milliseconds the frame should appear
-
mutate
Description copied from class:Drawable
Make this drawable mutable. This operation cannot be reversed. A mutable drawable is guaranteed to not share its state with any other drawable. This is especially useful when you need to modify properties of drawables loaded from resources. By default, all drawables instances loaded from the same resource share a common state; if you modify the state of one instance, all the other instances will receive the same modification.Calling this method on a mutable Drawable will have no effect.
- Overrides:
mutate
in classDrawableContainer
- Returns:
- This drawable.
- See Also:
-
setConstantState
- Overrides:
setConstantState
in classDrawableContainer
-