public class

Animation

extends Object
java.lang.Object
   ↳ com.neomades.ui.animation.Animation

Class Overview

This class provides functionalities to animate views. Animations are combinations of translations, rotations, scales and fade effects.

To animate a view, create an animation with animate(View). Once the animation created, various effects may be applied such as rotations, translations, zoom, etc. To start the animation, call the start() method.

Example of a 1s fade effect animation on an ImageLabel :

 ImageLabel image = new ImageLabel();
 image.setImage("MyImage.png");
 
 Animation animation = Animation.animate(image).setAlpha(0).setDuration(1000).start();
 

Summary

Public Methods
Animation alpha(float value)
This method will change the transparency of the View from its current value to the specified value.
Animation alphaBy(float value)
This method will change the transparency of the image from its current value by the specified value.
static Animation animate(View view)
This method creates an Animation object which can be used to animate specific properties on a View.
void cancel()
Cancels the animations if it is running.
long getDuration()
Returns the current duration of the animations.
long getStartDelay()
Returns the current startDelay of the animations.
Animation rotation(float value)
This method will cause the View to rotate to the specified value.
Animation rotationBy(float value)
This method will cause the View to rotate by the specified value.
Animation rotationX(float value)
This method will cause the View to rotate to the specified value around the x-axis.
Animation rotationXBy(float value)
This method will cause the View to rotate by the specified value around the x-axis.
Animation rotationY(float value)
This method will cause the View to rotate to the specified value around the y-axis.
Animation rotationYBy(float value)
This method will cause the View to rotate by the specified value around the y-axis.
Animation scaleX(float scaleFactor)
This method will cause the View to scale its width to the specified scale factor, based on the view's original width.
Animation scaleXBy(float scaleFactor)
This method will cause the View to scale its width by the specified scale factor, based on the view's current scale.
Animation scaleY(float scaleFactor)
This method will cause the View to scale its height to the specified scale factor, based on the view's original height.
Animation scaleYBy(float scaleFactor)
This method will cause the View to scale its height by the specified scale factor, based on the view's current scale.
Animation setDuration(long duration)
Sets the duration of the animation in milliseconds.
Animation setListener(AnimationListener listener)
Attaches a callback to listen state of this animation.
Animation setStartDelay(long startDelay)
Sets a startDelay for the animation.
void start()
Starts the animation immediately.
Animation translationX(float value)
This method will cause the View to translate to the specified value around the x-axis.
Animation translationXBy(float value)
This method will cause the View to translate by the specified value around the x-axis.
Animation translationY(float value)
This method will cause the View to translate to the specified value around the y-axis.
Animation translationYBy(float value)
This method will cause the View to translate by the specified value around the y-axis.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public Animation alpha (float value)

This method will change the transparency of the View from its current value to the specified value. The transparency can change from 1 (opaque) to 0 (transparent).

Parameters
value The value to be animated to.
Returns
  • This object, allowing calls to methods in this class to be chained.

public Animation alphaBy (float value)

This method will change the transparency of the image from its current value by the specified value. The transparency can change from 1 (opaque) to 0 (transparent).

Parameters
value The amount to be animated by, as an offset from the current value.
Returns
  • This object, allowing calls to methods in this class to be chained.

public static Animation animate (View view)

This method creates an Animation object which can be used to animate specific properties on a View.

Parameters
view View to animate.
Returns
  • The Animation associated with this View.
Throws
IllegalStateException Animation has already be started or cancelled
See Also

public void cancel ()

Cancels the animations if it is running. The animations will be stopped and the view will be reseted to its original position.

public long getDuration ()

Returns the current duration of the animations. If the duration was set on this object, that value is returned. Otherwise, the default value is returned.

Returns
  • The duration of animations, in milliseconds.

public long getStartDelay ()

Returns the current startDelay of the animations. If the startDelay was set on this object, that value is returned. Otherwise, the default value is returned.

Returns
  • The startDelay of animations, in milliseconds.

public Animation rotation (float value)

This method will cause the View to rotate to the specified value. Once the View has reached its angle, calling this method with the same value on the View will have no effect.

By default the center of the rotation is the middle of the view. It can be changed using setTransformOrigin(float, float).

Parameters
value The value to be animated to.
Returns
  • This object, allowing calls to methods in this class to be chained.

public Animation rotationBy (float value)

This method will cause the View to rotate by the specified value.

By default the center of the rotation is the middle of the view. It can be changed using setTransformOrigin(float, float).

