Save the date! Android Dev Summit is coming to Mountain View, CA on November 7-8, 2018.
added in version 1.0.0
belongs to Maven artifact androidx.appcompat:appcompat:1.1.0-alpha01

AnimatedStateListDrawableCompat

public class AnimatedStateListDrawableCompat
extends Drawable implements Drawable.Callback

java.lang.Object
   ↳ android.graphics.drawable.Drawable
     ↳ androidx.appcompat.graphics.drawable.AnimatedStateListDrawableCompat


A Drawable providing animated transitions between states.

A port of AnimatedStateListDrawable compatible with older versions of the platform.

This drawable can be defined in an XML file with the <animated-selector> element. Each keyframe Drawable is defined in a nested <item> element. Transitions are defined in a nested <transition> element.

Notable exceptions not supported by this class:

  • drawables defined as children of <item>s or <transition>s (except vectors) ignore theme attributes prior to API level 21
  • Animated vector transitions do not support reversing prior to API level 24

Summary

Public constructors

AnimatedStateListDrawableCompat()

Public methods

void addState(int[] stateSet, Drawable drawable, int id)

Add a new drawable to the set of keyframes.

void addState(int[] stateSet, Drawable drawable)

Add a new image/string ID to the set of images.

<T extends Drawable & Animatable> void addTransition(int fromId, int toId, T transition, boolean reversible)

Adds a new transition between keyframes.

void applyTheme(Resources.Theme theme)
boolean canApplyTheme()
static AnimatedStateListDrawableCompat create(Context context, int resId, Resources.Theme theme)

Creates an AnimatedStateListDrawableCompat.

static AnimatedStateListDrawableCompat createFromXmlInner(Context context, Resources resources, XmlPullParser parser, AttributeSet attrs, Resources.Theme theme)

Create a AnimatedStateListDrawableCompat from inside an XML document using an optional Resources.Theme.

void draw(Canvas canvas)
int getAlpha()
int getChangingConfigurations()
final Drawable.ConstantState getConstantState()
Drawable getCurrent()
void getHotspotBounds(Rect outRect)
int getIntrinsicHeight()
int getIntrinsicWidth()
int getMinimumHeight()
int getMinimumWidth()
int getOpacity()
void getOutline(Outline outline)
boolean getPadding(Rect padding)
void inflate(Context context, Resources resources, XmlPullParser parser, AttributeSet attrs, Resources.Theme theme)

Inflate this Drawable from an XML resource optionally styled by a theme.

void invalidateDrawable(Drawable who)
boolean isAutoMirrored()
boolean isStateful()
void jumpToCurrentState()
Drawable mutate()
boolean onLayoutDirectionChanged(int layoutDirection)
void scheduleDrawable(Drawable who, Runnable what, long when)
void setAlpha(int alpha)
void setAutoMirrored(boolean mirrored)
void setColorFilter(ColorFilter colorFilter)
void setDither(boolean dither)
void setEnterFadeDuration(int ms)

Change the global fade duration when a new drawable is entering the scene.

void setExitFadeDuration(int ms)

Change the global fade duration when a new drawable is leaving the scene.

void setHotspot(float x, float y)
void setHotspotBounds(int left, int top, int right, int bottom)
void setTintList(ColorStateList tint)
void setTintMode(PorterDuff.Mode tintMode)
boolean setVisible(boolean visible, boolean restart)
void unscheduleDrawable(Drawable who, Runnable what)

Protected methods

void onBoundsChange(Rect bounds)
boolean onLevelChange(int level)
boolean onStateChange(int[] stateSet)
void setConstantState(DrawableContainer.DrawableContainerState state)

Inherited methods

Public constructors

AnimatedStateListDrawableCompat

added in version 1.0.0
public AnimatedStateListDrawableCompat ()

Public methods

addState

added in version 1.0.0
public void addState (int[] stateSet, 
                Drawable drawable, 
                int id)

Add a new drawable to the set of keyframes.

Parameters
stateSet int: An array of resource IDs to associate with the keyframe

drawable Drawable: The drawable to show when in the specified state, may not be null

id int: The unique identifier for the keyframe

addState

public void addState (int[] stateSet, 
                Drawable drawable)

Add a new image/string ID to the set of images.

Parameters
stateSet int: - An array of resource Ids to associate with the image. Switch to this image by calling setState().

drawable Drawable: -The image to show.

addTransition

added in version 1.0.0
public void addTransition (int fromId, 
                int toId, 
                T transition, 
                boolean reversible)

Adds a new transition between keyframes.

Parameters
fromId int: Unique identifier of the starting keyframe

toId int: Unique identifier of the ending keyframe

transition T: An Animatable drawable to use as a transition, may not be null

reversible boolean: Whether the transition can be reversed

applyTheme

public void applyTheme (Resources.Theme theme)

Parameters
theme Resources.Theme

canApplyTheme

public boolean canApplyTheme ()

Returns
boolean

create

added in version 1.0.0
public static AnimatedStateListDrawableCompat create (Context context, 
                int resId, 
                Resources.Theme theme)

Creates an AnimatedStateListDrawableCompat.

Parameters
context Context: context to inflate against

