TimeAnimator


public class TimeAnimator
extends ValueAnimator

java.lang.Object
   ↳ android.animation.Animator
     ↳ android.animation.ValueAnimator
       ↳ android.animation.TimeAnimator


This class provides a simple callback mechanism to listeners that is synchronized with all other animators in the system. There is no duration, interpolation, or object value-setting with this Animator. Instead, it is simply started, after which it proceeds to send out events on every animation frame to its TimeListener (if set), with information about this animator, the total elapsed time, and the elapsed time since the previous animation frame.

Summary

Nested classes

interface TimeAnimator.TimeListener

Implementors of this interface can set themselves as update listeners to a TimeAnimator instance to receive callbacks on every animation frame to receive the total time since the animator started and the delta time since the last frame. 

Inherited constants

int INFINITE

This value used used with the setRepeatCount(int) property to repeat the animation indefinitely.

int RESTART

When the animation reaches the end and repeatCount is INFINITE or a positive value, the animation restarts from the beginning.

int REVERSE

When the animation reaches the end and repeatCount is INFINITE or a positive value, the animation reverses direction on every iteration.

long DURATION_INFINITE

The value used to indicate infinite duration (e.g. when Animators repeat infinitely).

Public constructors

TimeAnimator()

Public methods

void setCurrentPlayTime(long playTime)

Sets the position of the animation to the specified point in time.

void setTimeListener(TimeAnimator.TimeListener listener)

Sets a listener that is sent update events throughout the life of an animation.

void start()

Starts this animation.

Inherited methods

void addUpdateListener(ValueAnimator.AnimatorUpdateListener listener)

Adds a listener to the set of listeners that are sent update events through the life of an animation.

static boolean areAnimatorsEnabled()

Returns whether animators are currently enabled, system-wide.

void cancel()

Cancels the animation.

ValueAnimator clone()

Creates and returns a copy of this object.

void end()

Ends the animation.

float getAnimatedFraction()

Returns the current animation fraction, which is the elapsed/interpolated fraction used in the most recent frame update on the animation.

Object getAnimatedValue()

The most recent value calculated by this ValueAnimator when there is just one property being animated.

Object getAnimatedValue(String propertyName)

The most recent value calculated by this ValueAnimator for propertyName.

long getCurrentPlayTime()

Gets the current position of the animation in time, which is equal to the current time minus the time that the animation started.

long getDuration()

Gets the length of the animation.

static float getDurationScale()

Returns the system-wide scaling factor for Animator-based animations.

static long getFrameDelay()

The amount of time, in milliseconds, between each frame of the animation.

TimeInterpolator getInterpolator()

Returns the timing interpolator that this ValueAnimator uses.

int getRepeatCount()

Defines how many times the animation should repeat.

int getRepeatMode()

Defines what this animation should do when it reaches the end.

long getStartDelay()

The amount of time, in milliseconds, to delay starting the animation after start() is called.

long getTotalDuration()

Gets the total duration of the animation, accounting for animation sequences, start delay, and repeating.

PropertyValuesHolder[] getValues()

Returns the values that this ValueAnimator animates between.

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.

static ValueAnimator ofArgb(int... values)

Constructs and returns a ValueAnimator that animates between color values.

static ValueAnimator ofFloat(float... values)

Constructs and returns a ValueAnimator that animates between float values.

static ValueAnimator ofInt(int... values)

Constructs and returns a ValueAnimator that animates between int values.

static ValueAnimator ofObject(TypeEvaluator<T> evaluator, Object... values)

Constructs and returns a ValueAnimator that animates between Object values.

static ValueAnimator ofPropertyValuesHolder(PropertyValuesHolder... values)

Constructs and returns a ValueAnimator that animates between the values specified in the PropertyValuesHolder objects.

void pause()

Pauses a running animation.

static boolean registerDurationScaleChangeListener(ValueAnimator.DurationScaleChangeListener listener)

Registers a DurationScaleChangeListener This listens for changes to the system-wide scaling factor for Animator-based animations.

void removeAllUpdateListeners()

Removes all listeners from the set listening to frame updates for this animation.

void removeUpdateListener(ValueAnimator.AnimatorUpdateListener listener)

Removes a listener from the set listening to frame updates for this animation.

void resume()

Resumes a paused animation, causing the animator to pick up where it left off when it was paused.

void reverse()

Plays the ValueAnimator in reverse.

void setCurrentFraction(float fraction)

Sets the position of the animation to the specified fraction.

void setCurrentPlayTime(long playTime)

Sets the position of the animation to the specified point in time.

ValueAnimator setDuration(long duration)

Sets the length of the animation.

void setEvaluator(TypeEvaluator<T> value)

The type evaluator to be used when calculating the animated values of this animation.

void setFloatValues(float... values)

Sets float values that will be animated between.

static void setFrameDelay(long frameDelay)

The amount of time, in milliseconds, between each frame of the animation.

void setIntValues(int... values)

Sets int values that will be animated between.

void setInterpolator(TimeInterpolator value)

The time interpolator used in calculating the elapsed fraction of this animation.

void setObjectValues(Object... values)

Sets the values to animate between for this animation.

void setRepeatCount(int value)

Sets how many times the animation should be repeated.

void setRepeatMode(int value)

Defines what this animation should do when it reaches the end.

void setStartDelay(long startDelay)

The amount of time, in milliseconds, to delay starting the animation after start() is called.

void setValues(PropertyValuesHolder... values)

Sets the values, per property, being animated between.

void start()

Starts this animation.

String toString()

Returns a string representation of the object.

static boolean unregisterDurationScaleChangeListener(ValueAnimator.DurationScaleChangeListener listener)

Unregisters a DurationScaleChangeListener.

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 cancel()

Cancels the animation.

Animator clone()

Creates and returns a copy of this object.

void end()

Ends the animation.

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.

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.

Object clone()

Creates and returns a copy of this object.

boolean equals(Object obj)

Indicates whether some other object is "equal to" this one.

void finalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

final Class<?> getClass()

Returns the runtime class of this Object.

int hashCode()

Returns a hash code value for the object.

final void notify()

Wakes up a single thread that is waiting on this object's monitor.

final void notifyAll()

Wakes up all threads that are waiting on this object's monitor.

String toString()

Returns a string representation of the object.

final void wait(long timeoutMillis, int nanos)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait(long timeoutMillis)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait()

Causes the current thread to wait until it is awakened, typically by being notified or interrupted.

Public constructors

TimeAnimator

public TimeAnimator ()

Public methods

setCurrentPlayTime

Added in API level 16
public void setCurrentPlayTime (long playTime)

Sets the position of the animation to the specified point in time. This time should be between 0 and the total duration of the animation, including any repetition. If the animation has not yet been started, then it will not advance forward after it is set to this time; it will simply set the time to this value and perform any appropriate actions based on that time. If the animation is already running, then setCurrentPlayTime() will set the current playing time to this value and continue playing from that point.

Parameters
playTime long: The time, in milliseconds, to which the animation is advanced or rewound.

setTimeListener

Added in API level 16
public void setTimeListener (TimeAnimator.TimeListener listener)

Sets a listener that is sent update events throughout the life of an animation.

Parameters
listener TimeAnimator.TimeListener: the listener to be set.

start

Added in API level 16
public void start ()

Starts this animation. If the animation has a nonzero startDelay, the animation will start running after that delay elapses. A non-delayed animation will have its initial value(s) set immediately, followed by calls to 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.