Added in API level 1

BoringLayout


open class BoringLayout : Layout, TextUtils.EllipsizeCallback
kotlin.Any
   ↳ android.text.Layout
   ↳ android.text.BoringLayout

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 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 instead of calling Canvas.drawText() directly.

Summary

Nested classes
open

Inherited constants
Public constructors
BoringLayout(source: CharSequence!, paint: TextPaint!, outerwidth: Int, align: Layout.Alignment!, spacingMult: Float, spacingAdd: Float, metrics: BoringLayout.Metrics!, includePad: Boolean)

BoringLayout(source: CharSequence!, paint: TextPaint!, outerWidth: Int, align: Layout.Alignment!, spacingMult: Float, spacingAdd: Float, metrics: BoringLayout.Metrics!, includePad: Boolean, ellipsize: TextUtils.TruncateAt!, ellipsizedWidth: Int)

BoringLayout(source: CharSequence, paint: TextPaint, outerWidth: Int, align: Layout.Alignment, spacingMult: Float, spacingAdd: Float, metrics: BoringLayout.Metrics, includePad: Boolean, ellipsize: TextUtils.TruncateAt?, ellipsizedWidth: Int, useFallbackLineSpacing: Boolean)

Public methods
open RectF

Get an actual bounding box that draws text content.

open Unit
draw(c: Canvas!, highlight: Path!, highlightpaint: Paint!, cursorOffset: Int)

open Unit
ellipsized(start: Int, end: Int)

Callback for the ellipsizer to report what region it ellipsized.

open Int

open Int

open Int

open Int

open Int

open Boolean

open Int

open Int

Layout.Directions!

open Float
getLineMax(line: Int)

open Int

open Int
getLineTop(line: Int)

open Float

open Int

open Int

open static BoringLayout.Metrics!
isBoring(text: CharSequence!, paint: TextPaint!)

Determine and compute metrics if given text can be handled by BoringLayout.

open static BoringLayout.Metrics!
isBoring(text: CharSequence!, paint: TextPaint!, metrics: BoringLayout.Metrics!)

Determine and compute metrics if given text can be handled by BoringLayout.

