public final class Timeline

  1. Object
  2. Image
  3. Timeline

ImplementsActionSource, Animation, Painter

A timeline represents the motions of animation objects

Methods

public static Timeline createTimeline(int duration, AnimationObject[] animations, Dimension size)Create a new timeline animation
public void lock()This callback indicates that a component pointing at this image is initialized, this allows an image to make performance sensitive considerations e.g. an encoded image might choose to cache itself in RAM.
public void unlock()This callback indicates that a component pointing at this image is now deinitilized This method may be invoked multiple times.
public int[] getRGB()Returns the content of this image as a newly created ARGB array.
public int[] getRGBCached()Returns the content of this image as a newly created ARGB array or a cached instance if possible.
public void addAnimation(AnimationObject o)Adds an animation object to show using this timeline
public int getTime()Returns the time of the timeline
public void setTime(int time)Set the time of the timeline
public boolean isAnimation()Returns true if this is an animated image
public boolean animate()Advances this image’s animation state, if it is animated.
public void paint(Graphics g)Draws the animation, within a component the standard paint method would be invoked since it bares the exact same signature.
public void paint(Graphics g, Rectangle rect)Draws inside the given rectangle clipping area.
public int getAnimationDelay()Inidicates the minimal delay between animation frames allowing the CPU to rest.
public void setAnimationDelay(int animationDelay)Inidicates the minimal delay between animation frames allowing the CPU to rest.
protected void drawImage(Graphics g, Object nativeGraphics, int x, int y)Callback invoked internally by Codename One to draw the image/frame onto the display.
protected void drawImage(Graphics g, Object nativeGraphics, int x, int y, int w, int h)Callback invoked internally by Codename One to draw the image/frame onto the display.
public int getWidth()Returns the width of the image
public int getHeight()Returns the height of the image
public Image scaled(int width, int height)Returns a scaled version of this image image using the given width and height, this is a fast algorithm that preserves translucent information.
public boolean isPause()Returns true when the timeline is paused
public void setPause(boolean pause)Indicate that the application is paused
public int getDuration()Returns the duration of the entire timeline in milliseconds
public Dimension getSize()Returns the pixel based unscaled dimentions of this timeline
public int getAnimationCount()Returns the number of animation objects in this timeline
public AnimationObject getAnimation(int i)Returns the animation object in the given offset
public AnimationObject getAnimationAt(int x, int y)Returns the animation object at the given X/Y coordinate in the timeline for the current frame.
public boolean isLoop()Indicates if the image should loop
public void setLoop(boolean loop)Indicates if the image should loop
public boolean requiresDrawImage()New label optimizations don’t invoke drawImage and instead just pass the native image directly to the underlying renderer.

Inherited methods

Method details

createTimeline

public static Timeline createTimeline(int duration, AnimationObject[] animations, Dimension size)
Create a new timeline animation

Parameters

duration int
the duration of the animation in milliseconds
animations AnimationObject[]
the animation objects that are part of this timeline
size Dimension
size of the animation in virtual pixels, if the size differs the animation would be scaled on the fly

Returns

the new timeline instance

lock

public void lock()
This callback indicates that a component pointing at this image is initialized, this allows an image to make performance sensitive considerations e.g. an encoded image might choose to cache itself in RAM. This method may be invoked multiple times.

unlock

public void unlock()
This callback indicates that a component pointing at this image is now deinitilized This method may be invoked multiple times.

getRGB

public int[] getRGB()
Returns the content of this image as a newly created ARGB array.

Returns

new array instance containing the ARGB data within this image

getRGBCached

public int[] getRGBCached()
Returns the content of this image as a newly created ARGB array or a cached instance if possible. Note that cached instances may be garbage collected.

Returns

array instance containing the ARGB data within this image

addAnimation

public void addAnimation(AnimationObject o)
Adds an animation object to show using this timeline

Parameters

o AnimationObject
animation object featured in this timeline

getTime

public int getTime()
Returns the time of the timeline

Returns

the time of the timeline in ms starting from 0

setTime

