de.enough.polish.ui
Class ScreenChangeAnimation

java.lang.Object
  extended by javax.microedition.lcdui.Displayable
      extended by javax.microedition.lcdui.Canvas
          extended by de.enough.polish.ui.ScreenChangeAnimation
All Implemented Interfaces:
AccessibleCanvas, java.lang.Runnable
Direct Known Subclasses:
BottomScreenChangeAnimation, BottomShutterScreenChangeAnimation, BwToColorScreenChangeAnimation, CageScreenChangeAnimation, CardScreenChangeAnimation, CubeScreenChangeAnimation, DancingPixelScreenChangeAnimation, DiagonalScreenChangeAnimation, DisplayScreenChangeAnimation, DominoScreenChangeAnimation, FadeOutFadeInScreenChangeAnimation, FadeScreenChangeAnimation, FlashScreenChangeAnimation, GradientScreenChangeAnimation, LeftScreenChangeAnimation, LeftShutterScreenChangeAnimation, NewWaveScreenChangeAnimation, PaperScreenChangeAnimation, ParticleScreenChangeAnimation, PixelScreenChangeAnimation, RainScreenChangeAnimation, RightScreenChangeAnimation, RightShutterScreenChangeAnimation, Rotate3DScreenChangeAnimation, RotateScreenChangeAnimation, ScaleScreenChangeAnimation, SqueezeScreenChangeAnimation, TopScreenChangeAnimation, TopShutterScreenChangeAnimation, VerticalFlashScreenChangeAnimation, ZoomBothScreenChangeAnimation, ZoomInAndHideScreenChangeAnimation, ZoomOutScreenChangeAnimation

public abstract class ScreenChangeAnimation
extends javax.microedition.lcdui.Canvas
implements java.lang.Runnable, AccessibleCanvas

Paints a transition of two screens for a nice effect.

Using a screen change animation is easy:
Use the screen-change-animation CSS attribute for specifying which animation you would like to have. You can also finetune some animations. Note that some animations have certain conditions like support of the MIDP 2.0 profile.

 screen-change-animation: left;
 left-screen-change-animation-speed: 5;
 

You can easily implement your own screen change animations by following these steps:

  1. Extend de.enough.polish.ui.ScreenChangeAnimation
  2. Implement the animate() method for doing the animation, use the fields lastCanvasImage and nextCanvasImage for your manipulation and consider the isForwardAnimation field.
  3. Implement the paintAnimation(Graphics) method.
  4. Override the show() method if you need to get parameters from the style.
  5. In case you want to manipulate the RGB data, you should set the useNextCanvasRgb and/or useLastCanvasRgb fields to true - you can then access the nextCanvasRgb and lastCanvasRgb fields for manupulating the data.

You can now use your animation by specifying the screen-change-animation CSS attribute accordingly:

 screen-change-animation: new com.company.ui.MyScreenChangeAnimation();
 

You can also ease the usage by registering your animation in ${polish.home}/custom-css-attributes:

 <attribute name="screen-change-animation">
                <mapping from="myanimation" to="com.company.ui.MyScreenChangeAnimation()" />
 </attribute>
 

Now your animation is easier to use:

 screen-change-animation: myanimation;
 

Copyright (c) Enough Software 2005 - 2008

 history
        27-May-2005 - rob creation
 

Author:
Robert Virkus, j2mepolish@enough.de
See Also:
show(Style, Display, int, int, Image, Image, AccessibleCanvas, Displayable, boolean), animate()

Field Summary
protected  javax.microedition.lcdui.Display display
           
protected  boolean fullScreenModeSet
           
protected  boolean isForwardAnimation
           
protected  javax.microedition.lcdui.Image lastCanvasImage
           
protected  int[] lastCanvasRgb
           
protected  AccessibleCanvas nextCanvas
           
protected  javax.microedition.lcdui.Image nextCanvasImage
           
protected  int[] nextCanvasRgb
           
protected  javax.microedition.lcdui.Displayable nextDisplayable
           
protected  int screenHeight
           
protected  int screenWidth
           
protected  boolean useLastCanvasRgb
          set to true in subclasses for populating lastCanvasRgb
protected  boolean useNextCanvasRgb
          set to true in subclasses for populating nextCanvasRgb
 
Fields inherited from class javax.microedition.lcdui.Canvas
DOWN, FIRE, GAME_A, GAME_B, GAME_C, GAME_D, KEY_NUM0, KEY_NUM1, KEY_NUM2, KEY_NUM3, KEY_NUM4, KEY_NUM5, KEY_NUM6, KEY_NUM7, KEY_NUM8, KEY_NUM9, KEY_POUND, KEY_STAR, LEFT, RIGHT, UP
 
