com.nineoldandroids.animation
Class AnimatorSet

java.lang.Object
  extended by com.nineoldandroids.animation.Animator
      extended by com.nineoldandroids.animation.AnimatorSet
All Implemented Interfaces:
Cloneable

public final class AnimatorSet
extends Animator

This class plays a set of Animator objects in the specified order. Animations can be set up to play together, in sequence, or after a specified delay.

There are two different approaches to adding animations to a AnimatorSet: either the playTogether() or playSequentially() methods can be called to add a set of animations all at once, or the play(Animator) can be used in conjunction with methods in the Builder class to add animations one by one.

It is possible to set up a AnimatorSet with circular dependencies between its animations. For example, an animation a1 could be set up to start before animation a2, a2 before a3, and a3 before a1. The results of this configuration are undefined, but will typically result in none of the affected animations being played. Because of this (and because circular dependencies do not make logical sense anyway), circular dependencies should be avoided, and the dependency flow of animations should only be in one direction.


Nested Class Summary
 class AnimatorSet.Builder
          The Builder object is a utility class to facilitate adding animations to a AnimatorSet along with the relationships between the various animations.
 
Nested classes/interfaces inherited from class com.nineoldandroids.animation.Animator
Animator.AnimatorListener
 
Constructor Summary
AnimatorSet()
           
 
Method Summary
 void cancel()
          Cancels the animation.
 AnimatorSet clone()
           
 void end()
          Ends the animation.
 ArrayList<Animator> getChildAnimations()
          Returns the current list of child Animator objects controlled by this AnimatorSet.
 long getDuration()
          Gets the length of each of the child animations of this AnimatorSet.
 long getStartDelay()
          The amount of time, in milliseconds, to delay starting the animation after start() is called.
 boolean isRunning()
          Returns true if any of the child animations of this AnimatorSet have been started and have not yet ended.
 boolean isStarted()
          Returns whether this Animator has been started and not yet ended.
 AnimatorSet.Builder play(Animator anim)
          This method creates a Builder object, which is used to set up playing constraints.
 void playSequentially(Animator... items)
          Sets up this AnimatorSet to play each of the supplied animations when the previous animation ends.
 void playSequentially(List<Animator> items)
          Sets up this AnimatorSet to play each of the supplied animations when the previous animation ends.
 void playTogether(Animator... items)
          Sets up this AnimatorSet to play all of the supplied animations at the same time.
 void playTogether(Collection<Animator> items)
          Sets up this AnimatorSet to play all of the supplied animations at the same time.
 AnimatorSet setDuration(long duration)
          Sets the length of each of the current child animations of this AnimatorSet.
 void setInterpolator(Interpolator interpolator)
          Sets the TimeInterpolator for all current child animations of this AnimatorSet.
 void setStartDelay(long startDelay)
          The amount of time, in milliseconds, to delay starting the animation after start() is called.
 void setTarget(Object target)
          Sets the target object for all current child animations of this AnimatorSet that take targets (ObjectAnimator and AnimatorSet).
 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.
 
Methods inherited from class com.nineoldandroids.animation.Animator
addListener, getListeners, removeAllListeners, removeListener
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AnimatorSet

public AnimatorSet()
Method Detail

playTogether

public void playTogether(Animator... items)
Sets up this AnimatorSet to play all of the supplied animations at the same time.

Parameters:
items - The animations that will be started simultaneously.

playTogether

public void playTogether(Collection<Animator> items)
Sets up this AnimatorSet to play all of the supplied animations at the same time.

Parameters:
items - The animations that will be started simultaneously.

playSequentially

public void playSequentially(Animator... items)
Sets up this AnimatorSet to play each of the supplied animations when the previous animation ends.

Parameters:
items - The animations that will be started one after another.

playSequentially

public void playSequentially(List<Animator> items)
Sets up this AnimatorSet to play each of the supplied animations when the previous animation ends.

Parameters:
items - The animations that will be started one after another.

getChildAnimations

public ArrayList<Animator> getChildAnimations()
Returns the current list of child Animator objects controlled by this AnimatorSet. This is a copy of the internal list; modifications to the returned list will not affect the AnimatorSet, although changes to the underlying Animator objects will affect those objects being managed by the AnimatorSet.

Returns:
ArrayList The list of child animations of this AnimatorSet.

setTarget

public void setTarget(Object target)
Sets the target object for all current child animations of this AnimatorSet that take targets (ObjectAnimator and AnimatorSet).

Overrides:
setTarget in class Animator
Parameters:
target - The object being animated

setInterpolator

public void setInterpolator(Interpolator interpolator)
Sets the TimeInterpolator for all current child animations of this AnimatorSet.