public void setTime(int time)
Set the time of the timeline

Parameters

time int
the time of the timeline in ms starting from 0

isAnimation

public boolean isAnimation()
Returns true if this is an animated image

Returns

true if this image represents an animation

animate

public boolean animate()
Advances this image’s animation state, if it is animated.

Returns

true if the animation state changed.

paint

public void paint(Graphics g)
Draws the animation, within a component the standard paint method would be invoked since it bares the exact same signature.

Parameters

g Graphics
graphics context

paint

public void paint(Graphics g, Rectangle rect)
Draws inside the given rectangle clipping area.

Parameters

g Graphics
the Graphics object
rect Rectangle
the given rectangle cliping area

getAnimationDelay

public int getAnimationDelay()
Inidicates the minimal delay between animation frames allowing the CPU to rest. Increase this number to increase general device performance, decrease it to speed the animation.

Returns

the animationDelay

setAnimationDelay

public void setAnimationDelay(int animationDelay)
Inidicates the minimal delay between animation frames allowing the CPU to rest. Increase this number to increase general device performance, decrease it to speed the animation.

Parameters

animationDelay int
the animationDelay to set

drawImage

protected void drawImage(Graphics g, Object nativeGraphics, int x, int y)
Callback invoked internally by Codename One to draw the image/frame onto the display. Image subclasses can override this method to perform drawing of custom image types.

Parameters

g Graphics
the graphics object
nativeGraphics Object
the underlying native graphics which might be essential for some image types
x int
the x coordinate
y int
the y coordinate

drawImage

protected void drawImage(Graphics g, Object nativeGraphics, int x, int y, int w, int h)
Callback invoked internally by Codename One to draw the image/frame onto the display. Image subclasses can override this method to perform drawing of custom image types.

Parameters

g Graphics
the graphics object
nativeGraphics Object
the underlying native graphics which might be essential for some image types
x int
the x coordinate
y int
the y coordinate
w int
the width to occupy
h int
the height to occupy

getWidth

public int getWidth()
Returns the width of the image

Returns

the width of the image

getHeight

public int getHeight()
Returns the height of the image

Returns

the height of the image

scaled

public Image scaled(int width, int height)
Returns a scaled version of this image image using the given width and height, this is a fast algorithm that preserves translucent information. The method accepts -1 to preserve aspect ratio in the given axis.

Parameters

width int
width for the scaling
height int
height of the scaled image

Returns

new image instance scaled to the given height and width

isPause

public boolean isPause()
Returns true when the timeline is paused

Returns

the pause state

setPause

public void setPause(boolean pause)
Indicate that the application is paused

Parameters

pause boolean
true to pause the application

getDuration

public int getDuration()
Returns the duration of the entire timeline in milliseconds

Returns

the duration

getSize

public Dimension getSize()
Returns the pixel based unscaled dimentions of this timeline

Returns

the size

getAnimationCount

public int getAnimationCount()
Returns the number of animation objects in this timeline

Returns

the number of animations

getAnimation

public AnimationObject getAnimation(int i)
Returns the animation object in the given offset

Parameters

i int
the offset of the animation

Returns

the animation object

getAnimationAt

public AnimationObject getAnimationAt(int x, int y)
Returns the animation object at the given X/Y coordinate in the timeline for the current frame. This allows functionality such as responding to pointer events on the resource editor. Notice that this method is not efficient since it tests the pixel opacity which is a pretty expensive operation…

Parameters

x int
the x location in the timeline
y int
the y location in the timeline

Returns

an animation object or null if no animation object is at that position.

isLoop

public boolean isLoop()
Indicates if the image should loop

Returns

the loop

setLoop

public void setLoop(boolean loop)
Indicates if the image should loop

Parameters

loop boolean
the loop to set

requiresDrawImage

public boolean requiresDrawImage()
New label optimizations don’t invoke drawImage and instead just pass the native image directly to the underlying renderer. This is problematic for some image types specifically timeline & FontImage and this method allows these classes to indicate that they need that legacy behavior of calling drawImage.

Returns

true if a drawImage call is a required