Interface UltraliteSDK.Canvas

Enclosing interface:
UltraliteSDK

public static interface UltraliteSDK.Canvas
Canvas is used to perform direct drawing operations to the Ultralite display. Before a canvas can be used, the Ultralite layout should be set to CANVAS. Otherwise Canvas methods won't do anything. Glasses control is also required for all Canvas methods.

All canvas operations need to be committed before they will be reflected on the canvas. This allows you to stage an entire screen with changes and display them all at once. This is done by calling commit(). Please note that uncommitted changes may be shown early in some situations, so this should be called immediately after the last canvas element is sent to ensure predictable results.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    Gets notified when a commit is complete.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    available height of the canvas that can be drawn to
    static final int
    available width of the canvas that can be drawn to
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clears the entire canvas.
    void
    Clears the entire background layer.
    void
    Clears the entire background layer to the specified color.
    void
    clearBackgroundRect(int x, int y, int width, int height)
    Clears a specific area of the background layer.
    void
    clearBackgroundRect(int x, int y, int width, int height, UltraliteColor color)
    Clears a specific area of the background layer to the specified color.
    void
    Commits canvas changes made since the last commit.
    void
    Commits canvas changes made since the last commit.
    int
    createAnimation(LVGLImage[] images, Anchor anchor, int duration)
    Creates an animation out of an array of images.
    int
    createAnimation(LVGLImage[] images, Anchor anchor, int offsetX, int offsetY, int duration)
    Creates an animation out of an array of images.
    int
    createImage(LVGLImage image, Anchor anchor)
    Creates an identifiable image that can be manipulated.
    int
    createImage(LVGLImage image, Anchor anchor, boolean visible)
    Creates an identifiable image that can be manipulated.
    int
    createImage(LVGLImage image, Anchor anchor, int offsetX, int offsetY, boolean visible)
    Creates an identifiable image that can be manipulated.
    int
    createText(String text, Anchor anchor)
    Creates an identifiable block of text that can be manipulated.
    int
    createText(String text, TextAlignment alignment, UltraliteColor color, Anchor anchor, boolean visible)
    Creates an identifiable block of text that can be manipulated.
    int
    createText(String text, TextAlignment alignment, UltraliteColor color, Anchor anchor, int offsetX, int offsetY, int width, int height, TextWrapMode wrap, boolean visible)
    Creates an identifiable block of text that can be manipulated.
    boolean
    drawBackground(android.graphics.Bitmap bitmap, int x, int y)
    Draws the provided bitmap in the background layer at the specified coordinates.
    boolean
    drawBackground(android.graphics.Bitmap bitmap, android.graphics.Point[] coordinates)
    Draws the provided bitmap in the background layer at the specified coordinate pairs.
    boolean
    drawBackground(LVGLImage image, int x, int y)
    Draws the provided image in the background layer at the specified coordinates.
    boolean
    drawBackground(LVGLImage image, android.graphics.Point[] coordinates)
    Draws the provided image in the background layer at the specified coordinate pairs.
    boolean
    moveAnimation(int id, int x, int y)
    Moves an animation to a new absolute location on screen.
    boolean
    moveAnimation(int id, int x, int y, int durationMs)
    Moves an animation to a new absolute location on screen.
    boolean
    moveImage(int id, int x, int y)
    Moves an image to a new absolute location on screen.
    boolean
    moveImage(int id, int x, int y, int durationMs)
    Moves an image to a new absolute location on screen.
    boolean
    moveText(int id, int offsetX, int offsetY, int durationMs)
    Moves text to a new location.
    boolean
    moveText(int id, Anchor anchor, int offsetX, int offsetY)
    Moves text to a new location.
    boolean
    Removes a previously created animation.
    boolean
    removeImage(int id)
    Removes a previously created image.
    boolean
    removeText(int id)
    Removes a previously created text block.
    boolean
    setAnimationVisible(int id, boolean visible)
    Changes visibility of an animation.
    boolean
    setImageVisible(int id, boolean visible)
    Changes visibility of an image.
    boolean
    setTextVisible(int id, boolean visible)
    Changes visibility of text.
    boolean
    updateImage(int id, LVGLImage image)
    Replaces the image displayed with a particular id.
    boolean
    updateText(int id, String text)
    Replaces the text displayed with a particular id.
  • Field Details

    • WIDTH

      static final int WIDTH
      available width of the canvas that can be drawn to
      See Also:
    • HEIGHT

      static final int HEIGHT
      available height of the canvas that can be drawn to
      See Also:
  • Method Details

    • drawBackground

      boolean drawBackground(@NonNull android.graphics.Bitmap bitmap, int x, int y)
      Draws the provided bitmap in the background layer at the specified coordinates. The bitmap can be no wider than 640 and no taller than 480, otherwise nothing will be drawn.
      Parameters:
      bitmap - a bitmap
      x - the x location to draw
      y - the y location to draw
      Returns:
      true if the bitmap was drawn on the background, false otherwise
    • drawBackground

      boolean drawBackground(@NonNull android.graphics.Bitmap bitmap, @NonNull android.graphics.Point[] coordinates)
      Draws the provided bitmap in the background layer at the specified coordinate pairs. The bitmap can be no wider than 640 and no taller than 480, otherwise nothing will be drawn.
      Parameters:
      bitmap - a bitmap
      coordinates - an array of Point coordinate at which to draw the same image
      Returns:
      true if the bitmap was drawn on the background, false otherwise
    • drawBackground

      boolean drawBackground(@NonNull LVGLImage image, int x, int y)
      Draws the provided image in the background layer at the specified coordinates. The image can be no wider than 640 and no taller than 480, otherwise nothing will be drawn.
      Parameters:
      image - an LVGLImage in color format LVGLImage.CF_INDEXED_2_BIT
      x - the x location to draw
      y - the y location to draw
      Returns:
      true if the bitmap was drawn on the background, false otherwise
    • drawBackground

      boolean drawBackground(@NonNull LVGLImage image, @NonNull android.graphics.Point[] coordinates)
      Draws the provided image in the background layer at the specified coordinate pairs. The image can be no wider than 640 and no taller than 480, otherwise nothing will be drawn.
      Parameters:
      image - an LVGLImage in color format LVGLImage.CF_INDEXED_2_BIT
      coordinates - an array of Point coordinate at which to draw the same image
      Returns:
      true if the bitmap was drawn on the background, false otherwise
    • clearBackground

      void clearBackground()
      Clears the entire background layer.
    • clearBackground

      void clearBackground(@NonNull UltraliteColor color)
      Clears the entire background layer to the specified color.
      Parameters:
      color - the color to paint on the background
    • clearBackgroundRect

      void clearBackgroundRect(int x, int y, int width, int height)
      Clears a specific area of the background layer.
      Parameters:
      x - starting x location to clear
      y - starting y location to clear
      width - amount of horizontal space to clear (must be greater than zero)
      height - amount of vertical space to clear (must be greater than zero)
    • clearBackgroundRect

      void clearBackgroundRect(int x, int y, int width, int height, @NonNull UltraliteColor color)
      Clears a specific area of the background layer to the specified color.
      Parameters:
      x - starting x location to clear
      y - starting y location to clear
      width - amount of horizontal space to clear (must be greater than zero)
      height - amount of vertical space to clear (must be greater than zero)
      color - the color to paint on the background
    • createImage

      int createImage(@NonNull LVGLImage image, @NonNull Anchor anchor)
      Creates an identifiable image that can be manipulated. The image will initially be visible.

      Note that only 3 images can be allocated. If you create more than this, you will start overwriting previously created images.

      Also note that there is a limit of 9900 bytes for the image data. Images larger than this will not be created.
      Parameters:
      image - the initial image
      anchor - where to anchor the image
      Returns:
      an int that can be used to update the image or -1 if the image can't be created
    • createImage

      int createImage(@NonNull LVGLImage image, @NonNull Anchor anchor, boolean visible)
      Creates an identifiable image that can be manipulated.

      Note that only 3 images can be allocated. If you create more than this, you will start overwriting previously created images.

      Also note that there is a limit of 9900 bytes for the image data. Images larger than this will not be created.
      Parameters:
      image - the initial image
      anchor - where to anchor the image
      visible - initial visibility of the image
      Returns:
      an int that can be used to update the image or -1 if the image can't be created
    • createImage

      int createImage(@NonNull LVGLImage image, @NonNull Anchor anchor, int offsetX, int offsetY, boolean visible)
      Creates an identifiable image that can be manipulated.

      Note that only 3 images can be allocated. If you create more than this, you will start overwriting previously created images.

      Also note that there is a limit of 9900 bytes for the image data. Images larger than this will not be created.
      Parameters:
      image - the initial image
      anchor - where to anchor the image
      offsetX - the horizontal offset
      offsetY - the vertical offset
      visible - initial visibility of the image
      Returns:
      an int that can be used to update the image or -1 if the image can't be created
    • updateImage

      boolean updateImage(int id, @NonNull LVGLImage image)
      Replaces the image displayed with a particular id. Location and visibility are not changed. If the provided id is invalid, this method does nothing.

      Note that there is a limit of 9900 bytes for the image data. Images larger than this will not be updated.
      Parameters:
      id - the image id returned by createImage
      image - the new image
      Returns:
      true if the image was updated, false otherwise
    • moveImage

      boolean moveImage(int id, int x, int y)
      Moves an image to a new absolute location on screen. If the provided id is invalid, this method does nothing.
      Parameters:
      id - the image id returned by createImage
      x - new absolute x position
      y - new absolute y position
      Returns:
      true if the image was moved, false otherwise
    • moveImage

      boolean moveImage(int id, int x, int y, int durationMs)
      Moves an image to a new absolute location on screen. If the provided id is invalid, this method does nothing.
      Parameters:
      id - the image id returned by createImage
      x - new absolute x position
      y - new absolute y position
      durationMs - duration in milliseconds over which to animate the move (0 = immediate)
      Returns:
      true if the image was moved, false otherwise
    • setImageVisible

      boolean setImageVisible(int id, boolean visible)
      Changes visibility of an image. If the provided id is invalid, this method does nothing.
      Parameters:
      id - the image id returned by createImage
      visible - new visibility
      Returns:
      true if the image visibility was changed, false otherwise
    • removeImage

      boolean removeImage(int id)
      Removes a previously created image. If the provided id is invalid, this method does nothing.
      Parameters:
      id - the image id returned by createImage
      Returns:
      true if the image was removed, false otherwise
    • createAnimation

      int createAnimation(@NonNull LVGLImage[] images, @NonNull Anchor anchor, int duration)
      Creates an animation out of an array of images. This will count against your 3 image limit. This means if your array length is larger than 3, only the last 3 images will be used. Also, previously created images could be overwritten.

      Note that only 1 animation can be allocated. If you create more than this, you will start overwriting previously created animations.
      Parameters:
      images - an array of images
      anchor - where to anchor the animation
      duration - the duration, in milliseconds, of the entire animation (must be greater than zero)
      Returns:
      an int that can be used to update the animation or -1 if the animation can't be created
    • createAnimation

      int createAnimation(@NonNull LVGLImage[] images, @NonNull Anchor anchor, int offsetX, int offsetY, int duration)
      Creates an animation out of an array of images. This will count against your 3 image limit. This means if your array length is larger than 3, only the last 3 images will be used. Also, previously created images could be overwritten.

      Note that only 1 animation can be allocated. If you create more than this, you will start overwriting previously created animations.
      Parameters:
      images - an array of images
      anchor - where to anchor the animation
      offsetX - the horizontal offset
      offsetY - the vertical offset
      duration - the duration, in milliseconds, of the entire animation (must be greater than zero)
      Returns:
      an int that can be used to update the animation or -1 if the animation can't be created
    • moveAnimation

      boolean moveAnimation(int id, int x, int y)
      Moves an animation to a new absolute location on screen. If the provided id is invalid, this method does nothing.
      Parameters:
      id - the animation id returned by createAnimation
      x - new absolute x position
      y - new absolute y position
      Returns:
      true if the animation was moved, false otherwise
    • moveAnimation

      boolean moveAnimation(int id, int x, int y, int durationMs)
      Moves an animation to a new absolute location on screen. If the provided id is invalid, this method does nothing.
      Parameters:
      id - the animation id returned by createAnimation
      x - new absolute x position
      y - new absolute y position
      durationMs - duration in milliseconds over which to animate the move (0 = immediate)
      Returns:
      true if the animation was moved, false otherwise
    • setAnimationVisible

      boolean setAnimationVisible(int id, boolean visible)
      Changes visibility of an animation. If the provided id is invalid, this method does nothing.
      Parameters:
      id - the animation id returned by createAnimation
      visible - new visibility
      Returns:
      true if the animation visibility was changed, false otherwise
    • removeAnimation

      boolean removeAnimation(int id)
      Removes a previously created animation. If the provided id is invalid, this method does nothing.
      Parameters:
      id - the animation id returned by createAnimation
      Returns:
      true if the animation was removed, false otherwise
    • createText

      int createText(@NonNull String text, @NonNull Anchor anchor)
      Creates an identifiable block of text that can be manipulated. The alignment will be AUTO and the color will be WHITE. The text will initially be visible.

      Note that only 7 text blocks can be allocated. If you create more than this, you will start overwriting previously created text blocks.
      Parameters:
      text - the initial text
      anchor - where to anchor the text
      Returns:
      an int that can be used to update the text or -1 if the text can't be created
    • createText

      int createText(@NonNull String text, @NonNull TextAlignment alignment, @NonNull UltraliteColor color, @NonNull Anchor anchor, boolean visible)
      Creates an identifiable block of text that can be manipulated.

      Note that only 7 text blocks can be allocated. If you create more than this, you will start overwriting previously created text blocks.
      Parameters:
      text - the initial text
      alignment - the text alignment
      color - the text color
      anchor - where to Anchor the text
      visible - initial visibility of the text
      Returns:
      an int that can be used to update the text or -1 if the text can't be created
    • createText

      int createText(@NonNull String text, @NonNull TextAlignment alignment, @NonNull UltraliteColor color, @NonNull Anchor anchor, int offsetX, int offsetY, int width, int height, @Nullable TextWrapMode wrap, boolean visible)
      Creates an identifiable block of text that can be manipulated.

      Note that only 7 text blocks can be allocated. If you create more than this, you will start overwriting previously created text blocks.
      Parameters:
      text - the initial text
      alignment - the text alignment
      color - the text color
      anchor - where to Anchor the text
      offsetX - the horizontal offset
      offsetY - the vertical offset
      width - the width of the text block, use -1 for auto
      height - the height of the text block, use -1 for auto
      wrap - the desired wrapping mode, null specifies no wrap mode
      visible - initial visibility of the text
      Returns:
      an int that can be used to update the text or -1 if the text can't be created
    • updateText

      boolean updateText(int id, @NonNull String text)
      Replaces the text displayed with a particular id. Location and visibility are not changed. If the provided id is invalid, this method does nothing.
      Parameters:
      id - the text id returned by createText
      text - the new text
      Returns:
      true if the text was updated, false otherwise
    • moveText

      boolean moveText(int id, @NonNull Anchor anchor, int offsetX, int offsetY)
      Moves text to a new location. If the provided id is invalid, this method does nothing.
      Parameters:
      id - the text id returned by createText
      anchor - new anchor
      offsetX - new x offset
      offsetY - new y offset
      Returns:
      true if the text was moved, false otherwise
    • moveText

      boolean moveText(int id, int offsetX, int offsetY, int durationMs)
      Moves text to a new location. If the provided id is invalid, this method does nothing.
      Parameters:
      id - the text id returned by createText
      offsetX - new x offset
      offsetY - new y offset
      durationMs - duration in milliseconds over which to animate the move (0 = immediate)
      Returns:
      true if the text was moved, false otherwise
    • setTextVisible

      boolean setTextVisible(int id, boolean visible)
      Changes visibility of text. If the provided id is invalid, this method does nothing.
      Parameters:
      id - the text id returned by createText
      visible - new visibility
      Returns:
      true if the text's visibility was changed, false otherwise
    • removeText

      boolean removeText(int id)
      Removes a previously created text block. If the provided id is invalid, this method does nothing.
      Parameters:
      id - the text id returned by createText
      Returns:
      true if the text was removed, false otherwise
    • commit

      void commit()
      Commits canvas changes made since the last commit.
    • commit

      void commit(UltraliteSDK.Canvas.CommitCallback callback)
      Commits canvas changes made since the last commit.
      Parameters:
      callback - callback to be notified when the commit is complete
    • clear

      void clear()
      Clears the entire canvas. This includes the background layer, all images and all text blocks.