added in version 25.1.0
belongs to Maven artifact com.android.support:animated-vector-drawable:28.0.0-alpha1

AnimatedVectorDrawableCompat

public class AnimatedVectorDrawableCompat
extends Drawable implements Animatable2Compat

java.lang.Object
   ↳ android.graphics.drawable.Drawable
     ↳ android.support.graphics.drawable.AnimatedVectorDrawableCompat


For API 24 and above, this class is delegating to the framework's AnimatedVectorDrawable. For older API version, this class uses ObjectAnimator and AnimatorSet to animate the properties of a VectorDrawableCompat to create an animated drawable.

AnimatedVectorDrawableCompat are defined in the same XML format as AnimatedVectorDrawable.

Here are all the animatable attributes in VectorDrawableCompat:

Element Name Animatable attribute name
<vector> alpha
<group> rotation
pivotX
pivotY
scaleX
scaleY
translateX
translateY
<path> fillColor
pathData
strokeColor
strokeWidth
strokeAlpha
fillAlpha
trimPathStart
trimPathEnd
trimPathOffset

You can always create a AnimatedVectorDrawableCompat object and use it as a Drawable by the Java API. In order to refer to AnimatedVectorDrawableCompat inside a XML file, you can use app:srcCompat attribute in AppCompat library's ImageButton or ImageView.

Note that the animation in AnimatedVectorDrawableCompat now can support the following features:

  • Path Morphing (PathType evaluator). This is used for morphing one path into another.
  • Path Interpolation. This is used to defined a flexible interpolator (represented as a path) instead of the system defined ones like LinearInterpolator.
  • Animating 2 values in one ObjectAnimator according to one path's X value and Y value. One usage is moving one object in both X and Y dimensions along an path.

Summary

Public methods

void applyTheme(Resources.Theme t)
boolean canApplyTheme()
void clearAnimationCallbacks()

Removes all existing animation callbacks.

static void clearAnimationCallbacks(Drawable dr)

Utility function to clear animation callbacks from Drawable, when the drawable is created from XML and referred in Java code, e.g: ImageView.getDrawable().

void clearColorFilter()
static AnimatedVectorDrawableCompat create(Context context, int resId)

Create a AnimatedVectorDrawableCompat object.

static AnimatedVectorDrawableCompat createFromXmlInner(Context context, Resources r, XmlPullParser parser, AttributeSet attrs, Resources.Theme theme)

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

void draw(Canvas canvas)
int getAlpha()
int getChangingConfigurations()
ColorFilter getColorFilter()
Drawable.ConstantState getConstantState()

Note that we don't support constant state when SDK < 24.

Drawable getCurrent()
int getIntrinsicHeight()
int getIntrinsicWidth()
int getMinimumHeight()
int getMinimumWidth()
int getOpacity()
boolean getPadding(Rect padding)
int[] getState()
Region getTransparentRegion()
void inflate(Resources res, XmlPullParser parser, AttributeSet attrs, Resources.Theme theme)
void inflate(Resources res, XmlPullParser parser, AttributeSet attrs)
boolean isAutoMirrored()
boolean isRunning()
boolean isStateful()
void jumpToCurrentState()
Drawable mutate()

mutate() will be effective only if the getConstantState() is returning non-null.

static void registerAnimationCallback(Drawable dr, Animatable2Compat.AnimationCallback callback)

Utility function to register callback to Drawable, when the drawable is created from XML and referred in Java code, e.g: ImageView.getDrawable().

void registerAnimationCallback(Animatable2Compat.AnimationCallback callback)

Adds a callback to listen to the animation events.

void setAlpha(int alpha)
void setAutoMirrored(boolean mirrored)
void setChangingConfigurations(int configs)
void setColorFilter(int color, PorterDuff.Mode mode)
void setColorFilter(ColorFilter colorFilter)
void setFilterBitmap(boolean filter)
void setHotspot(float x, float y)
void setHotspotBounds(int left, int top, int right, int bottom)
boolean setState(int[] stateSet)
void setTint(int tint)
void setTintList(ColorStateList tint)
void setTintMode(PorterDuff.Mode tintMode)
boolean setVisible(boolean visible, boolean restart)
void start()
void stop()
boolean unregisterAnimationCallback(Animatable2Compat.AnimationCallback callback)

