public class

Shape.Animator

extends Object
java.lang.Object
   ↳ sofia.graphics.Shape.Animator<AnimatorType extends sofia.graphics.Shape.Animator<AnimatorType>>
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

Provides animation support for shapes. Most uses of this class will not need to reference it directly; for example, an animation can be constructed and played by chaining method calls directly:

     shape.animate(500).color(Color.blue).alpha(128).play();
In situations where the type of the class must be referenced directly (for example, when one is passed to an event handler like onAnimationDone), referring to the name of that type can be somewhat awkward due to the use of some Java generics tricks to ensure that the methods chain properly. In nearly all cases, it is reasonable to use a "?" wildcard in place of the generic parameter:
     Shape.Animator<?> anim = shape.animate(500).color(Color.blue);
     anim.play();

Summary

Protected Constructors
Shape.Animator(long duration)
Creates a new animator for the specified shape.
Public Methods
boolean advanceTo(long time)
This method is intended for internal use.
AnimatorType alpha(int alpha)
Sets the final alpha (opacity) of the shape when the animation ends.
AnimatorType bounds(RectF bounds)
Sets the final bounds of the shape when the animation ends.
AnimatorType color(Color color)
Sets the final color of the shape when the animation ends.
AnimatorType delay(long newDelay)
Sets the delay, in milliseconds, that the animation will wait after the play() method is called until it actually starts.
long getDelay()
Gets the delay, in milliseconds, that this animation will wait (or did wait) before starting.
long getDuration()
Gets the duration of this animation in milliseconds.
Shape getShape()
Gets the shape that the receiver is animating.
boolean isBackward()
Gets a value indicating whether the animation is playing backward.
boolean isForward()
Gets a value indicating whether the animation is playing forward.
boolean isPlaying()
Gets a value indicating whether the animation is currently playing, either forward or backward.
AnimatorType moveBy(float dx, float dy)
Sets the final position of the shape when the animation ends as a relative shift from the shape's position when the animation starts.
AnimatorType moveBy(MotionStep motionStep)
AnimatorType moveBy(float dx, float dy, float ax, float ay)
AnimatorType name(String newName)

Sets the name of this animation.

AnimatorType oscillate()
Causes the animation to oscillate (from start to end and back to start) until stopped.
void play()
Starts the animation.
AnimatorType position(float x, float y)
Sets the final position of the shape when the animation ends.
AnimatorType position(PointF point)
Sets the final position of the shape when the animation ends.
AnimatorType removeWhenComplete()

Causes the shape to be automatically removed from its view when the animation completes.

AnimatorType repeat()
Causes the animation to repeat until stopped.
AnimatorType repeatMode(RepeatMode mode)
Sets the repeat mode for this animation.
AnimatorType rotation(float rotation)

Sets the final rotation, in degrees clockwise, of the shape when the animation ends.

void stop()
Stops the animation.
AnimatorType timing(Interpolator newInterpolator)
Sets the timing function (interpolator) that determines how the animation behaves during execution.
AnimatorType x(float x)
Sets the final x-coordinate of the shape when the animation ends.
AnimatorType y(float y)
Sets the final y-coordinate of the shape when the animation ends.
Protected Methods
void addTransformer(PropertyTransformer transformer)
Adds a property transformer to the list of those that will be applied each time the animation advances.
[Expand]
Inherited Methods
From class java.lang.Object

Protected Constructors

protected Shape.Animator (long duration)

Creates a new animator for the specified shape. Users cannot call call this constructor directly; instead, they need to use the Shape#animate(long) method to get an animator object.

Parameters
duration the length of one pass of the animation, in milliseconds

Public Methods

public boolean advanceTo (long time)

This method is intended for internal use.

public AnimatorType alpha (int alpha)

Sets the final alpha (opacity) of the shape when the animation ends.

Parameters
alpha the final alpha (opacity) of the shape when the animation ends, from 0 (fully transparent) to 255 (fully opaque)
Returns
  • this animator, for method chaining

public AnimatorType bounds (RectF bounds)

Sets the final bounds of the shape when the animation ends.

Parameters
bounds the final bounds of the shape when the animation ends
Returns
  • this animator, for method chaining

public AnimatorType color (Color color)

Sets the final color of the shape when the animation ends.

Parameters
color the final color of the shape when the animation ends
Returns
  • this animator, for method chaining

public AnimatorType delay (long newDelay)

Sets the delay, in milliseconds, that the animation will wait after the play() method is called until it actually starts.

Parameters
newDelay the delay, in milliseconds, before the animation starts
Returns
  • this animator, for method chaining

public long getDelay ()

Gets the delay, in milliseconds, that this animation will wait (or did wait) before starting.

Returns
  • the delay, in milliseconds, that this animation will (or did) wait before starting

public long getDuration ()

Gets the duration of this animation in milliseconds.

