public abstract class Animator extends Object implements Cloneable
AnimatorListeners
added to them.Modifier and Type | Class and Description |
---|---|
static interface |
Animator.AnimatorListener
An animation listener receives notifications from an animation.
|
static interface |
Animator.AnimatorPauseListener
|
Modifier and Type | Field and Description |
---|---|
static long |
DURATION_INFINITE
The value used to indicate infinite duration (e.g. when Animators repeat infinitely).
|
Constructor and Description |
---|
Animator() |
Modifier and Type | Method and Description |
---|---|
void |
addListener(Animator.AnimatorListener listener)
Adds a listener to the set of listeners that are sent events through the life of an
animation, such as start, repeat, and end.
|
void |
addPauseListener(Animator.AnimatorPauseListener listener)
Adds a pause listener to this animator.
|
void |
appendChangingConfigurations(int configs)
Sets the changing configurations value to the union of the current changing configurations
and the provided configs.
|
void |
cancel()
Cancels the animation.
|
boolean |
canReverse() |
Animator |
clone()
Creates and returns a copy of this object.
|
ConstantState<Animator> |
createConstantState()
Return a
ConstantState instance that holds the shared state of
this Animator. |
void |
end()
Ends the animation.
|
int |
getChangingConfigurations()
Return a mask of the configuration parameters for which this animator may change, requiring
that it should be re-created from Resources.
|
abstract long |
getDuration()
Gets the duration of the animation.
|
TimeInterpolator |
getInterpolator()
Returns the timing interpolator that this animation uses.
|
ArrayList<Animator.AnimatorListener> |
getListeners()
Gets the set of
Animator.AnimatorListener objects that are currently
listening for events on this Animator object. |
abstract long |
getStartDelay()
The amount of time, in milliseconds, to delay processing the animation
after
start() is called. |
long |
getTotalDuration()
Gets the total duration of the animation, accounting for animation sequences, start delay,
and repeating.
|
boolean |
isPaused()
Returns whether this animator is currently in a paused state.
|
abstract boolean |
isRunning()
Returns whether this Animator is currently running (having been started and gone past any
initial startDelay period and not yet ended).
|
boolean |
isStarted()
Returns whether this Animator has been started and not yet ended.
|
void |
pause()
Pauses a running animation.
|
void |
removeAllListeners()
Removes all
listeners
and pauseListeners from this object. |
void |
removeListener(Animator.AnimatorListener listener)
Removes a listener from the set listening to this animation.
|
void |
removePauseListener(Animator.AnimatorPauseListener listener)
Removes a pause listener from the set listening to this animation.
|
void |
resume()
Resumes a paused animation, causing the animator to pick up where it left off
when it was paused.
|
void |
reverse() |
void |
setAllowRunningAsynchronously(boolean mayRunAsync)
Whether or not the Animator is allowed to run asynchronously off of
the UI thread.
|
void |
setChangingConfigurations(int configs)
Set a mask of the configuration parameters for which this animator may change, requiring
that it be re-created from resource.
|
abstract Animator |
setDuration(long duration)
Sets the duration of the animation.
|
abstract void |
setInterpolator(TimeInterpolator value)
The time interpolator used in calculating the elapsed fraction of the
animation.
|
abstract void |
setStartDelay(long startDelay)
The amount of time, in milliseconds, to delay processing the animation
after
start() is called. |
void |
setTarget(Object target)
Sets the target object whose property will be animated by this animation.
|
void |
setupEndValues()
This method tells the object to use appropriate information to extract
ending values for the animation.
|
void |
setupStartValues()
This method tells the object to use appropriate information to extract
starting values for the animation.
|
void |
start()
Starts this animation.
|
public static final long DURATION_INFINITE
public void start()
Animator.AnimatorListener.onAnimationStart(Animator)
for any listeners of this animator.
The animation started by calling this method will be run on the thread that called this method. This thread should have a Looper on it (a runtime exception will be thrown if this is not the case). Also, if the animation will animate properties of objects in the view hierarchy, then the calling thread should be the UI thread for that view hierarchy.
public void cancel()
end()
, cancel()
causes the animation to
stop in its tracks, sending an
Animator.AnimatorListener.onAnimationCancel(Animator)
to
its listeners, followed by an
Animator.AnimatorListener.onAnimationEnd(Animator)
message.
This method must be called on the thread that is running the animation.
public void end()
Animator.AnimatorListener.onAnimationEnd(Animator)
method on
its listeners.
This method must be called on the thread that is running the animation.
public void pause()
started
or has since ended, then the call is ignored. Paused
animations can be resumed by calling resume()
.resume()
,
isPaused()
,
Animator.AnimatorPauseListener
public void resume()
pause()
,
isPaused()
,
Animator.AnimatorPauseListener
public boolean isPaused()
public abstract long getStartDelay()
start()
is called.public abstract void setStartDelay(long startDelay)
start()
is called.startDelay
- The amount of the delay, in millisecondspublic abstract Animator setDuration(long duration)
duration
- The length of the animation, in milliseconds.public abstract long getDuration()
public long getTotalDuration()
DURATION_INFINITE
if the duration is infinite.start()
is called. DURATION_INFINITE
will be returned if the animation or any
child animation repeats infinite times.public abstract void setInterpolator(TimeInterpolator value)
AccelerateDecelerateInterpolator
.value
- the interpolator to be used by this animationpublic TimeInterpolator getInterpolator()
public abstract boolean isRunning()
public boolean isStarted()
createCircularReveal()
),
this state is a superset of isRunning()
, because an Animator with a
nonzero startDelay
will return true for isStarted()
during
the delay phase, whereas isRunning()
will return true only after the delay phase
is complete. Non-reusable animators will always return true after they have been
started, because they cannot return to a non-started state.public void addListener(Animator.AnimatorListener listener)
listener
- the listener to be added to the current set of listeners for this animation.public void removeListener(Animator.AnimatorListener listener)
listener
- the listener to be removed from the current set of listeners for this
animation.public ArrayList<Animator.AnimatorListener> getListeners()
Animator.AnimatorListener
objects that are currently
listening for events on this Animator
object.public void addPauseListener(Animator.AnimatorPauseListener listener)
listener
- the listener to be added to the current set of pause listeners
for this animation.public void removePauseListener(Animator.AnimatorPauseListener listener)
listener
- the listener to be removed from the current set of pause
listeners for this animation.public void removeAllListeners()
listeners
and pauseListeners
from this object.public int getChangingConfigurations()
ActivityInfo
.ActivityInfo
public void setChangingConfigurations(int configs)
configs
- A mask of the changing configuration parameters, as
defined by ActivityInfo
.ActivityInfo
public void appendChangingConfigurations(int configs)
public ConstantState<Animator> createConstantState()
ConstantState
instance that holds the shared state of
this Animator.
This constant state is used to create new instances of this animator when needed, instead
of re-loading it from resources. Default implementation creates a new
AnimatorConstantState
. You can override this method to provide your custom logic or
return null if you don't want this animator to be cached.
ConstantState
,
clone()
public Animator clone()
Object
x
, the expression:
will be true, and that the expression:x.clone() != x
will bex.clone().getClass() == x.getClass()
true
, but these are not absolute requirements.
While it is typically the case that:
will bex.clone().equals(x)
true
, this is not an absolute requirement.
By convention, the returned object should be obtained by calling
super.clone
. If a class and all of its superclasses (except
Object
) obey this convention, it will be the case that
x.clone().getClass() == x.getClass()
.
By convention, the object returned by this method should be independent
of this object (which is being cloned). To achieve this independence,
it may be necessary to modify one or more fields of the object returned
by super.clone
before returning it. Typically, this means
copying any mutable objects that comprise the internal "deep structure"
of the object being cloned and replacing the references to these
objects with references to the copies. If a class contains only
primitive fields or references to immutable objects, then it is usually
the case that no fields in the object returned by super.clone
need to be modified.
The method clone
for class Object
performs a
specific cloning operation. First, if the class of this object does
not implement the interface Cloneable
, then a
CloneNotSupportedException
is thrown. Note that all arrays
are considered to implement the interface Cloneable
and that
the return type of the clone
method of an array type T[]
is T[]
where T is any reference or primitive type.
Otherwise, this method creates a new instance of the class of this
object and initializes all its fields with exactly the contents of
the corresponding fields of this object, as if by assignment; the
contents of the fields are not themselves cloned. Thus, this method
performs a "shallow copy" of this object, not a "deep copy" operation.
The class Object
does not itself implement the interface
Cloneable
, so calling the clone
method on an object
whose class is Object
will result in throwing an
exception at run time.
public void setupStartValues()
public void setupEndValues()
public void setTarget(Object target)
ValueAnimator
, but this method
is on the superclass for the convenience of dealing generically with those subclasses
that do handle targets.
Note: The target is stored as a weak reference internally to avoid leaking resources by having animators directly reference old targets. Therefore, you should ensure that animator targets always have a hard reference elsewhere.
target
- The object being animatedpublic boolean canReverse()
public void reverse()
public void setAllowRunningAsynchronously(boolean mayRunAsync)
Whether or not the Animator is allowed to run asynchronously off of the UI thread. This is a hint that informs the Animator that it is OK to run the animation off-thread, however the Animator may decide that it must run the animation on the UI thread anyway.
Regardless of whether or not the animation runs asynchronously, all listener callbacks will be called on the UI thread.
To be able to use this hint the following must be true:
isStarted()
is true. Requests
to change duration, delay, etc... may be ignored.Animator.AnimatorListener.onAnimationEnd(Animator)
or
Animator.AnimatorListener.onAnimationRepeat(Animator)
may end up delayed
as they must be posted back to the UI thread, and any actions performed
by those callbacks (such as starting new animations) will not happen
in the same frame.cancel()
, end()
, reverse()
, etc...)
may be asynchronous. It is guaranteed that all state changes that are
performed on the UI thread in the same frame will be applied as a single
atomic update, however that frame may be the current frame,
the next frame, or some future frame. This will also impact the observed
state of the Animator. For example, isStarted()
may still return true
after a call to end()
. Using the lifecycle callbacks is preferred over
queries to isStarted()
, isRunning()
, and isPaused()
for this reason.