Removes the specified animation callback.

static boolean unregisterAnimationCallback(Drawable dr, Animatable2Compat.AnimationCallback callback)

Utility function to unregister animation callback from Drawable, when the drawable is created from XML and referred in Java code, e.g: ImageView.getDrawable().

Protected methods

void onBoundsChange(Rect bounds)
boolean onLevelChange(int level)
boolean onStateChange(int[] state)

Inherited methods

From class android.graphics.drawable.Drawable
From class java.lang.Object
From interface android.support.graphics.drawable.Animatable2Compat
From interface android.graphics.drawable.Animatable

Public methods

applyTheme

void applyTheme (Resources.Theme t)

Parameters
t Resources.Theme

canApplyTheme

boolean canApplyTheme ()

Returns
boolean

clearAnimationCallbacks

added in version 25.4.0
void clearAnimationCallbacks ()

Removes all existing animation callbacks.

clearAnimationCallbacks

added in version 25.4.0
void clearAnimationCallbacks (Drawable dr)

Utility function to clear animation callbacks from Drawable, when the drawable is created from XML and referred in Java code, e.g: ImageView.getDrawable(). From API 24 on, the drawable is treated as an AnimatedVectorDrawable. Otherwise, it is treated as AnimatedVectorDrawableCompat.

Parameters
dr Drawable

clearColorFilter

void clearColorFilter ()

create

added in version 25.1.0
AnimatedVectorDrawableCompat create (Context context, 
                int resId)

Create a AnimatedVectorDrawableCompat object.

Parameters
context Context: the context for creating the animators.

resId int: the resource ID for AnimatedVectorDrawableCompat object.

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

createFromXmlInner

added in version 25.1.0
AnimatedVectorDrawableCompat createFromXmlInner (Context context, 
                Resources r, 
                XmlPullParser parser, 
                AttributeSet attrs, 
                Resources.Theme theme)

Create a AnimatedVectorDrawableCompat 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 a Drawable from that tag. Returns null if the tag is not a valid drawable.

Parameters
context Context

r Resources

parser XmlPullParser

attrs AttributeSet

theme Resources.Theme

Returns
AnimatedVectorDrawableCompat

Throws
XmlPullParserException
IOException

draw

added in version 25.1.0
void draw (Canvas canvas)

Parameters
canvas Canvas

getAlpha

int getAlpha ()

Returns
int

getChangingConfigurations

int getChangingConfigurations ()

Returns
int

getColorFilter

ColorFilter getColorFilter ()

Returns
ColorFilter

getConstantState

Drawable.ConstantState getConstantState ()

Note that we don't support constant state when SDK < 24. Make sure you check the return value before using it.

Returns
Drawable.ConstantState

getCurrent

Drawable getCurrent ()

Returns
Drawable

getIntrinsicHeight

int getIntrinsicHeight ()

Returns
int

getIntrinsicWidth

int getIntrinsicWidth ()

Returns
int

getMinimumHeight

int getMinimumHeight ()

Returns
int

getMinimumWidth

int getMinimumWidth ()

Returns
int

getOpacity

added in version 25.1.0
int getOpacity ()

Returns
int

getPadding

boolean getPadding (Rect padding)

Parameters
padding Rect

Returns
boolean

getState

int[] getState ()

Returns
int[]

getTransparentRegion

Region getTransparentRegion ()

Returns
Region

inflate

void inflate (Resources res, 
                XmlPullParser parser, 
                AttributeSet attrs, 
                Resources.Theme theme)

Parameters
res Resources

parser XmlPullParser

attrs AttributeSet

theme Resources.Theme

Throws
XmlPullParserException
IOException

inflate

