public class

BitmapAnimationBackend

extends Object
implements AnimationBackend AnimationBackendDelegateWithInactivityCheck.InactivityListener
java.lang.Object
   ↳ com.facebook.fresco.animation.bitmap.BitmapAnimationBackend

Class Overview

Bitmap animation backend that renders bitmap frames. The given BitmapFrameCache is used to cache frames and create new bitmaps. AnimationInformation defines the main animation parameters, like frame and loop count. BitmapFrameRenderer is used to render frames to the bitmaps aquired from the BitmapFrameCache.

Summary

Nested Classes
interface BitmapAnimationBackend.FrameListener  
@interface BitmapAnimationBackend.FrameType Frame type that has been drawn. 
Constants
int FRAME_TYPE_CACHED
int FRAME_TYPE_CREATED
int FRAME_TYPE_FALLBACK
int FRAME_TYPE_REUSED
[Expand]
Inherited Constants
From interface com.facebook.fresco.animation.backend.AnimationBackend
From interface com.facebook.fresco.animation.backend.AnimationInformation
Public Constructors
BitmapAnimationBackend(PlatformBitmapFactory platformBitmapFactory, BitmapFrameCache bitmapFrameCache, AnimationInformation animationInformation, BitmapFrameRenderer bitmapFrameRenderer, BitmapFramePreparationStrategy bitmapFramePreparationStrategy, BitmapFramePreparer bitmapFramePreparer)
Public Methods
void clear()
Clean up animation data.
boolean drawFrame(Drawable parent, Canvas canvas, int frameNumber)
Draw the frame for the given frame number on the canvas.
int getFrameCount()
Get the number of frames for the animation
int getFrameDurationMs(int frameNumber)
Get the frame duration for a given frame number in milliseconds.
int getIntrinsicHeight()
Get the intrinsic height of the underlying animation or INTRINSIC_DIMENSION_UNSET if not available.
int getIntrinsicWidth()
Get the intrinsic width of the underlying animation or INTRINSIC_DIMENSION_UNSET if not available.
int getLoopCount()
Get the number of loops the animation has or LOOP_COUNT_INFINITE for infinite looping.
int getSizeInBytes()
Get the size of the animation backend.
void onInactive()
Called when the animation backend has not been used to draw frames within the given threshold.
void setAlpha(int alpha)
Set the alpha value to be used for drawing frames in drawFrame(Drawable, Canvas, int) if supported.
void setBitmapConfig(Bitmap.Config bitmapConfig)
Set the bitmap config to be used to create new bitmaps.
void setBounds(Rect bounds)
Called when the bounds of the parent drawable are updated.
void setColorFilter(ColorFilter colorFilter)
The color filter to be used for drawing frames in drawFrame(Drawable, Canvas, int) if supported.
void setFrameListener(BitmapAnimationBackend.FrameListener frameListener)
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.facebook.fresco.animation.backend.AnimationBackend
From interface com.facebook.fresco.animation.backend.AnimationBackendDelegateWithInactivityCheck.InactivityListener
From interface com.facebook.fresco.animation.backend.AnimationInformation

Constants

public static final int FRAME_TYPE_CACHED

Constant Value: 0 (0x00000000)

public static final int FRAME_TYPE_CREATED

Constant Value: 2 (0x00000002)

public static final int FRAME_TYPE_FALLBACK

Constant Value: 3 (0x00000003)

public static final int FRAME_TYPE_REUSED

Constant Value: 1 (0x00000001)

Public Constructors

public BitmapAnimationBackend (PlatformBitmapFactory platformBitmapFactory, BitmapFrameCache bitmapFrameCache, AnimationInformation animationInformation, BitmapFrameRenderer bitmapFrameRenderer, BitmapFramePreparationStrategy bitmapFramePreparationStrategy, BitmapFramePreparer bitmapFramePreparer)

Public Methods

public void clear ()

Clean up animation data. This will be called when the backing drawable is cleared as well. For example, drop all cached frames.

public boolean drawFrame (Drawable parent, Canvas canvas, int frameNumber)

Draw the frame for the given frame number on the canvas.

Parameters
parent the parent that draws the frame
canvas the canvas to draw an
frameNumber the frame number of the frame to draw
Returns
  • true if successful, false if the frame could not be rendered

public int getFrameCount ()

Get the number of frames for the animation

Returns
  • the number of frames

public int getFrameDurationMs (int frameNumber)

Get the frame duration for a given frame number in milliseconds.

Parameters
frameNumber the frame to get the duration for
Returns
  • the duration in ms

public int getIntrinsicHeight ()

Get the intrinsic height of the underlying animation or INTRINSIC_DIMENSION_UNSET if not available. This value is used by the underlying drawable for aspect ratio computations, similar to getIntrinsicHeight().

Returns

public int getIntrinsicWidth ()

Get the intrinsic width of the underlying animation or INTRINSIC_DIMENSION_UNSET if not available. This value is used by the underlying drawable for aspect ratio computations, similar to getIntrinsicWidth().

Returns

public int getLoopCount ()

Get the number of loops the animation has or LOOP_COUNT_INFINITE for infinite looping.

Returns

public int getSizeInBytes ()

Get the size of the animation backend.

Returns
  • the size in bytes

public void onInactive ()

Called when the animation backend has not been used to draw frames within the given threshold.

public void setAlpha (int alpha)

Set the alpha value to be used for drawing frames in drawFrame(Drawable, Canvas, int) if supported.

Parameters
alpha the alpha value between 0 and 255

public void setBitmapConfig (Bitmap.Config bitmapConfig)

Set the bitmap config to be used to create new bitmaps.

Parameters
bitmapConfig the bitmap config to be used

public void setBounds (Rect bounds)

Called when the bounds of the parent drawable are updated. This can be used to perform some ahead-of-time computations if needed. The supplied bounds do not have to be stored. It is possible to just use getBounds() of the parent drawable of drawFrame(Drawable, Canvas, int) instead.

Parameters
bounds the bounds to be used for drawing frames

public void setColorFilter (ColorFilter colorFilter)

The color filter to be used for drawing frames in drawFrame(Drawable, Canvas, int) if supported.

Parameters
colorFilter the color filter to use

public void setFrameListener (BitmapAnimationBackend.FrameListener frameListener)