Returns
  • the duration of this animation in milliseconds

public Shape getShape ()

Gets the shape that the receiver is animating.

Returns
  • the shape that the receiver is animating

public boolean isBackward ()

Gets a value indicating whether the animation is playing backward.

Returns
  • true if the animation is playing backward, otherwise false

public boolean isForward ()

Gets a value indicating whether the animation is playing forward.

Returns
  • true if the animation is playing forward, otherwise false

public boolean isPlaying ()

Gets a value indicating whether the animation is currently playing, either forward or backward.

Returns
  • true if the animation is playing, otherwise false

public AnimatorType moveBy (float dx, float dy)

Sets the final position of the shape when the animation ends as a relative shift from the shape's position when the animation starts.

Parameters
dx the horizontal amount to have shifted the shape when the animation ends
dy the vertical amount to have shifted the shape when the animation ends
Returns
  • this animator, for method chaining

public AnimatorType moveBy (MotionStep motionStep)

public AnimatorType moveBy (float dx, float dy, float ax, float ay)

public AnimatorType name (String newName)

Sets the name of this animation. You should set the name of an animation if you wish to be notified about events related to that animation. This name is used to determine the name of the handler method to call on the shape or the controller when animation begins, repeats, or ends.

For example, if the animation has the name "bounce", then the following notifications will be sent to the shape and the controller, if those methods exist:

  • bounceAnimationStarted(Shape.Animator<?>)
  • bounceAnimationStarted()
  • bounceAnimationRepeated(Shape.Animator<?>)
  • bounceAnimationStarted()
  • bounceAnimationEnded(Shape.Animator<?>)
  • bounceAnimationEnded()

Therefore, the name of an animation should be a valid Java identifier, preferably starting with a lowercase letter.

The name of the animation must be set in order to receive notifications about it.

Parameters
newName the name of the animation
Returns
  • this animator, for method chaining

public AnimatorType oscillate ()

Causes the animation to oscillate (from start to end and back to start) until stopped. This method is provided as shorthand, equivalent to repeatMode(RepeatMode.OSCILLATE).

Returns
  • this animator, for chaining method calls

public void play ()

Starts the animation.

public AnimatorType position (float x, float y)

Sets the final position of the shape when the animation ends.

Parameters
x the final x-coordinate of the shape when the animation ends
y the final y-coordinate of the shape when the animation ends
Returns
  • this animator, for method chaining

public AnimatorType position (PointF point)

Sets the final position of the shape when the animation ends.

Parameters
point the final position of the shape when the animation ends
Returns
  • this animator, for method chaining

public AnimatorType removeWhenComplete ()

Causes the shape to be automatically removed from its view when the animation completes. This is useful for animations that cause a shape to fade out, where you want it to disappear for good when done.

Note that the shape will only be removed if the animation ends on its own when its time expires; it will not be removed if you end the animation prematurely by calling Shape#stopAnimation(). This also means that this method will have no effect if the animation is repeating or oscillating.

Returns
  • this animator, for chaining method calls

public AnimatorType repeat ()

Causes the animation to repeat until stopped. This method is provided as shorthand, equivalent to repeatMode(RepeatMode.REPEAT).

Returns
  • this animator, for chaining method calls

public AnimatorType repeatMode (RepeatMode mode)

Sets the repeat mode for this animation. See the RepeatMode enumeration for possible values.

Parameters
mode the repeat mode for the animation
Returns
  • this animator, for chaining method calls

public AnimatorType rotation (float rotation)

Sets the final rotation, in degrees clockwise, of the shape when the animation ends. Negative values will create a counter-clockwise rotation.

A shape can be made to rotate completely multiple times by providing values higher than 360 to this method. For example, passing 360 would cause the shape to make one full rotation over the duration of the animation, passing 720 would cause it to make two full rotations, and so forth.

Parameters
rotation the final rotation, in degrees clockwise (negative values will rotate counter-clockwise)
Returns
  • this animator, for method chaining

public void stop ()

Stops the animation.

public AnimatorType timing (Interpolator newInterpolator)

Sets the timing function (interpolator) that determines how the animation behaves during execution. A number of pre-written timing functions can be found as static methods in the Timings class.

Parameters
newInterpolator the timing function (interpolator) that determines how the animation behaves during execution
Returns
  • this animator, for method chaining

public AnimatorType x (float x)

Sets the final x-coordinate of the shape when the animation ends.

Returns
  • this animator, for method chaining

public AnimatorType y (float y)

Sets the final y-coordinate of the shape when the animation ends.

Parameters
y the final y-coordinate of the shape when the animation ends
Returns
  • this animator, for method chaining

Protected Methods

protected void addTransformer (PropertyTransformer transformer)

Adds a property transformer to the list of those that will be applied each time the animation advances.

Parameters
transformer the property transformer