Class Timeline

java.lang.Object
com.codename1.ui.Image
com.codename1.ui.animations.Timeline
All Implemented Interfaces:
Animation, ActionSource, Painter

public final class Timeline extends Image implements Animation, Painter
A timeline represents the motions of animation objects
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds an animation object to show using this timeline
    boolean
    Advances this image's animation state, if it is animated.
    static Timeline
    createTimeline(int duration, AnimationObject[] animations, Dimension size)
    Create a new timeline animation
    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.
    getAnimation(int i)
    Returns the animation object in the given offset
    getAnimationAt(int x, int y)
    Returns the animation object at the given X/Y coordinate in the timeline for the current frame.
    int
    Returns the number of animation objects in this timeline
    int
    Inidicates the minimal delay between animation frames allowing the CPU to rest.
    int
    Returns the duration of the entire timeline in milliseconds
    int
    Returns the height of the image
    int[]
    Returns the content of this image as a newly created ARGB array.
    int[]
    Returns the content of this image as a newly created ARGB array or a cached instance if possible.
    Returns the pixel based unscaled dimentions of this timeline
    int
    Returns the time of the timeline
    int
    Returns the width of the image
    boolean
    Returns true if this is an animated image
    boolean
    Indicates if the image should loop
    boolean
    Returns true when the timeline is paused
    void
    This callback indicates that a component pointing at this image is initialized, this allows an image to make performance sensitive considerations e.g.
    void
    Draws the animation, within a component the standard paint method would be invoked since it bares the exact same signature.
    void
    Draws inside the given rectangle clipping area.
    boolean
    New label optimizations don't invoke drawImage and instead just pass the native image directly to the underlying renderer.
    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.
    void
    setAnimationDelay(int animationDelay)
    Inidicates the minimal delay between animation frames allowing the CPU to rest.
    void
    setLoop(boolean loop)
    Indicates if the image should loop
    void
    setPause(boolean pause)
    Indicate that the application is paused
    void
    setTime(int time)
    Set the time of the timeline
    void
    This callback indicates that a component pointing at this image is now deinitilized This method may be invoked multiple times.

    Methods inherited from class Image

    addActionListener, applyMask, applyMask, applyMaskAutoScale, asyncLock, createImage, createImage, createImage, createImage, createImage, createImage, createImage, createIndexed, createMask, createSVG, dispose, exifRotation, exifRotation, exifRotation, fill, fireChangedEvent, flipHorizontally, flipVertically, getExifOrientationTag, getExifOrientationTag, getGraphics, getImage, getImageName, getRGB, getSVGDocument, isAlphaMutableImageSupported, isJPEG, isLocked, isOpaque, isPNG, isSVG, isSVGSupported, mirror, modifyAlpha, modifyAlpha, modifyAlphaWithTranslucency, removeActionListener, rotate, rotate180Degrees, rotate270Degrees, rotate90Degrees, scale, scaledHeight, scaledLargerRatio, scaledSmallerRatio, scaledWidth, setImageName, subImage, toRGB
    Modifier and Type
    Method
    Description
    void
    Adds ActionListener to receive action events form this source.
    Applies the given alpha mask onto this image and returns the resulting image see the createMask method for indication on how to convert an image into an alpha mask.
    applyMask(Object mask, int x, int y)
    Applies the given alpha mask onto this image and returns the resulting image see the createMask method for indication on how to convert an image into an alpha mask.
    Applies the given alpha mask onto this image and returns the resulting image see the createMask method for indication on how to convert an image into an alpha mask.
    void
    asyncLock(Image internal)
    Async lock is the equivalent of a lock operation, however it uses the given image as the hard cache and performs the actual image loading asynchronously.
    static Image
    createImage(byte[] bytes, int offset, int len)
    creates an image from a given byte array data
    static Image
    createImage(int[] rgb, int width, int height)
    creates an image from an RGB image
    static Image
    createImage(int width, int height)
    Creates a white opaque mutable image that may be manipulated using #getGraphics().
    static Image
    createImage(int width, int height, int fillColor)
    Creates a mutable image that may be manipulated using #getGraphics().
    static Image
    creates an image from an InputStream
    static Image
    createImage(Object nativeImage)
    creates an image from the given native image (e.g. MIDP image object)
    static Image
    Creates an image from a path.
    static Image
    createIndexed(int width, int height, int[] palette, byte[] data)
    Creates an indexed image with byte data this method may return a native indexed image rather than an instance of the IndexedImage class
    Creates a mask from the given image, a mask can be used to apply an arbitrary alpha channel to any image.
    static Image
    createSVG(String baseURL, boolean animated, byte[] data)
    Creates an SVG Image from the given byte array data and the base URL, this method will throw an exception if SVG is unsupported.
    void
    DO NOT CALL THIS METHOD UNLESS YOU KNOW WHAT YOU ARE DOING, IT WILL CAUSE PLATFORM SPECIFC CRASHES OTHERWISE! Images dispose automatically for most cases except for very rare special cases.
    static Image
    exifRotation(String capturedImage)
    The main use case of this method is the automatic rotation and flipping of an image returned from the camera or from the gallery, preserving the original format (jpeg or png); it detects the Exif Orientation Tag, if available (all the possible Exif Orientation Tag values are supported); transparency is not preserved.
    static Image
    exifRotation(String capturedImage, String rotatedImage)
    The main use case of this method is the automatic rotation and flipping of an image returned from the camera or from the gallery, preserving the original format (jpeg or png); it detects the Exif Orientation Tag, if available (all the possible Exif Orientation Tag values are supported); transparency is not preserved.
    static Image
    exifRotation(String capturedImage, String rotatedImage, int maxSize)
    The main use case of this method is the automatic rotation and flipping of an image returned from the camera or from the gallery, preserving the original format (jpeg or png); it detects the Exif Orientation Tag, if available (all the possible Exif Orientation Tag values are supported); transparency is not preserved.
    fill(int width, int height)
    Resizes/crops the image so that its center fills the given dimensions.
    void
     
    flipHorizontally(boolean maintainOpacity)
    Flips this image on the horizontal axis
    flipVertically(boolean maintainOpacity)
    Flips this image on the vertical axis
    static int
    Gets the EXIF orientation tag of an image, if it's available.
    static int
    Gets the EXIF orientation tag of an image if it's available.
    If this is a mutable image a graphics object allowing us to draw on it is returned.
    Returns the platform specific image implementation, warning the implementation class can change between revisions of Codename One and platforms.
    The name of the image is set for some images mostly to ease the debugging of Codename One application
    void
    getRGB(int[] rgbData)
    Returns the content of this image in the supplied ARGB array.
    Returns a platform specific DOM object that can be manipulated by the user to change the SVG Image
    static boolean
    Returns true if mutable images support alpha transparency
    static boolean
    isJPEG(InputStream inputStream)
    Very fast method to detect if the given inputStream is a JPEG image (according to its guessed mime type)
    boolean
    Returns true if the image is locked
    boolean
    Indicates whether this image is opaque or not
    static boolean
    isPNG(InputStream inputStream)
    Very fast method to detect if the given inputStream is a PNG image (according to its guessed mime type)
    boolean
    Indicates if this image represents an SVG file or a bitmap file
    static boolean
    Indicates whether the underlying platform supports creating an SVG Image
    Creates a mirror image for the given image which is useful for some RTL scenarios.
    modifyAlpha(byte alpha)
    Creates a new image instance with the alpha channel of opaque/translucent pixels within the image using the new alpha value.
    modifyAlpha(byte alpha, int removeColor)
    Creates a new image instance with the alpha channel of opaque/translucent pixels within the image using the new alpha value.
    Creates a new image instance with the alpha channel of opaque pixels within the image using the new alpha value.
    void
    Removes ActionListener so that it will no longer receive events from this source.
    rotate(int degrees)
    Returns an instance of this image rotated by the given number of degrees.
    rotate180Degrees(boolean maintainOpacity)
    Rotates the image by 180 degrees
    rotate270Degrees(boolean maintainOpacity)
    Rotates the image by 270 degrees while changing the ratio of the picture
    rotate90Degrees(boolean maintainOpacity)
    Rotates this image by 90 degrees while changing the ratio of the picture
    void
    scale(int width, int height)
    Scale the image to the given width and height, this is a fast algorithm that preserves translucent information
    scaledHeight(int height)
    Scales the image to the given height while updating the width based on the aspect ratio of the height
    scaledLargerRatio(int width, int height)
    Scales the image while maintaining the aspect ratio to the larger size image
    scaledSmallerRatio(int width, int height)
    Scales the image while maintaining the aspect ratio to the smaller size image
    scaledWidth(int width)
    Scales the image to the given width while updating the height based on the aspect ratio of the width
    void
    setImageName(String imageName)
    The name of the image is set for some images mostly to ease the debugging of Codename One application
    subImage(int x, int y, int width, int height, boolean processAlpha)
    Extracts a subimage from the given image allowing us to breakdown a single large image into multiple smaller images in RAM, this actually creates a standalone version of the image for use.
    void
    toRGB(RGBImage image, int destX, int destY, int x, int y, int width, int height)
    Extracts data from this image into the given RGBImage

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    Modifier and Type
    Method
    Description
    protected Object
     
    boolean
    Indicates whether some other object is "equal to" this one.
    final Class
    Returns the runtime class of an object.
    int
    Returns a hash code value for the object.
    final void
    Wakes up a single thread that is waiting on this object's monitor.
    final void
    Wakes up all threads that are waiting on this object's monitor.
    Returns a string representation of the object.
    final void
    Causes current thread to wait until another thread invokes the method or the method for this object.
    final void
    wait(long timeout)
    Causes current thread to wait until either another thread invokes the method or the method for this object, or a specified amount of time has elapsed.
    final void
    wait(long timeout, int nanos)
    Causes current thread to wait until another thread invokes the method or the method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.
  • Method Details

    • createTimeline

      public static Timeline createTimeline(int duration, AnimationObject[] animations, Dimension size)

      Create a new timeline animation

      Parameters
      • duration: the duration of the animation in milliseconds

      • animations: the animation objects that are part of this timeline

      • size: @param size 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.
      Overrides:
      lock in class Image
    • unlock

      public void unlock()
      This callback indicates that a component pointing at this image is now deinitilized This method may be invoked multiple times.
      Overrides:
      unlock in class Image
    • 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

      Overrides:
      getRGB in class 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

      Overrides:
      getRGBCached in class Image
    • addAnimation

      public void addAnimation(AnimationObject o)

      Adds an animation object to show using this timeline

      Parameters
      • o: 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: 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

      Overrides:
      isAnimation in class Image
    • animate

      public boolean animate()

      Advances this image's animation state, if it is animated.

      Returns

      true if the animation state changed.

      Specified by:
      animate in interface Animation
      Overrides:
      animate in class Image
    • 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 context
      Specified by:
      paint in interface Animation
    • paint

      public void paint(Graphics g, Rectangle rect)

      Draws inside the given rectangle clipping area.

      Parameters
      • g: the Graphics object

      • rect: the given rectangle cliping area

      Specified by:
      paint in interface Painter
    • 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: 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: the graphics object

      • nativeGraphics: the underlying native graphics which might be essential for some image types

      • x: the x coordinate

      • y: the y coordinate

      Overrides:
      drawImage in class Image
    • 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: the graphics object

      • nativeGraphics: the underlying native graphics which might be essential for some image types

      • x: the x coordinate

      • y: the y coordinate

      • w: the width to occupy

      • h: the height to occupy

      Overrides:
      drawImage in class Image
    • getWidth

      public int getWidth()

      Returns the width of the image

      Returns

      the width of the image

      Overrides:
      getWidth in class Image
    • getHeight

      public int getHeight()

      Returns the height of the image

      Returns

      the height of the image

      Overrides:
      getHeight in class 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: width for the scaling

      • height: height of the scaled image

      Returns

      new image instance scaled to the given height and width

      Overrides:
      scaled in class Image
    • 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: 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: 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: the x location in the timeline

      • y: 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: 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

      Overrides:
      requiresDrawImage in class Image