net.rim.device.api.animation
Interface Animatable

All Known Implementing Classes:
AnimatedScalar, AnimatedVector, Color3f, Color4f, Quaternion4f, Transform2D, Transform3D, Vector2f, Vector3f, Vector4f, ActivityImageField

public interface Animatable

Defines the interface that an object must support so it can be used as the target of an Animation.

Before implementing your own custom Animatable objects, you should consider using AnimatedScalar and AnimatedVector, which implement Animatable.

The net.rim.device.api.math package also includes several built-in Animatable objects such as colors, transformations, vectors and quaternions.

The Animatable and its defined animatable properties are targets for animations. The Animation framework uses the Animatable by calling Animatable.getAnimationValue(int, AnimationValue) to retrieve the current value of a target property and Animatable.setAnimationValue(int, AnimationValue) to update the value of a target property.

Classes that implement the Animatable interface must identify the properties that support animation by defining integer constants to represent each of them.

Implementing a custom Animatable object.

 import net.rim.device.api.animation.*;
 
 public class MyAnimatable implements Animatable
 {
      public static final int ANIMATION_PROPERTY_XY = 0;
      public static final int ANIMATION_PROPERTY_WIDTH = 1;
      public static final int ANIMATION_PROPERTY_HEIGHT = 2;
      public static final int ANIMATION_PROPERTY_COUNT = 3;
      private static final int[] ANIMATION_PROPERTY_COMPONENT_COUNTS = { 2, 1, 1 };
      
      public float x, y, width, height;
      
      public MyAnimatable(float x, float y, float height, float width) 
      {
          this.x = x;
          this.y = y;
          this.width = width;
          this.height = height;
      }
      
      public void getAnimationValue(int property, AnimationValue value)
      {
          switch(property) 
          {
              case ANIMATION_PROPERTY_XY:
                  value.setFloat(0, this.x);
                  value.setFloat(1, this.y);
                  break;
             case ANIMATION_PROPERTY_WIDTH:
                  value.setFloat(0, this.width);
                  break;
              case ANIMATION_PROPERTY_HEIGHT:
                  value.setFloat(0, this.height);
                  break;
          }
      }
      
      public void setAnimationValue(int property, AnimationValue value)
      {
          switch(property) 
          {
              case ANIMATION_PROPERTY_XY:
                  this.x = value.getFloat(0);
                  this.y = value.getFloat(1);
                  break;
              case ANIMATION_PROPERTY_WIDTH:
                  this.width = value.getFloat(0);
                  break;
              case ANIMATION_PROPERTY_HEIGHT:
                  this.height = value.getFloat(0);
                  break;
          }
          
          // Notify the view that the object is dirty and needs rendering
          _screen.invalidate();
      }

      public int getAnimationPropertyComponentCount(int property)
      {
          if (property >= 0 && property < ANIMATION_PROPERTY_COUNT)
              return ANIMATION_PROPERTY_COMPONENT_COUNTS[property];
          return 0;
      }
 }
 

Since:
BlackBerry API 6.0.0

Method Summary
 int getAnimationPropertyComponentCount(int property)
           Gets the number of components of the specified property.
 void getAnimationValue(int property, AnimationValue value)
           Gets the value or values of the specified property.
 void setAnimationValue(int property, AnimationValue value)
           Sets the value or values of the specified property.
 



Method Detail

getAnimationValue

void getAnimationValue(int property,
                       AnimationValue value)

Gets the value or values of the specified property.

Used by the Animation framework to get the values of the specified property on the Animatable. The implementer must set the value of the specified target property in the AnimationValue parameter.

Parameters:
property - The property to get the current value or values of.
value - An AnimationValue used to store the returned property values.
See Also:
AnimationValue
Since:
BlackBerry API 6.0.0

setAnimationValue

void setAnimationValue(int property,
                       AnimationValue value)

Sets the value or values of the specified property.

Used by the Animation framework to update the value or values of the specified target property on the Animatable with the currently calculated animation value. The implementer must update the current value or values of the given target property with the values in the AnimationValue parameter.

Parameters:
property - The property to set the current value or values of.
value - The AnimationValue used to specify the value or values to set.
See Also:
AnimationValue
Since:
BlackBerry API 6.0.0

getAnimationPropertyComponentCount

int getAnimationPropertyComponentCount(int property)

Gets the number of components of the specified property.

The implementer must define the component size of every animatable property defined for the Animatable.

Parameters:
property - The property to retrieve the component count for.
Returns:
The number of components comprising the specified property.
Since:
BlackBerry API 6.0.0





Copyright 1999-2011 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Java is a trademark of Oracle America Inc. in the US and other countries.
Legal