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 this Layout on the specified canvas, with the highlight path drawn between the background and the text. |
| open Unit |
ellipsized(start: Int, end: Int)Callback for the ellipsizer to report what region it ellipsized. |
| open Int |
Returns the number of extra pixels of descent padding in the bottom line of the Layout. |
| open Int |
getEllipsisCount(line: Int)Returns the number of characters to be ellipsized away, or 0 if no ellipsis is to take place. |
| open Int |
getEllipsisStart(line: Int)Return the offset of the first character to be ellipsized away, relative to the start of the line. |
| open Int |
Return the width to which this layout is ellipsized. |
| open Int |
Return the total height of this layout. |
| open Boolean |
getLineContainsTab(line: Int)Returns whether the specified line contains one or more characters that need to be handled specially, like tabs. |
| open Int |
Return the number of lines of text in this layout. |
| open Int |
getLineDescent(line: Int)Return the descent of the specified line(0…getLineCount() - 1). |
| Layout.Directions! |
getLineDirections(line: Int)Returns the directional run information for the specified line. |
| open Float |
getLineMax(line: Int)Gets the unsigned horizontal extent of the specified line, including leading margin indent, but excluding trailing whitespace. |
| open Int |
getLineStart(line: Int)Return the text offset of the beginning of the specified line ( 0…getLineCount()). |
| open Int |
getLineTop(line: Int)Return the vertical position of the top of the specified line (0…getLineCount()). |
| open Float |
getLineWidth(line: Int)Gets the unsigned horizontal extent of the specified line, including leading margin indent and trailing whitespace. |
| open Int |
getParagraphDirection(line: Int)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 |
| open Int |
Returns the (negative) number of extra pixels of ascent padding in the top line of the Layout. |
| 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 |
Return true if the fallback line space is enabled in this Layout. |
| 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 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 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)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
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
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
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
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
open fun draw(
c: Canvas!,
highlight: Path!,
highlightpaint: Paint!,
cursorOffset: Int
): Unit
Draw this Layout on the specified canvas, with the highlight path drawn between the background and the text.
| 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
open fun ellipsized(
start: Int,
end: Int
): Unit
Callback for the ellipsizer to report what region it ellipsized.
getBottomPadding
open fun getBottomPadding(): Int
Returns the number of extra pixels of descent padding in the bottom line of the Layout.
getEllipsisCount
open fun getEllipsisCount(line: Int): Int
Returns the number of characters to be ellipsized away, or 0 if no ellipsis is to take place.
getEllipsisStart
open fun getEllipsisStart(line: Int): Int
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().)
getEllipsizedWidth
open fun getEllipsizedWidth(): Int
Return the width to which this layout is ellipsized. If no ellipsize is applied, the same amount of getWidth is returned.
| Return | |
|---|---|
Int |
the amount of ellipsized width in pixels. Value is 0 or greater |
getLineContainsTab
open fun getLineContainsTab(line: Int): Boolean
Returns whether the specified line contains one or more characters that need to be handled specially, like tabs.
getLineCount
open fun getLineCount(): Int
Return the number of lines of text in this layout.
getLineDescent
open fun getLineDescent(line: Int): Int
Return the descent of the specified line(0…getLineCount() - 1).
getLineDirections
fun getLineDirections(line: Int): Layout.Directions!
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.
getLineMax
open fun getLineMax(line: Int): Float
Gets the unsigned horizontal extent of the specified line, including leading margin indent, but excluding trailing whitespace.
getLineStart
open fun getLineStart(line: Int): Int
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.
getLineTop
open fun getLineTop(line: Int): Int
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.
getLineWidth
open fun getLineWidth(line: Int): Float
Gets the unsigned horizontal extent of the specified line, including leading margin indent and trailing whitespace.
getParagraphDirection
open fun getParagraphDirection(line: Int): Int
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 DIR_LEFT_TO_RIGHT, DIR_RIGHT_TO_LEFT).
getTopPadding
open fun getTopPadding(): Int
Returns the (negative) number of extra pixels of ascent padding in the top line of the Layout.
isBoring
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
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
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
open fun isFallbackLineSpacingEnabled(): Boolean
Return true if the fallback line space is enabled in this Layout.
| Return | |
|---|---|
Boolean |
true if the fallback line space is enabled. Otherwise, returns false. |
make
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. |
make
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
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 |
replaceOrMake
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
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
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 |