Class TextToImageSlicer

java.lang.Object
com.vuzix.ultralite.utils.scroll.TextToImageSlicer

public class TextToImageSlicer extends Object

Utility class to convert blocks of text to image slices to send to the SCROLL layout.

This class does not interact with the glasses in any way. This is a convenience class to manipulates local data to create content that is appropriate to send to the glasses via the SDK.

This is used internally by AutoScroller and TextToImageSlicer, and may also be used directly.

Since:
1.4.0
See Also:
  • Constructor Details

    • TextToImageSlicer

      public TextToImageSlicer(String stringToSlice, int sliceHeight, int fontSize)
      Construct a slicer to convert a block of text to a series of image slices that can be sent to the SCROLL layout.
      Parameters:
      stringToSlice - String containing text to display
      sliceHeight - Height of each slice as configured in scrollLayoutConfig()
      fontSize - Point size of the font
      Since:
      1.4.0
    • TextToImageSlicer

      public TextToImageSlicer(String stringToSlice, int sliceHeight, int fontSize, int paddingPx)
      Construct a slicer to convert a block of text to a series of image slices that can be sent to the SCROLL layout.
      Parameters:
      stringToSlice - String containing text to display
      sliceHeight - Height of each slice as configured in scrollLayoutConfig()
      fontSize - Point size of the font
      paddingPx - Pixels on the device window to pad both left and right side
      Since:
      1.4.0
    • TextToImageSlicer

      public TextToImageSlicer(String stringToSlice, int sliceHeight, android.text.TextPaint textPaint, int paddingPx)
      Construct a slicer to convert a block of text to a series of image slices that can be sent to the SCROLL layout.
      Parameters:
      stringToSlice - String containing text to display
      sliceHeight - Height of each slice as configured in scrollLayoutConfig()
      textPaint - Defines the specific look of the text
      paddingPx - Pixels on the device window to pad both left and right side
      Since:
      1.4.0
    • TextToImageSlicer

      public TextToImageSlicer(TextToImageSlicer from)
      Create a deep copy of the TextToImageSlicer
      Parameters:
      from - TextToImageSlicer to copy
      Since:
      1.7.0
  • Method Details

    • peekSliceText

      public String peekSliceText()
      Call this to peek at the next sequential line of text that will be used if you call getNextSlice()
      Returns:
      String containing one line of text that will be rendered to the next image slice
      Since:
      1.4.0
    • getNextSlice

      public LVGLImage getNextSlice()
      Call this to get the next sequential line of text rendered to an image. Continue until it returns null, or until hasMoreSlices() returns false. Each call to this method increments an internal iterator.
      Returns:
      LVGLImage containing a single line of text rendered to an image
      Since:
      1.4.0
    • getSliceAt

      public LVGLImage getSliceAt(int lineIndex)
      Call this to get a specific line of text rendered to an image.
      Parameters:
      lineIndex - zero-based index, up to ( getNumLines()-1 )
      Returns:
      LVGLImage containing a single line of text rendered to an image
      Since:
      1.4.0
    • getStringAt

      public String getStringAt(int lineIndex)
      Call this to get a specific line of text that will fit in a slice.
      Parameters:
      lineIndex - zero-based index, up to ( getNumLines()-1 )
      Returns:
      String of text
      Since:
      1.4.0
    • hasMoreSlices

      public Boolean hasMoreSlices()
      You may loop calling getNextSlice() as long as hasMoreSlices() is true
      Returns:
      - True if calling getNextSlice() will return a valid image
      Since:
      1.4.0
    • getNumLines

      public int getNumLines()
      Determine the number of lines into which we have sliced the given text
      Returns:
      number of lines of text after formatting to lines
      Since:
      1.4.0
    • firstDifferentIndexFrom

      public int firstDifferentIndexFrom(TextToImageSlicer that)
      Find the first sliced line with a difference between two TextToImageSlicer objects
      Parameters:
      that - TextToImageSlicer object against which to compare
      Returns:
      Valid zero-based index of the first line with a difference, or negative if both objects have the same content. Note, a non-negative index is guaranteed to be valid in at least one of the objects, but may be out of bounds in the other.
      Since:
      1.4.0
    • toString

      @NonNull public String toString()
      Return the string currently being sliced, useful for debugging
      Overrides:
      toString in class Object
      Returns:
      String representation of the sliced contents for debugging purposes
      Since:
      1.7.0
      See Also:
    • compareTo

      public TextToImageSlicer.SliceComparison compareTo(@Nullable TextToImageSlicer that)
      Compare one TextToImageSlicer to another for detailed results
      Parameters:
      that - TextToImageSlicer object against which to compare this object
      Returns:
      SliceComparison object containing deatils about the simliarities and differences
      Since:
      1.7.0
    • discardLeadingLines

      public void discardLeadingLines(int numberToDiscard)
      Discard the leading lines of text
      Parameters:
      numberToDiscard - Number of lines to discard from the beginning
      Since:
      1.7.0
    • truncateToLine

      public void truncateToLine(int numLinesNeeded)
      Truncate this sliced text to a given number of lines. Discard the remaining lines from the end. This may be useful when scrolling a subset of the text and adding it to the screen over time.
      Parameters:
      numLinesNeeded - Number of lines to retain from the current sliced text
      Since:
      1.7.0
    • replaceLineFrom

      public void replaceLineFrom(@NonNull TextToImageSlicer that, int indexToCopy)
      Replace a line in the current sliced text with a line from another textToImageSlicer
      Parameters:
      that - TextToImageSlicer from which we will copy the line of text
      indexToCopy - Zero-based index identifying the line to copy
      Since:
      1.7.0