Class BoringLayout

java.lang.Object
icyllis.modernui.text.Layout
icyllis.modernui.text.BoringLayout
All Implemented Interfaces:
TextUtils.EllipsizeCallback

public class BoringLayout extends Layout implements TextUtils.EllipsizeCallback
A BoringLayout is a very simple Layout implementation for text that fits on a single line and is all left-to-right characters. You will probably never want to make one of these yourself; if you do, be sure to call isBoring(java.lang.CharSequence, icyllis.modernui.text.TextPaint) first to make sure the text meets the criteria.

This class is used by widgets to control text layout. You should not need to use this class directly unless you are implementing your own widget or custom display object, in which case you are encouraged to use a Layout.

  • Constructor Details

    • BoringLayout

      public BoringLayout(CharSequence source, TextPaint paint, int outerWidth, Layout.Alignment align, BoringLayout.Metrics metrics, boolean includePad)
      Parameters:
      source - the text to render
      paint - the default paint for the layout
      outerWidth - the wrapping width for the text
      align - whether to left, right, or center the text
      metrics - #Metrics instance that contains information about FontMetrics and line width
      includePad - set whether to include extra space beyond font ascent and descent which is needed to avoid clipping in some scripts
    • BoringLayout

      public BoringLayout(CharSequence source, TextPaint paint, int outerWidth, Layout.Alignment align, BoringLayout.Metrics metrics, boolean includePad, TextUtils.TruncateAt ellipsize, int ellipsizedWidth)
      Parameters:
      source - the text to render
      paint - the default paint for the layout
      outerWidth - the wrapping width for the text
      align - whether to left, right, or center the text
      metrics - #Metrics instance that contains information about FontMetrics and line width
      includePad - set whether to include extra space beyond font ascent and descent which is needed to avoid clipping in some scripts
      ellipsize - whether to ellipsize the text if width of the text is longer than the requested outerwidth
      ellipsizedWidth - the width to which this Layout is ellipsizing. If ellipsize is null, or is TextUtils.TruncateAt.MARQUEE this value is not used, outerwidth is used instead
  • Method Details

    • make

      public static BoringLayout make(CharSequence source, TextPaint paint, int outerWidth, Layout.Alignment align, BoringLayout.Metrics metrics, boolean includePad)
      Utility function to construct a BoringLayout instance.
      Parameters:
      source - the text to render
      paint - the default paint for the layout
      outerWidth - the wrapping width for the text
      align - whether to left, right, or center the text
      metrics - #Metrics instance that contains information about FontMetrics and line width
      includePad - set whether to include extra space beyond font ascent and descent which is needed to avoid clipping in some scripts
    • make

      public static BoringLayout make(CharSequence source, TextPaint paint, int outerWidth, Layout.Alignment align, BoringLayout.Metrics metrics, boolean includePad, TextUtils.TruncateAt ellipsize, int ellipsizedWidth)
      Utility function to construct a BoringLayout instance.
      Parameters:
      source - the text to render
      paint - the default paint for the layout
      outerWidth - the wrapping width for the text
      align - whether to left, right, or center the text
      metrics - #Metrics instance that contains information about FontMetrics and line width
      includePad - set whether to include extra space beyond font ascent and descent which is needed to avoid clipping in some scripts
      ellipsize - whether to ellipsize the text if width of the text is longer than the requested width
      ellipsizedWidth - the width to which this Layout is ellipsizing. If ellipsize is null, or is TextUtils.TruncateAt.MARQUEE this value is not used, outerWidth is used instead
    • replaceOrMake

      public BoringLayout replaceOrMake(CharSequence source, TextPaint paint, int outerWidth, Layout.Alignment align, BoringLayout.Metrics metrics, boolean includePad)
      Returns a BoringLayout for the specified text, potentially reusing this one if it is already suitable. The caller must make sure that no one is still using this Layout.
      Parameters:
      source - the text to render
      paint - the default paint for the layout
      outerWidth - the wrapping width for the text
      align - whether to left, right, or center the text
      metrics - #Metrics instance that contains information about FontMetrics and line width
      includePad - set whether to include extra space beyond font ascent and descent which is needed to avoid clipping in some scripts
    • replaceOrMake

      public BoringLayout replaceOrMake(CharSequence source, TextPaint paint, int outerWidth, Layout.Alignment align, BoringLayout.Metrics metrics, boolean includePad, TextUtils.TruncateAt ellipsize, int ellipsizedWidth)
      Returns a BoringLayout for the specified text, potentially reusing this one if it is already suitable. The caller must make sure that no one is still using this Layout.
      Parameters:
      source - the text to render
      paint - the default paint for the layout
      outerWidth - the wrapping width for the text
      align - whether to left, right, or center the text
      metrics - #Metrics instance that contains information about FontMetrics and line width
      includePad - set whether to include extra space beyond font ascent and descent which is needed to avoid clipping in some scripts
      ellipsize - whether to ellipsize the text if width of the text is longer than the requested width
      ellipsizedWidth - the width to which this Layout is ellipsizing. If ellipsize is null, or is TextUtils.TruncateAt.MARQUEE this value is not used, outerwidth is used instead
    • isBoring

      public static BoringLayout.Metrics isBoring(CharSequence text, TextPaint paint)
      Determine and compute metrics if given text can be handled by BoringLayout.
      Parameters:
      text - a text
      paint - a paint
      Returns:
      layout metric for the given text. null if given text is unable to be handled by BoringLayout.
    • isBoring

      public static BoringLayout.Metrics isBoring(CharSequence text, TextPaint paint, BoringLayout.Metrics metrics)
      Determine and compute metrics if given text can be handled by BoringLayout.
      Parameters:
      text - a text
      paint - a paint
      metrics - a metrics object to be recycled. If null is passed, this function creat new object.
      Returns:
      layout metric for the given text. If metrics is not null, this method fills values to given metrics object instead of allocating new metrics object. null if given text is unable to be handled by BoringLayout.
    • isBoring

      @Nullable public static BoringLayout.Metrics isBoring(@Nonnull CharSequence text, TextPaint paint, TextDirectionHeuristic textDir, BoringLayout.Metrics metrics)
      Returns null if not boring; the width, ascent, and descent in the provided Metrics object (or a new one if the provided one was null) if boring.
    • getHeight

      public int getHeight()
      Description copied from class: Layout
      Return the total height of this layout.
      Overrides:
      getHeight in class Layout
    • getLineCount

      public int getLineCount()
      Description copied from class: Layout
      Return the number of lines of text in this layout.
      Specified by:
      getLineCount in class Layout
    • getLineTop

      public int getLineTop(int line)
      Description copied from class: Layout
      Return the vertical position of the top of the specified line (0…getLineCount()). If the specified line is equal to the line count, returns the bottom of the last line.
      Specified by:
      getLineTop in class Layout
    • getLineDescent

      public int getLineDescent(int line)
      Description copied from class: Layout
      Return the descent of the specified line(0…getLineCount() - 1).
      Specified by:
      getLineDescent in class Layout
    • getLineStart

      public int getLineStart(int line)
      Description copied from class: Layout
      Return the text offset of the beginning of the specified line ( 0…getLineCount()). If the specified line is equal to the line count, returns the length of the text.
      Specified by:
      getLineStart in class Layout
    • getParagraphDirection

      public int getParagraphDirection(int line)
      Description copied from class: Layout
      Returns the primary directionality of the paragraph containing the specified line, either 1 for left-to-right lines, or -1 for right-to-left lines (see Layout.DIR_LEFT_TO_RIGHT, Layout.DIR_RIGHT_TO_LEFT).
      Specified by:
      getParagraphDirection in class Layout
    • getLineContainsTab

      public boolean getLineContainsTab(int line)
      Description copied from class: Layout
      Returns whether the specified line contains one or more characters that need to be handled specially, like tabs.
      Specified by:
      getLineContainsTab in class Layout
    • getLineMax

      public float getLineMax(int line)
      Description copied from class: Layout
      Gets the unsigned horizontal extent of the specified line, including leading margin indent, but excluding trailing whitespace.
      Overrides:
      getLineMax in class Layout
    • getLineWidth

      public float getLineWidth(int line)
      Description copied from class: Layout
      Gets the unsigned horizontal extent of the specified line, including leading margin indent and trailing whitespace.
      Overrides:
      getLineWidth in class Layout
    • getLineDirections

      public final Directions getLineDirections(int line)
      Description copied from class: Layout
      Returns the directional run information for the specified line. The array alternates counts of characters in left-to-right and right-to-left segments of the line.

      NOTE: this is inadequate to support bidirectional text, and will change.

      Specified by:
      getLineDirections in class Layout
    • getTopPadding

      public int getTopPadding()
      Description copied from class: Layout
      Returns the (negative) number of extra pixels of ascent padding in the top line of the Layout.
      Specified by:
      getTopPadding in class Layout
    • getBottomPadding

      public int getBottomPadding()
      Description copied from class: Layout
      Returns the number of extra pixels of descent padding in the bottom line of the Layout.
      Specified by:
      getBottomPadding in class Layout
    • getEllipsisCount

      public int getEllipsisCount(int line)
      Description copied from class: Layout
      Returns the number of characters to be ellipsized away, or 0 if no ellipsis is to take place.
      Specified by:
      getEllipsisCount in class Layout
    • getEllipsisStart

      public int getEllipsisStart(int line)
      Description copied from class: Layout
      Return the offset of the first character to be ellipsized away, relative to the start of the line. (So 0 if the beginning of the line is ellipsized, not getLineStart().)
      Specified by:
      getEllipsisStart in class Layout
    • getEllipsizedWidth

      public int getEllipsizedWidth()
      Description copied from class: Layout
      Return the width to which this Layout is ellipsizing, or Layout.getWidth() if it is not doing anything special.
      Overrides:
      getEllipsizedWidth in class Layout
    • drawText

      public void drawText(@NonNull Canvas canvas, int firstLine, int lastLine)
      Description copied from class: Layout
      Draw all visible text lines of this Layout on the specified canvas.

      Significantly, visible area given by firstLine and lastLine is computed by Layout.getLineRangeForDraw(Canvas). You may never just call this method without that method.

      Overrides:
      drawText in class Layout
      Parameters:
      canvas - the canvas to draw on
      firstLine - first line index (inclusive)
      lastLine - last line index (inclusive)
      See Also:
    • ellipsized

      public void ellipsized(int start, int end)
      Callback for the ellipsizer to report what region it ellipsized.
      Specified by:
      ellipsized in interface TextUtils.EllipsizeCallback