×
Namespaces

Variants
Actions
(Difference between revisions)

Creating Simple Animations with Java ME

From Nokia Developer Wiki
Jump to: navigation, search
Tomi_ (Talk | contribs)
m (Tomi -)
Tomi_ (Talk | contribs)
m (Tomi -)
Line 25: Line 25:
 
== Introduction ==
 
== Introduction ==
  
 +
The standard LCDUI framework has no out-of-the-box animations. [http://www.developer.nokia.com/Resources/Library/LWUIT/#!index.html LWUIT] does provide them, but in case you want to stick with the LCDUI you have no choice but to implement them yourself. Nokia UI API provides the [http://www.developer.nokia.com/Resources/Library/Java/_zip/GUID-237420DE-CCBE-4A74-A129-572E0708D428/com/nokia/mid/ui/frameanimator/package-summary.html FrameAnimator package], but that is not generic and has dependency to the user interface (UI) components. This article studies implementing a simple, generic, UI independent animation framework that is both efficient and easy to use.
  
 
== Implementation ==
 
== Implementation ==

Revision as of 16:18, 27 June 2013

This article explains how to ...

Article Metadata
CompatibilityArticle
Created: (28 Jun 2013)
Last edited: Tomi_ (27 Jun 2013)

Contents

Introduction

The standard LCDUI framework has no out-of-the-box animations. LWUIT does provide them, but in case you want to stick with the LCDUI you have no choice but to implement them yourself. Nokia UI API provides the FrameAnimator package, but that is not generic and has dependency to the user interface (UI) components. This article studies implementing a simple, generic, UI independent animation framework that is both efficient and easy to use.

Implementation

Architecture

Animation-fw-architecture.png

Easing curves

Usage

public class MyCanvas
extends Canvas
implements AnimationListener
{
// Constants
...
private static final int ANIMATION_DURATION = 500;
private static final int EASING_CURVE = IntAnimation.EASING_CURVE_INOUTQUAD;
 
// Members
...
private IntAnimation _animation = null;
...
 
/**
* Constructor.
*/

public MyCanvas() {
super();
...
_animation = new IntAnimation();
_animation.setListener(this);
...
    /**
* @see AnimationListener#onAnimatedValueChanged(int)
*/

public void onAnimatedValueChanged(int value) {
// Handle the value
...
repaint();
}
 
/**
* @see AnimationListener#onAnimationStateChanged(int)
*/

public void onAnimationStateChanged(int state) {
switch (state) {
case IntAnimation.STATE_RUNNING:
...
break;
case IntAnimation.STATE_STOPPED:
...
break;
case IntAnimation.STATE_FINISHED:
...
break;
default:
break;
}
}

Then just let it rip:

boolean started = _animation.start(from, to, ANIMATION_DURATION, EASING_CURVE))
 
if (!started) {
// Failed to start the animation! Handle this situation gracefully - maybe by just jumping to the "to" point.
}

Summary

141 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×