javax.microedition.m2g
Class SVGAnimator

java.lang.Object
  extended by javax.microedition.m2g.SVGAnimator

public abstract class SVGAnimator
extends Object

The SVGAnimator class handles automatic rendering of updates and animations in an SVGImage to a target user interface (UI) component. The target component type depends on the Java profile this specification is implemented on, as described in the createAnimator and getTargetComponent methods documentation.

In this implementation, the target component is a View. As the construction of a View requires a Context , a new factory have been added with a context parameter.

The Context may also be set in the animatorContext global variable: all the SVGAnimators created by a Thread will use the context set in animatorContext.


Field Summary
static ThreadLocal<Context> animatorContext
          Android context management.
 
Constructor Summary
SVGAnimator()
           
 
Method Summary
static SVGAnimator createAnimator(SVGImage svgImage)
          Create a new SVGAnimator for the specified SVGImage and the current Context of the current thread.
static SVGAnimator createAnimator(SVGImage svgImage, String componentBaseClass)
          Create a new SVGAnimator for the specified SVGImage and the current Context of the current thread.
static SVGAnimator createAnimator(SVGImage svgImage, String componentBaseClass, Context context)
          Create a new SVGAnimator for the specified SVGImage.
abstract  Object getTargetComponent()
          Retrieve the animator's target component.
abstract  float getTimeIncrement()
          Get the current time increment for animation rendering.
abstract  void invokeAndWait(Runnable runnable)
          Invoke the Runnable in the Document update thread and return only after this Runnable has finished.
abstract  void invokeLater(Runnable runnable)
          Schedule execution of the input Runnable in the update thread at a later time.
abstract  void pause()
          Transition this SVGAnimator to the paused state.
abstract  void play()
          Transition this SVGAnimator to the playing state.
abstract  void setSVGEventListener(SVGEventListener svgEventListener)
          Associate the specified SVGEventListener with this SVGAnimator.
abstract  void setTimeIncrement(float timeIncrement)
          Set the time increment to be used for animation rendering.
abstract  void stop()
          Transition this SVGAnimator to the stopped state.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

animatorContext

public static final ThreadLocal<Context> animatorContext
Android context management. Context must be set in this field before creating a new SVGAnimator with the JSR-226 standard SVGAnimator factories. The variable is a ThreadLocal, so a thread creating an animator must first set the context and animators may be created for different contexts in parallel by different threads.

Constructor Detail

SVGAnimator

public SVGAnimator()
Method Detail

createAnimator

public static SVGAnimator createAnimator(SVGImage svgImage)
Create a new SVGAnimator for the specified SVGImage and the current Context of the current thread.

See Also:
createAnimator(javax.microedition.m2g.SVGImage, java.lang.String, android.content.Context)

createAnimator

public static SVGAnimator createAnimator(SVGImage svgImage,
                                         String componentBaseClass)
Create a new SVGAnimator for the specified SVGImage and the current Context of the current thread.

See Also:
createAnimator(javax.microedition.m2g.SVGImage, java.lang.String, android.content.Context)

createAnimator

public static SVGAnimator createAnimator(SVGImage svgImage,
                                         String componentBaseClass,
                                         Context context)
Create a new SVGAnimator for the specified SVGImage. This implementation adds a new animator factory that takes the target View context.

Parameters:
svgImage - the SVGImage to be rendered by this animator.
componentBaseClass - the desired base class for the component associated with the animator (useful only for platforms supporting multiple UI component frameworks). When null, this is equivalent to invoking createAnimator with the svgImage parameter only.
context - Android context for the target View
Returns:
the newly created SVGAnimator instance.
Throws:
NullPointerException - if svgImage or context is null.
IllegalArgumentException - if the specified componentBaseClass is not supported by the implementation.

setSVGEventListener

public abstract void setSVGEventListener(SVGEventListener svgEventListener)
Associate the specified SVGEventListener with this SVGAnimator.

Parameters:
svgEventListener - the SVGEventListener that will receive events forwarded by this SVGAnimator. If null, events will not be forwarded by the SVGAnimator.

setTimeIncrement

public abstract void setTimeIncrement(float timeIncrement)
Set the time increment to be used for animation rendering.

Parameters:
timeIncrement - the minimal period of time, in seconds, that should elapse between frame. Must be greater than zero.
Throws:
IllegalArgumentException - if timeIncrement is less than or equal to zero.
See Also:
getTimeIncrement()

getTimeIncrement

public abstract float getTimeIncrement()
Get the current time increment for animation rendering. The SVGAnimator increments the SVG document's current time by this amount upon each rendering. The default value is 0.1 (100 milliseconds).

Returns:
the current time increment, in seconds, used for animation rendering.
See Also:
setTimeIncrement(float)

play

public abstract void play()
Transition this SVGAnimator to the playing state. In the playing state, both Animation and SVGImage updates cause rendering updates. Note that in the playing state, when the document's current time changes, the animator will seek to the new time, and continue to play animations from this place.

Throws:
IllegalStateException - if the animator is not currently in the stopped or paused state.

pause

public abstract void pause()
Transition this SVGAnimator to the paused state. The SVGAnimator stops advancing the document's current time automatically (see the SVGDocument's setCurrentTime method). In consequence, animation playback will be paused until another call to the play method is made, at which points animations will resume from the document's current time. SVGImage updates (through API calls) cause a rendering update while the SVGAnimator is in the paused state.

Throws:
IllegalStateException - if the animator is not in the playing state.

stop

public abstract void stop()
Transition this SVGAnimator to the stopped state. In this state, no rendering updates are performed.

Throws:
IllegalStateException - if the animator is not in the playing or paused state.

getTargetComponent

public abstract Object getTargetComponent()
Retrieve the animator's target component.

Returns:
the target component associated with the animator, a View
See Also:
createAnimator(javax.microedition.m2g.SVGImage)

invokeAndWait

public abstract void invokeAndWait(Runnable runnable)
                            throws InterruptedException
Invoke the Runnable in the Document update thread and return only after this Runnable has finished.

Parameters:
runnable - the new Runnable to invoke.
Throws:
InterruptedException - if the current thread is waiting, sleeping, or otherwise paused for a long time and another thread interrupts it.
NullPointerException - if runnable is null.
IllegalStateException - if the animator is in the stopped state.

invokeLater

public abstract void invokeLater(Runnable runnable)
Schedule execution of the input Runnable in the update thread at a later time.

Parameters:
runnable - the new Runnable to execute in the Document's update thread when time permits.
Throws:
NullPointerException - if runnable is null.
IllegalStateException - if the animator is in the stopped state.


Copyright © 2010 JSRs for Android team. All Rights Reserved.