Constructor Summary
ScreenChangeAnimation()
          Creates a new ScreenChangeAnimation.
 
Method Summary
protected abstract  boolean animate()
          Animates this animation.
 void hideNotify()
          Notifies this animation that it will be hidden shortly.
 void keyPressed(int keyCode)
          Handles key pressed events.
 void keyReleased(int keyCode)
          Handles key released events.
 void keyRepeated(int keyCode)
          Handles key repeat events.
 void paint(javax.microedition.lcdui.Graphics g)
           
protected abstract  void paintAnimation(javax.microedition.lcdui.Graphics g)
          Paints the animation.
 void pointerDragged(int x, int y)
          Forwards pointer dragged events to the next screen.
 void pointerPressed(int x, int y)
          Forwards pointer pressed events to the next screen.
 void pointerReleased(int x, int y)
          Forwards pointer pressed events to the next screen.
 void run()
          Runs this animation - subclasses need to ensure to call this.display.callSerially( this ); at the end of the paint method.
protected  void setStyle(Style style)
          Sets the style for this animation.
protected  void show(Style style, javax.microedition.lcdui.Display dsplay, int width, int height, javax.microedition.lcdui.Image lstScreenImage, javax.microedition.lcdui.Image nxtScreenImage, AccessibleCanvas nxtCanvas, javax.microedition.lcdui.Displayable nxtDisplayable, boolean isForward)
          Starts the animation.
 void showNotify()
          Notifies this animation that it will be shown shortly.
 void sizeChanged(int width, int height)
          Notifies this animation that the screen space has been changed.
protected  void updateNextScreen(AccessibleCanvas next, javax.microedition.lcdui.Image nextImage, int[] rgb)
          Updates the image and possibly the RGB data of the next screen.
 
Methods inherited from class javax.microedition.lcdui.Canvas
getGameAction, getKeyCode, getKeyName, hasPointerEvents, hasPointerMotionEvents, hasRepeatEvents, isDoubleBuffered, repaint, repaint, serviceRepaints, setFullScreenMode
 
Methods inherited from class javax.microedition.lcdui.Displayable
addCommand, getHeight, getTicker, getTitle, getWidth, isShown, removeCommand, setCommandListener, setTicker, setTitle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

display

protected javax.microedition.lcdui.Display display

nextCanvas

protected AccessibleCanvas nextCanvas

lastCanvasImage

protected javax.microedition.lcdui.Image lastCanvasImage

lastCanvasRgb

protected int[] lastCanvasRgb

useLastCanvasRgb

protected boolean useLastCanvasRgb
set to true in subclasses for populating lastCanvasRgb


nextCanvasImage

protected javax.microedition.lcdui.Image nextCanvasImage

nextCanvasRgb

protected int[] nextCanvasRgb

useNextCanvasRgb

protected boolean useNextCanvasRgb
set to true in subclasses for populating nextCanvasRgb


screenWidth

protected int screenWidth

screenHeight

protected int screenHeight

fullScreenModeSet

protected boolean fullScreenModeSet

nextDisplayable

protected javax.microedition.lcdui.Displayable nextDisplayable

isForwardAnimation

protected boolean isForwardAnimation
Constructor Detail

ScreenChangeAnimation

public ScreenChangeAnimation()
Creates a new ScreenChangeAnimation. All subclasses need to implement the default constructor.

Method Detail

show

protected void show(Style style,
                    javax.microedition.lcdui.Display dsplay,
                    int width,
                    int height,
                    javax.microedition.lcdui.Image lstScreenImage,
                    javax.microedition.lcdui.Image nxtScreenImage,
                    AccessibleCanvas nxtCanvas,
                    javax.microedition.lcdui.Displayable nxtDisplayable,
                    boolean isForward)
Starts the animation. Please note that an animation can be re-used for several screens.

Parameters:
style - the associated style.
dsplay - the display, which is used for setting this animation
width - the screen's width
height - the screen's height
lstScreenImage - an image of the last screen
nxtScreenImage - an image of the next screen
nxtCanvas - the next screen that should be displayed when this animation finishes (as an AccessibleCanvas)
nxtDisplayable - the next screen that should be displayed when this animation finishes (as a Displayable)
isForward - true when the animation should run in the normal direction/mode - false if it should run backwards

setStyle

protected void setStyle(Style style)
Sets the style for this animation. Subclasses can override this for adapting to different design settings.