Specified by:
setInterpolator in class Animator
Parameters:
interpolator - the interpolator to be used by each child animation of this AnimatorSet

play

public AnimatorSet.Builder play(Animator anim)
This method creates a Builder object, which is used to set up playing constraints. This initial play() method tells the Builder the animation that is the dependency for the succeeding commands to the Builder. For example, calling play(a1).with(a2) sets up the AnimatorSet to play a1 and a2 at the same time, play(a1).before(a2) sets up the AnimatorSet to play a1 first, followed by a2, and play(a1).after(a2) sets up the AnimatorSet to play a2 first, followed by a1.

Note that play() is the only way to tell the Builder the animation upon which the dependency is created, so successive calls to the various functions in Builder will all refer to the initial parameter supplied in play() as the dependency of the other animations. For example, calling play(a1).before(a2).before(a3) will play both a2 and a3 when a1 ends; it does not set up a dependency between a2 and a3.

Parameters:
anim - The animation that is the dependency used in later calls to the methods in the returned Builder object. A null parameter will result in a null Builder return value.
Returns:
Builder The object that constructs the AnimatorSet based on the dependencies outlined in the calls to play and the other methods in the Builder

cancel

public void cancel()
Cancels the animation. Unlike Animator.end(), cancel() causes the animation to stop in its tracks, sending an Animator.AnimatorListener to its listeners, followed by an Animator.AnimatorListener message.

This method must be called on the thread that is running the animation.

Note that canceling a AnimatorSet also cancels all of the animations that it is responsible for.

Overrides:
cancel in class Animator

end

public void end()
Ends the animation. This causes the animation to assign the end value of the property being animated, then calling the Animator.AnimatorListener method on its listeners.

This method must be called on the thread that is running the animation.

Note that ending a AnimatorSet also ends all of the animations that it is responsible for.

Overrides:
end in class Animator

isRunning

public boolean isRunning()
Returns true if any of the child animations of this AnimatorSet have been started and have not yet ended.

Specified by:
isRunning in class Animator
Returns:
Whether this AnimatorSet has been started and has not yet ended.

isStarted

public boolean isStarted()
Description copied from class: Animator
Returns whether this Animator has been started and not yet ended. This state is a superset of the state of Animator.isRunning(), because an Animator with a nonzero startDelay will return true for Animator.isStarted() during the delay phase, whereas Animator.isRunning() will return true only after the delay phase is complete.

Overrides:
isStarted in class Animator
Returns:
Whether the Animator has been started and not yet ended.

getStartDelay

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

Specified by:
getStartDelay in class Animator
Returns:
the number of milliseconds to delay running the animation

setStartDelay

public void setStartDelay(long startDelay)
The amount of time, in milliseconds, to delay starting the animation after start() is called.

Specified by:
setStartDelay in class Animator
Parameters:
startDelay - The amount of the delay, in milliseconds

getDuration

public long getDuration()
Gets the length of each of the child animations of this AnimatorSet. This value may be less than 0, which indicates that no duration has been set on this AnimatorSet and each of the child animations will use their own duration.

Specified by:
getDuration in class Animator
Returns:
The length of the animation, in milliseconds, of each of the child animations of this AnimatorSet.

setDuration

public AnimatorSet setDuration(long duration)
Sets the length of each of the current child animations of this AnimatorSet. By default, each child animation will use its own duration. If the duration is set on the AnimatorSet, then each child animation inherits this duration.

Specified by:
setDuration in class Animator
Parameters:
duration - The length of the animation, in milliseconds, of each of the child animations of this AnimatorSet.

setupStartValues

public void setupStartValues()
Description copied from class: Animator
This method tells the object to use appropriate information to extract starting values for the animation. For example, a AnimatorSet object will pass this call to its child objects to tell them to set up the values. A ObjectAnimator object will use the information it has about its target object and PropertyValuesHolder objects to get the start values for its properties. An ValueAnimator object will ignore the request since it does not have enough information (such as a target object) to gather these values.

Overrides:
setupStartValues in class Animator

setupEndValues

public void setupEndValues()
Description copied from class: Animator
This method tells the object to use appropriate information to extract ending values for the animation. For example, a AnimatorSet object will pass this call to its child objects to tell them to set up the values. A ObjectAnimator object will use the information it has about its target object and PropertyValuesHolder objects to get the start values for its properties. An ValueAnimator object will ignore the request since it does not have enough information (such as a target object) to gather these values.

Overrides:
setupEndValues in class Animator

start

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 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.

Starting this AnimatorSet will, in turn, start the animations for which it is responsible. The details of when exactly those animations are started depends on the dependency relationships that have been set up between the animations.

Overrides:
start in class Animator

clone

public AnimatorSet clone()
Overrides:
clone in class Animator