resId int: the resource ID for AnimatedStateListDrawable object.

theme Resources.Theme: the theme to apply, may be null.

Returns
AnimatedStateListDrawableCompat a new AnimatedStateListDrawableCompat or null if parsing error is found.

createFromXmlInner

added in version 1.0.0
public static AnimatedStateListDrawableCompat createFromXmlInner (Context context, 
                Resources resources, 
                XmlPullParser parser, 
                AttributeSet attrs, 
                Resources.Theme theme)

Create a AnimatedStateListDrawableCompat from inside an XML document using an optional Resources.Theme. Called on a parser positioned at a tag in an XML document, tries to create an AnimatedStateListDrawableCompat from that tag.

Parameters
context Context

resources Resources

parser XmlPullParser

attrs AttributeSet

theme Resources.Theme

Returns
AnimatedStateListDrawableCompat

Throws
IOException
XmlPullParserException

draw

public void draw (Canvas canvas)

Parameters
canvas Canvas

getAlpha

public int getAlpha ()

Returns
int

getChangingConfigurations

public int getChangingConfigurations ()

Returns
int

getConstantState

public final Drawable.ConstantState getConstantState ()

Returns
Drawable.ConstantState

getCurrent

public Drawable getCurrent ()

Returns
Drawable

getHotspotBounds

public void getHotspotBounds (Rect outRect)

Parameters
outRect Rect

getIntrinsicHeight

public int getIntrinsicHeight ()

Returns
int

getIntrinsicWidth

public int getIntrinsicWidth ()

Returns
int

getMinimumHeight

public int getMinimumHeight ()

Returns
int

getMinimumWidth

public int getMinimumWidth ()

Returns
int

getOpacity

public int getOpacity ()

Returns
int

getOutline

public void getOutline (Outline outline)

Parameters
outline Outline

getPadding

public boolean getPadding (Rect padding)

Parameters
padding Rect

Returns
boolean

inflate

added in version 1.0.0
public void inflate (Context context, 
                Resources resources, 
                XmlPullParser parser, 
                AttributeSet attrs, 
                Resources.Theme theme)

Inflate this Drawable from an XML resource optionally styled by a theme. This can't be called more than once for each Drawable.

Parameters
context Context: context to inflate against

resources Resources: Resources used to resolve attribute values

parser XmlPullParser: XML parser from which to inflate this Drawable

attrs AttributeSet: Base set of attribute values

theme Resources.Theme: Theme to apply, may be null

Throws
XmlPullParserException
IOException
XmlPullParserException

invalidateDrawable

public void invalidateDrawable (Drawable who)

Parameters
who Drawable

isAutoMirrored

public boolean isAutoMirrored ()

Returns
boolean

isStateful

public boolean isStateful ()

Returns
boolean

jumpToCurrentState

public void jumpToCurrentState ()

mutate

public Drawable mutate ()

Returns
Drawable

onLayoutDirectionChanged

public boolean onLayoutDirectionChanged (int layoutDirection)

Parameters
layoutDirection int

Returns
boolean

scheduleDrawable

public void scheduleDrawable (Drawable who, 
                Runnable what, 
                long when)

Parameters
who Drawable

what Runnable

when long

setAlpha

public void setAlpha (int alpha)

Parameters
alpha int

setAutoMirrored

public void setAutoMirrored (boolean mirrored)

Parameters
mirrored boolean

setColorFilter

public void setColorFilter (ColorFilter colorFilter)

Parameters
colorFilter ColorFilter

setDither

public void setDither (boolean dither)

Parameters
dither boolean

setEnterFadeDuration

public void setEnterFadeDuration (int ms)

Change the global fade duration when a new drawable is entering the scene.

Parameters
ms int: The amount of time to fade in milliseconds.

setExitFadeDuration

public void setExitFadeDuration (int ms)

Change the global fade duration when a new drawable is leaving the scene.

Parameters
ms int: The amount of time to fade in milliseconds.

setHotspot

public void setHotspot (float x, 
                float y)

Parameters
x float

y float

setHotspotBounds

public void setHotspotBounds (int left, 
                int top, 
                int right, 
                int bottom)

Parameters
left int

top int

right int

bottom int

setTintList

public void setTintList (ColorStateList tint)

Parameters
tint ColorStateList

setTintMode

public void setTintMode (PorterDuff.Mode tintMode)

Parameters
tintMode PorterDuff.Mode

setVisible

public boolean setVisible (boolean visible, 
                boolean restart)

Parameters
visible boolean

restart boolean

Returns
boolean

unscheduleDrawable

public void unscheduleDrawable (Drawable who, 
                Runnable what)

Parameters
who Drawable

what Runnable

Protected methods

onBoundsChange

protected void onBoundsChange (Rect bounds)

Parameters
bounds Rect

onLevelChange

protected boolean onLevelChange (int level)

Parameters
level int

Returns
boolean

onStateChange

protected boolean onStateChange (int[] stateSet)

Parameters
stateSet int

Returns
boolean

setConstantState

added in version 1.0.0
protected void setConstantState (DrawableContainer.DrawableContainerState state)

Parameters
state DrawableContainer.DrawableContainerState