Parameters:
style - the style

animate

protected abstract boolean animate()
Animates this animation.

Returns:
true when the animation should continue, when false is returned the animation will be stopped and the next screen will be shown instead.

paintAnimation

protected abstract void paintAnimation(javax.microedition.lcdui.Graphics g)
Paints the animation.

Parameters:
g - the graphics context

paint

public final void paint(javax.microedition.lcdui.Graphics g)
Specified by:
paint in interface AccessibleCanvas
Specified by:
paint in class javax.microedition.lcdui.Canvas

pointerPressed

public void pointerPressed(int x,
                           int y)
Forwards pointer pressed events to the next screen.

Specified by:
pointerPressed in interface AccessibleCanvas
Overrides:
pointerPressed in class javax.microedition.lcdui.Canvas
Parameters:
x - the horizontal coordinate of the clicked pixel
y - the vertical coordinate of the clicked pixel
See Also:
updateNextScreen(AccessibleCanvas, Image, int[])

pointerReleased

public void pointerReleased(int x,
                            int y)
Forwards pointer pressed events to the next screen.

Specified by:
pointerReleased in interface AccessibleCanvas
Overrides:
pointerReleased in class javax.microedition.lcdui.Canvas
Parameters:
x - the horizontal coordinate of the clicked pixel
y - the vertical coordinate of the clicked pixel
See Also:
updateNextScreen(AccessibleCanvas, Image, int[])

pointerDragged

public void pointerDragged(int x,
                           int y)
Forwards pointer dragged events to the next screen.

Specified by:
pointerDragged in interface AccessibleCanvas
Overrides:
pointerDragged in class javax.microedition.lcdui.Canvas
Parameters:
x - the horizontal coordinate of the clicked pixel
y - the vertical coordinate of the clicked pixel
See Also:
updateNextScreen(AccessibleCanvas, Image, int[])

showNotify

public void showNotify()
Notifies this animation that it will be shown shortly. The default implementation switches into fullscreen mode

Specified by:
showNotify in interface AccessibleCanvas
Overrides:
showNotify in class javax.microedition.lcdui.Canvas

hideNotify

public void hideNotify()
Notifies this animation that it will be hidden shortly. This is ignored by the default implementation.

Specified by:
hideNotify in interface AccessibleCanvas
Overrides:
hideNotify in class javax.microedition.lcdui.Canvas

sizeChanged

public void sizeChanged(int width,
                        int height)
Notifies this animation that the screen space has been changed. This is ignored by the default implementation.

Specified by:
sizeChanged in interface AccessibleCanvas
Overrides:
sizeChanged in class javax.microedition.lcdui.Canvas
Parameters:
width - the width
height - the height

keyRepeated

public void keyRepeated(int keyCode)
Handles key repeat events. The implementation forwards this event to the next screen and then updates the nextCanvasImage field.

Specified by:
keyRepeated in interface AccessibleCanvas
Overrides:
keyRepeated in class javax.microedition.lcdui.Canvas
Parameters:
keyCode - the code of the key
See Also:
nextCanvasImage, updateNextScreen(AccessibleCanvas, Image, int[])

keyReleased

public void keyReleased(int keyCode)
Handles key released events. The implementation forwards this event to the next screen and then updates the nextCanvasImage field.

Specified by:
keyReleased in interface AccessibleCanvas
Overrides:
keyReleased in class javax.microedition.lcdui.Canvas
Parameters:
keyCode - the code of the key
See Also:
nextCanvasImage, updateNextScreen(AccessibleCanvas, Image, int[])

keyPressed

public void keyPressed(int keyCode)
Handles key pressed events. The implementation forwards this event to the next screen and then updates the nextCanvasImage field.

Specified by:
keyPressed in interface AccessibleCanvas
Overrides:
keyPressed in class javax.microedition.lcdui.Canvas
Parameters:
keyCode - the code of the key
See Also:
nextCanvasImage, updateNextScreen(AccessibleCanvas, Image, int[])

updateNextScreen

protected void updateNextScreen(AccessibleCanvas next,
                                javax.microedition.lcdui.Image nextImage,
                                int[] rgb)
Updates the image and possibly the RGB data of the next screen.

Parameters:
next - the next screen
nextImage - the image to which the screen should be painted
rgb - the RGB data, can be null

run

public void run()
Runs this animation - subclasses need to ensure to call this.display.callSerially( this ); at the end of the paint method.

Specified by:
run in interface java.lang.Runnable
See Also:
Runnable.run()