Parameters
value The amount to be animated by, as an offset from the current value.
Returns
  • This object, allowing calls to methods in this class to be chained.

public Animation rotationX (float value)

This method will cause the View to rotate to the specified value around the x-axis.

By default the x-axis is in the middle of the view. Its position can be changed using setTransformOrigin(float, float).

Parameters
value The value to be animated to.
Returns
  • This object, allowing calls to methods in this class to be chained.

public Animation rotationXBy (float value)

This method will cause the View to rotate by the specified value around the x-axis.

By default the x-axis is in the middle of the view. Its position can be changed using setTransformOrigin(float, float).

Parameters
value The amount to be animated by, as an offset from the current value.
Returns
  • This object, allowing calls to methods in this class to be chained.

public Animation rotationY (float value)

This method will cause the View to rotate to the specified value around the y-axis.

By default the y-axis is in the middle of the view. Its position can be changed using setTransformOrigin(float, float).

Parameters
value The value to be animated to.
Returns
  • This object, allowing calls to methods in this class to be chained.

public Animation rotationYBy (float value)

This method will cause the View to rotate by the specified value around the y-axis.

By default the y-axis is in the middle of the view. Its position can be changed using setTransformOrigin(float, float).

Parameters
value The amount to be animated by, as an offset from the current value.
Returns
  • This object, allowing calls to methods in this class to be chained.

public Animation scaleX (float scaleFactor)

This method will cause the View to scale its width to the specified scale factor, based on the view's original width.

By default the origin point of the transformation is the center of the view. It can be changed using setTransformOrigin(float, float).

Parameters
scaleFactor The factor to apply to the view. A value greater than 1 will scale up the view, less than 1 will scale down the view
Returns
  • This object, allowing calls to methods in this class to be chained.

public Animation scaleXBy (float scaleFactor)

This method will cause the View to scale its width by the specified scale factor, based on the view's current scale.

By default the origin point of the transformation is the center of the view. It can be changed using setTransformOrigin(float, float).

Parameters
scaleFactor The factor to apply to the view. A value greater than 1 will scale up the view, less than 1 will scale down the view
Returns
  • This object, allowing calls to methods in this class to be chained.

public Animation scaleY (float scaleFactor)

This method will cause the View to scale its height to the specified scale factor, based on the view's original height.

By default the origin point of the transformation is the center of the view. It can be changed using setTransformOrigin(float, float).

Parameters
scaleFactor The factor to apply to the view. A value greater than 1 will scale up the view, less than 1 will scale down the view
Returns
  • This object, allowing calls to methods in this class to be chained.

public Animation scaleYBy (float scaleFactor)

This method will cause the View to scale its height by the specified scale factor, based on the view's current scale.

By default the origin point of the transformation is the center of the view. It can be changed using setTransformOrigin(float, float).

Parameters
scaleFactor The factor to apply to the view. A value greater than 1 will scale up the view, less than 1 will scale down the view
Returns
  • This object, allowing calls to methods in this class to be chained.

public Animation setDuration (long duration)

Sets the duration of the animation in milliseconds.

Parameters
duration The length of ensuing property animations, in milliseconds. The value cannot be negative.
Returns
  • This object, allowing calls to methods in this class to be chained.

public Animation setListener (AnimationListener listener)

Attaches a callback to listen state of this animation. This can be use to chain animation starting one when an other finishes.

Parameters
listener callback to call or null
Returns
  • This object, allowing calls to methods in this class to be chained.

public Animation setStartDelay (long startDelay)

Sets a startDelay for the animation.

Parameters
startDelay The delay of ensuing property animations, in milliseconds. The value cannot be negative.
Returns
  • This object, allowing calls to methods in this class to be chained.

public void start ()

Starts the animation immediately.

public Animation translationX (float value)

This method will cause the View to translate to the specified value around the x-axis.

Parameters
value The value to be animated to.
Returns
  • This object, allowing calls to methods in this class to be chained.

public Animation translationXBy (float value)

This method will cause the View to translate by the specified value around the x-axis.

Parameters
value The amount to be animated by, as an offset from the current value.
Returns
  • This object, allowing calls to methods in this class to be chained.

public Animation translationY (float value)

This method will cause the View to translate to the specified value around the y-axis.

Parameters
value The value to be animated to.
Returns
  • This object, allowing calls to methods in this class to be chained.

public Animation translationYBy (float value)

This method will cause the View to translate by the specified value around the y-axis.

Parameters
value The amount to be animated by, as an offset from the current value.
Returns
  • This object, allowing calls to methods in this class to be chained.