void inflate (Resources res, 
                XmlPullParser parser, 
                AttributeSet attrs)

Parameters
res Resources

parser XmlPullParser

attrs AttributeSet

Throws
XmlPullParserException
IOException

isAutoMirrored

boolean isAutoMirrored ()

Returns
boolean

isRunning

added in version 25.1.0
boolean isRunning ()

Returns
boolean

isStateful

boolean isStateful ()

Returns
boolean

jumpToCurrentState

void jumpToCurrentState ()

mutate

Drawable mutate ()

mutate() will be effective only if the getConstantState() is returning non-null. Otherwise, it just return the current object without modification.

Returns
Drawable

registerAnimationCallback

added in version 25.4.0
void registerAnimationCallback (Drawable dr, 
                Animatable2Compat.AnimationCallback callback)

Utility function to register callback to Drawable, when the drawable is created from XML and referred in Java code, e.g: ImageView.getDrawable(). From API 24 on, the drawable is treated as an AnimatedVectorDrawable. Otherwise, it is treated as AnimatedVectorDrawableCompat.

Parameters
dr Drawable

callback Animatable2Compat.AnimationCallback

registerAnimationCallback

added in version 25.4.0
void registerAnimationCallback (Animatable2Compat.AnimationCallback callback)

Adds a callback to listen to the animation events.

Parameters
callback Animatable2Compat.AnimationCallback: Callback to add.

setAlpha

added in version 25.1.0
void setAlpha (int alpha)

Parameters
alpha int

setAutoMirrored

void setAutoMirrored (boolean mirrored)

Parameters
mirrored boolean

setChangingConfigurations

void setChangingConfigurations (int configs)

Parameters
configs int

setColorFilter

void setColorFilter (int color, 
                PorterDuff.Mode mode)

Parameters
color int

mode PorterDuff.Mode

setColorFilter

added in version 25.1.0
void setColorFilter (ColorFilter colorFilter)

Parameters
colorFilter ColorFilter

setFilterBitmap

void setFilterBitmap (boolean filter)

Parameters
filter boolean

setHotspot

void setHotspot (float x, 
                float y)

Parameters
x float

y float

setHotspotBounds

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

Parameters
left int

top int

right int

bottom int

setState

boolean setState (int[] stateSet)

Parameters
stateSet int

Returns
boolean

setTint

void setTint (int tint)

Parameters
tint int

setTintList

void setTintList (ColorStateList tint)

Parameters
tint ColorStateList

setTintMode

void setTintMode (PorterDuff.Mode tintMode)

Parameters
tintMode PorterDuff.Mode

setVisible

boolean setVisible (boolean visible, 
                boolean restart)

Parameters
visible boolean

restart boolean

Returns
boolean

start

added in version 25.1.0
void start ()

stop

added in version 25.1.0
void stop ()

unregisterAnimationCallback

added in version 25.4.0
boolean unregisterAnimationCallback (Animatable2Compat.AnimationCallback callback)

Removes the specified animation callback.

Parameters
callback Animatable2Compat.AnimationCallback: Callback to remove.

Returns
boolean false if callback didn't exist in the call back list, or true if callback has been removed successfully.

unregisterAnimationCallback

added in version 25.4.0
boolean unregisterAnimationCallback (Drawable dr, 
                Animatable2Compat.AnimationCallback callback)

Utility function to unregister animation callback from Drawable, when the drawable is created from XML and referred in Java code, e.g: ImageView.getDrawable(). From API 24 on, the drawable is treated as an AnimatedVectorDrawable. Otherwise, it is treated as AnimatedVectorDrawableCompat.

Parameters
dr Drawable

callback Animatable2Compat.AnimationCallback

Returns
boolean

Protected methods

onBoundsChange

void onBoundsChange (Rect bounds)

Parameters
bounds Rect

onLevelChange

boolean onLevelChange (int level)

Parameters
level int

Returns
boolean

onStateChange

boolean onStateChange (int[] state)

Parameters
state int

Returns
boolean