open static BoringLayout.Metrics?
isBoring(text: CharSequence, paint: TextPaint, textDir: TextDirectionHeuristic, useFallbackLineSpacing: Boolean, metrics: BoringLayout.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.

open Boolean

open static BoringLayout!
make(source: CharSequence!, paint: TextPaint!, outerWidth: Int, align: Layout.Alignment!, spacingMult: Float, spacingAdd: Float, metrics: BoringLayout.Metrics!, includePad: Boolean)

Utility function to construct a BoringLayout instance.

open static BoringLayout!
make(source: CharSequence!, paint: TextPaint!, outerWidth: Int, align: Layout.Alignment!, spacingmult: Float, spacingadd: Float, metrics: BoringLayout.Metrics!, includePad: Boolean, ellipsize: TextUtils.TruncateAt!, ellipsizedWidth: Int)

Utility function to construct a BoringLayout instance.

open static BoringLayout
make(source: CharSequence, paint: TextPaint, outerWidth: Int, align: Layout.Alignment, metrics: BoringLayout.Metrics, includePad: Boolean, ellipsize: TextUtils.TruncateAt?, ellipsizedWidth: Int, useFallbackLineSpacing: Boolean)

Utility function to construct a BoringLayout instance.

open BoringLayout!
replaceOrMake(source: CharSequence!, paint: TextPaint!, outerwidth: Int, align: Layout.Alignment!, spacingMult: Float, spacingAdd: Float, metrics: BoringLayout.Metrics!, includePad: Boolean)

Returns a BoringLayout for the specified text, potentially reusing this one if it is already suitable.

open BoringLayout
replaceOrMake(source: CharSequence, paint: TextPaint, outerWidth: Int, align: Layout.Alignment, metrics: BoringLayout.Metrics, includePad: Boolean, ellipsize: TextUtils.TruncateAt?, ellipsizedWidth: Int, useFallbackLineSpacing: Boolean)

Returns a BoringLayout for the specified text, potentially reusing this one if it is already suitable.

open BoringLayout!
replaceOrMake(source: CharSequence!, paint: TextPaint!, outerWidth: Int, align: Layout.Alignment!, spacingMult: Float, spacingAdd: Float, metrics: BoringLayout.Metrics!, includePad: Boolean, ellipsize: TextUtils.TruncateAt!, ellipsizedWidth: Int)

Returns a BoringLayout for the specified text, potentially reusing this one if it is already suitable.

Inherited functions
Inherited properties

Public constructors

BoringLayout

Added in API level 1
BoringLayout(
    source: CharSequence!,
    paint: TextPaint!,
    outerwidth: Int,
    align: Layout.Alignment!,
    spacingMult: Float,
    spacingAdd: Float,
    metrics: BoringLayout.Metrics!,
    includePad: Boolean)
Parameters
source CharSequence!: the text to render
paint TextPaint!: the default paint for the layout
outerwidth Int: the wrapping width for the text
align Layout.Alignment!: whether to left, right, or center the text
spacingMult Float: this value is no longer used by BoringLayout
spacingAdd Float: this value is no longer used by BoringLayout
metrics BoringLayout.Metrics!: Metrics instance that contains information about FontMetrics and line width
includePad Boolean: set whether to include extra space beyond font ascent and descent which is needed to avoid clipping in some scripts

BoringLayout

Added in API level 1
BoringLayout(
    source: CharSequence!,
    paint: TextPaint!,
    outerWidth: Int,
    align: Layout.Alignment!,
    spacingMult: Float,
    spacingAdd: Float,
    metrics: BoringLayout.Metrics!,
    includePad: Boolean,
    ellipsize: TextUtils.TruncateAt!,
    ellipsizedWidth: Int)
Parameters
source CharSequence!: the text to render
paint TextPaint!: the default paint for the layout
outerWidth Int: the wrapping width for the text
align Layout.Alignment!: whether to left, right, or center the text
spacingMult Float: this value is no longer used by BoringLayout
spacingAdd Float: this value is no longer used by BoringLayout
metrics BoringLayout.Metrics!: Metrics instance that contains information about FontMetrics and line width
includePad Boolean: set whether to include extra space beyond font ascent and descent which is needed to avoid clipping in some scripts
ellipsize TextUtils.TruncateAt!: whether to ellipsize the text if width of the text is longer than the requested outerWidth
ellipsizedWidth Int: 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

BoringLayout

Added in API level 33
BoringLayout(
    source: CharSequence,
    paint: TextPaint,
    outerWidth: Int,
    align: Layout.Alignment,
    spacingMult: Float,
    spacingAdd: Float,
    metrics: BoringLayout.Metrics,
    includePad: Boolean,
    ellipsize: TextUtils.TruncateAt?,
    ellipsizedWidth: Int,
    useFallbackLineSpacing: Boolean)
Parameters
source CharSequence: the text to render This value cannot be null.
paint TextPaint: the default paint for the layout This value cannot be null.
outerWidth Int: the wrapping width for the text Value is 0 or greater
align Layout.Alignment: whether to left, right, or center the text This value cannot be null.
spacingMult Float: this value is no longer used by BoringLayout
spacingAdd Float: this value is no longer used by BoringLayout
metrics BoringLayout.Metrics: Metrics instance that contains information about FontMetrics and line width This value cannot be null.
includePad Boolean: set whether to include extra space beyond font ascent and descent which is needed to avoid clipping in some scripts
ellipsize TextUtils.TruncateAt?: whether to ellipsize the text if width of the text is longer than the requested outerWidth. null if ellipsis is not applied.
ellipsizedWidth Int: 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 Value is 0 or greater
useFallbackLineSpacing Boolean: True for adjusting the line spacing based on fallback fonts. False for keeping the first font's line height. If some glyphs requires larger vertical spaces, by passing true to this argument, the layout increase the line height to fit all glyphs.

Public methods

computeDrawingBoundingBox

Added in API level 35
open fun computeDrawingBoundingBox(): RectF

Get an actual bounding box that draws text content. Note that the RectF#top and RectF#bottom may be different from the Layout#getLineTop(int) of the first line and Layout#getLineBottom(int) of the last line. The line top and line bottom are calculated based on yMin/yMax or ascent/descent value of font file. On the other hand, the drawing bounding boxes are calculated based on actual glyphs used there.

Return
RectF This value cannot be null.

draw

Added in API level 1
open fun draw(
    c: Canvas!,
    highlight: Path!,
    highlightpaint: Paint!,
    cursorOffset: Int
): Unit
Parameters
canvas the canvas
selectionHighlight the path of the selection highlight or cursor; can be null
selectionHighlightPaint the paint for the selection highlight
cursorOffsetVertical the amount to temporarily translate the canvas while rendering the highlight

ellipsized

Added in API level 1
open fun ellipsized(
    start: Int,
    end: Int
): Unit

Callback for the ellipsizer to report what region it ellipsized.

getBottomPadding

Added in API level 1
open fun getBottomPadding(): Int

getEllipsisCount

Added in API level 1
open fun getEllipsisCount(line: Int): Int

getEllipsisStart

Added in API level 1
open fun getEllipsisStart(line: Int): Int

getEllipsizedWidth

Added in API level 1
open fun getEllipsizedWidth(): Int
Return
Int the amount of ellipsized width in pixels. Value is 0 or greater

getHeight

Added in API level 1
open fun getHeight(): Int

getLineContainsTab

Added in API level 1
open fun getLineContainsTab(line: Int): Boolean

getLineCount

Added in API level 1
open fun getLineCount(): Int

getLineDescent

Added in API level 1
open fun getLineDescent(line: Int): Int

getLineDirections

Added in API level 1
fun getLineDirections(line: Int): Layout.Directions!

getLineMax

Added in API level 1
open fun getLineMax(line: Int): Float

getLineStart

Added in API level 1
open fun getLineStart(line: Int): Int

getLineTop

Added in API level 1
open fun getLineTop(line: Int): Int

getLineWidth

Added in API level 1
open fun getLineWidth(line: Int): Float

getParagraphDirection

Added in API level 1
open fun getParagraphDirection(line: Int): Int

getTopPadding

Added in API level 1
open fun getTopPadding(): Int

isBoring

Added in API level 1
open static fun isBoring(
    text: CharSequence!,
    paint: TextPaint!
): BoringLayout.Metrics!

Determine and compute metrics if given text can be handled by BoringLayout.

Parameters
text CharSequence!: a text
paint TextPaint!: a paint
Return
BoringLayout.Metrics! layout metric for the given text. null if given text is unable to be handled by BoringLayout.

isBoring

Added in API level 1
open static fun isBoring(
    text: CharSequence!,
    paint: TextPaint!,
    metrics: BoringLayout.Metrics!
): BoringLayout.Metrics!

Determine and compute metrics if given text can be handled by BoringLayout.

Parameters
text CharSequence!: a text
paint TextPaint!: a paint
metrics BoringLayout.Metrics!: a metrics object to be recycled. If null is passed, this function creat new object.
Return
BoringLayout.Metrics! 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

Added in API level 33
open static fun isBoring(
    text: CharSequence,
    paint: TextPaint,
    textDir: TextDirectionHeuristic,
    useFallbackLineSpacing: Boolean,
    metrics: BoringLayout.Metrics?
): BoringLayout.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.

Parameters
text CharSequence: a text to be calculated text layout. This value cannot be null.
paint TextPaint: a paint object used for styling. This value cannot be null.
textDir TextDirectionHeuristic: a text direction. This value cannot be null.
useFallbackLineSpacing Boolean: True for adjusting the line spacing based on fallback fonts. False for keeping the first font's line height. If some glyphs requires larger vertical spaces, by passing true to this argument, the layout increase the line height to fit all glyphs.
metrics BoringLayout.Metrics?: the out metrics. This value may be null.
Return
BoringLayout.Metrics? metrics on success. null if text cannot be rendered by BoringLayout.

isFallbackLineSpacingEnabled

Added in API level 33
open fun isFallbackLineSpacingEnabled(): Boolean
Return
Boolean true if the fallback line space is enabled. Otherwise, returns false.

make

Added in API level 1
open static fun make(
    source: CharSequence!,
    paint: TextPaint!,
    outerWidth: Int,
    align: Layout.Alignment!,
    spacingMult: Float,
    spacingAdd: Float,
    metrics: BoringLayout.Metrics!,
    includePad: Boolean
): BoringLayout!

Utility function to construct a BoringLayout instance.

Parameters
source CharSequence!: the text to render
paint TextPaint!: the default paint for the layout
outerWidth Int: the wrapping width for the text
align Layout.Alignment!: whether to left, right, or center the text
spacingMult Float: this value is no longer used by BoringLayout
spacingAdd Float: this value is no longer used by BoringLayout
metrics BoringLayout.Metrics!: Metrics instance that contains information about FontMetrics and line width
includePad Boolean: set whether to include extra space beyond font ascent and descent which is needed to avoid clipping in some scripts

make

Added in API level 1
open static fun make(
    source: CharSequence!,
    paint: TextPaint!,
    outerWidth: Int,
    align: Layout.Alignment!,
    spacingmult: Float,
    spacingadd: Float,
    metrics: BoringLayout.Metrics!,
    includePad: Boolean,
    ellipsize: TextUtils.TruncateAt!,
    ellipsizedWidth: Int
): BoringLayout!

Utility function to construct a BoringLayout instance.

Parameters
source CharSequence!: the text to render
paint TextPaint!: the default paint for the layout
outerWidth Int: the wrapping width for the text
align Layout.Alignment!: whether to left, right, or center the text
spacingmult Float: this value is no longer used by BoringLayout
spacingadd Float: this value is no longer used by BoringLayout
metrics BoringLayout.Metrics!: Metrics instance that contains information about FontMetrics and line width
includePad Boolean: set whether to include extra space beyond font ascent and descent which is needed to avoid clipping in some scripts
ellipsize TextUtils.TruncateAt!: whether to ellipsize the text if width of the text is longer than the requested width
ellipsizedWidth Int: 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

make

Added in API level 33
open static fun make(
    source: CharSequence,
    paint: TextPaint,
    outerWidth: Int,
    align: Layout.Alignment,
    metrics: BoringLayout.Metrics,
    includePad: Boolean,
    ellipsize: TextUtils.TruncateAt?,
    ellipsizedWidth: Int,
    useFallbackLineSpacing: Boolean
): BoringLayout

Utility function to construct a BoringLayout instance. The spacing multiplier and additional amount spacing are not used by BoringLayout. Layout#getSpacingMultiplier() will return 1.0 and Layout#getSpacingAdd() will return 0.0.

Parameters
source CharSequence: the text to render This value cannot be null.
paint TextPaint: the default paint for the layout This value cannot be null.
outerWidth Int: the wrapping width for the text Value is 0 or greater
align Layout.Alignment: whether to left, right, or center the text This value cannot be null.
metrics BoringLayout.Metrics: Metrics instance that contains information about FontMetrics and line width This value cannot be null.
includePad Boolean: set whether to include extra space beyond font ascent and descent which is needed to avoid clipping in some scripts
ellipsize TextUtils.TruncateAt?: whether to ellipsize the text if width of the text is longer than the requested width. null if ellipsis is not applied.
ellipsizedWidth Int: 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 Value is 0 or greater
useFallbackLineSpacing Boolean: True for adjusting the line spacing based on fallback fonts. False for keeping the first font's line height. If some glyphs requires larger vertical spaces, by passing true to this argument, the layout increase the line height to fit all glyphs.
Return
BoringLayout This value cannot be null.

replaceOrMake

Added in API level 1
open fun replaceOrMake(
    source: CharSequence!,
    paint: TextPaint!,
    outerwidth: Int,
    align: Layout.Alignment!,
    spacingMult: Float,
    spacingAdd: Float,
    metrics: BoringLayout.Metrics!,
    includePad: Boolean
): BoringLayout!

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 CharSequence!: the text to render
paint TextPaint!: the default paint for the layout
outerwidth Int: the wrapping width for the text
align Layout.Alignment!: whether to left, right, or center the text
spacingMult Float: this value is no longer used by BoringLayout
spacingAdd Float: this value is no longer used by BoringLayout
metrics BoringLayout.Metrics!: Metrics instance that contains information about FontMetrics and line width
includePad Boolean: set whether to include extra space beyond font ascent and descent which is needed to avoid clipping in some scripts

replaceOrMake

Added in API level 33
open fun replaceOrMake(
    source: CharSequence,
    paint: TextPaint,
    outerWidth: Int,
    align: Layout.Alignment,
    metrics: BoringLayout.Metrics,
    includePad: Boolean,
    ellipsize: TextUtils.TruncateAt?,
    ellipsizedWidth: Int,
    useFallbackLineSpacing: Boolean
): BoringLayout

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. The spacing multiplier and additional amount spacing are not used by BoringLayout. Layout#getSpacingMultiplier() will return 1.0 and Layout#getSpacingAdd() will return 0.0.

Parameters
source CharSequence: the text to render This value cannot be null.
paint TextPaint: the default paint for the layout This value cannot be null.
outerWidth Int: the wrapping width for the text Value is 0 or greater
align Layout.Alignment: whether to left, right, or center the text This value cannot be null.
metrics BoringLayout.Metrics: Metrics instance that contains information about FontMetrics and line width This value cannot be null.
includePad Boolean: set whether to include extra space beyond font ascent and descent which is needed to avoid clipping in some scripts
ellipsize TextUtils.TruncateAt?: whether to ellipsize the text if width of the text is longer than the requested width. null if ellipsis not applied.
ellipsizedWidth Int: 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 Value is 0 or greater
useFallbackLineSpacing Boolean: True for adjusting the line spacing based on fallback fonts. False for keeping the first font's line height. If some glyphs requires larger vertical spaces, by passing true to this argument, the layout increase the line height to fit all glyphs.
Return
BoringLayout This value cannot be null.

replaceOrMake

Added in API level 1
open fun replaceOrMake(
    source: CharSequence!,
    paint: TextPaint!,
    outerWidth: Int,
    align: Layout.Alignment!,
    spacingMult: Float,
    spacingAdd: Float,
    metrics: BoringLayout.Metrics!,
    includePad: Boolean,
    ellipsize: TextUtils.TruncateAt!,
    ellipsizedWidth: Int
): BoringLayout!

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 CharSequence!: the text to render
paint TextPaint!: the default paint for the layout
outerWidth Int: the wrapping width for the text
align Layout.Alignment!: whether to left, right, or center the text
spacingMult Float: this value is no longer used by BoringLayout
spacingAdd Float: this value is no longer used by BoringLayout
metrics BoringLayout.Metrics!: Metrics instance that contains information about FontMetrics and line width
includePad Boolean: set whether to include extra space beyond font ascent and descent which is needed to avoid clipping in some scripts
ellipsize TextUtils.TruncateAt!: whether to ellipsize the text if width of the text is longer than the requested width
ellipsizedWidth Int: 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