public class

AnimatedDrawable2

extends Drawable
implements Animatable DrawableWithCaches
java.lang.Object
   ↳ android.graphics.drawable.Drawable
     ↳ com.facebook.fresco.animation.drawable.AnimatedDrawable2

Class Overview

Experimental new animated drawable that uses a supplied AnimationBackend for drawing frames.

Summary

Nested Classes
interface AnimatedDrawable2.DrawListener draw(Canvas) listener that is notified for each draw call. 
Public Constructors
AnimatedDrawable2()
AnimatedDrawable2(AnimationBackend animationBackend)
Public Methods
void draw(Canvas canvas)
void dropCaches()
Informs the Drawable to drop its caches.
AnimationBackend getAnimationBackend()
long getDroppedFrames()
int getFrameCount()
Get the number of frames for the animation.
int getIntrinsicHeight()
int getIntrinsicWidth()
int getLoopCount()
Get the loop count of the animation.
long getLoopDurationMs()
Get the animation duration for 1 loop by summing all frame durations.
int getOpacity()
long getStartTimeMs()
boolean isInfiniteAnimation()
boolean isRunning()
Check whether the animation is running.
void jumpToFrame(int targetFrameNumber)
Jump immediately to the given frame number.
void setAlpha(int alpha)
void setAnimationBackend(AnimationBackend animationBackend)
Update the animation backend to be used for the animation.
void setAnimationListener(AnimationListener animationListener)
Set an animation listener that is notified for various animation events.
void setColorFilter(ColorFilter colorFilter)
void setDrawListener(AnimatedDrawable2.DrawListener drawListener)
Set a draw listener that is notified for each draw(Canvas) call.
void setFrameSchedulingDelayMs(long frameSchedulingDelayMs)
Frame scheduling delay to shift the target render time for a frame within the frame's visible window.
void setFrameSchedulingOffsetMs(long frameSchedulingOffsetMs)
Frame scheduling offset to shift the animation time by the given offset.
void start()
Start the animation.
void stop()
Stop the animation at the current frame.
Protected Methods
void onBoundsChange(Rect bounds)
boolean onLevelChange(int level)
Set the animation to the given level.
[Expand]
Inherited Methods
From class android.graphics.drawable.Drawable
From class java.lang.Object
From interface android.graphics.drawable.Animatable
From interface com.facebook.drawable.base.DrawableWithCaches

Public Constructors

public AnimatedDrawable2 ()

public AnimatedDrawable2 (AnimationBackend animationBackend)

Public Methods

public void draw (Canvas canvas)

public void dropCaches ()

Informs the Drawable to drop its caches.

public AnimationBackend getAnimationBackend ()

public long getDroppedFrames ()

public int getFrameCount ()

Get the number of frames for the animation. If no animation backend is set, 0 will be returned.

Returns
  • the number of frames of the animation

public int getIntrinsicHeight ()

public int getIntrinsicWidth ()

public int getLoopCount ()

Get the loop count of the animation. The returned value is either LOOP_COUNT_INFINITE if the animation is repeated infinitely or a positive integer that corresponds to the number of loops. If no animation backend is set, LOOP_COUNT_INFINITE will be returned.

Returns

public long getLoopDurationMs ()

Get the animation duration for 1 loop by summing all frame durations.

Returns
  • the duration of 1 animation loop in ms

public int getOpacity ()

public long getStartTimeMs ()

public boolean isInfiniteAnimation ()

public boolean isRunning ()

Check whether the animation is running.

Returns
  • true if the animation is currently running

public void jumpToFrame (int targetFrameNumber)

Jump immediately to the given frame number. The animation will not be paused if it is running. If the animation is not running, the animation will not be started.

Parameters
targetFrameNumber the frame number to jump to

public void setAlpha (int alpha)

public void setAnimationBackend (AnimationBackend animationBackend)

Update the animation backend to be used for the animation. This will also stop the animation. In order to remove the current animation backend, call this method with null.

Parameters
animationBackend the animation backend to be used or null

public void setAnimationListener (AnimationListener animationListener)

Set an animation listener that is notified for various animation events.

Parameters
animationListener the listener to use

public void setColorFilter (ColorFilter colorFilter)

public void setDrawListener (AnimatedDrawable2.DrawListener drawListener)

Set a draw listener that is notified for each draw(Canvas) call.

Parameters
drawListener the listener to use

public void setFrameSchedulingDelayMs (long frameSchedulingDelayMs)

Frame scheduling delay to shift the target render time for a frame within the frame's visible window. If the value is set to 0, the frame will be scheduled right at the beginning of the frame's visible window.

Parameters
frameSchedulingDelayMs the delay to use in ms

public void setFrameSchedulingOffsetMs (long frameSchedulingOffsetMs)

Frame scheduling offset to shift the animation time by the given offset. This is similar to #mFrameSchedulingDelayMs but instead of delaying the invalidation, this offsets the animation time by the given value.

Parameters
frameSchedulingOffsetMs the offset to use in ms

public void start ()

Start the animation.

public void stop ()

Stop the animation at the current frame. It can be resumed by calling start() again.

Protected Methods

protected void onBoundsChange (Rect bounds)

protected boolean onLevelChange (int level)

Set the animation to the given level. The level represents the animation time in ms. If the animation time is greater than the last frame time for the last loop, the last frame will be displayed.

If the animation is running (e.g. if start() has been called, the level change will be ignored. In this case, stop() the animation first.

Parameters
level the animation time in ms
Returns
  • true if the level change could be performed