BoringLayout
open class BoringLayout : Layout, 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 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
| Inherited constants |
From class Layout
Int |
BREAK_STRATEGY_BALANCED
Value for break strategy indicating balanced line breaking. The breaks are chosen to make all lines as close to the same length as possible, including automatic hyphenation.
|
Int |
BREAK_STRATEGY_HIGH_QUALITY
Value for break strategy indicating high quality line breaking, including automatic hyphenation and doing whole-paragraph optimization of line breaks.
|
Int |
BREAK_STRATEGY_SIMPLE
Value for break strategy indicating simple line breaking. Automatic hyphens are not added (though soft hyphens are respected), and modifying text generally doesn't affect the layout before it (which yields a more consistent user experience when editing), but layout may not be the highest quality.
|
Float |
DEFAULT_LINESPACING_ADDITION
|
Float |
DEFAULT_LINESPACING_MULTIPLIER
|
Int |
DIR_LEFT_TO_RIGHT
|
Int |
DIR_RIGHT_TO_LEFT
|
Int |
HYPHENATION_FREQUENCY_FULL
Value for hyphenation frequency indicating the full amount of automatic hyphenation, typical in typography. Useful for running text and where it's important to put the maximum amount of text in a screen with limited space.
|
Int |
HYPHENATION_FREQUENCY_NONE
Value for hyphenation frequency indicating no automatic hyphenation. Useful for backward compatibility, and for cases where the automatic hyphenation algorithm results in incorrect hyphenation. Mid-word breaks may still happen when a word is wider than the layout and there is otherwise no valid break. Soft hyphens are ignored and will not be used as suggestions for potential line breaks.
|
Int |
HYPHENATION_FREQUENCY_NORMAL
Value for hyphenation frequency indicating a light amount of automatic hyphenation, which is a conservative default. Useful for informal cases, such as short sentences or chat messages.
|
Int |
JUSTIFICATION_MODE_INTER_WORD
Value for justification mode indicating the text is justified by stretching word spacing.
|
Int |
JUSTIFICATION_MODE_NONE
Value for justification mode indicating no justification.
|
|
| Public methods |
| open Unit |
|
| open Unit |
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 |
|
| open Int |
|
| open Int |
|
| open Float |
|
| open Int |
|
| open Int |
|
| open static BoringLayout.Metrics! |
Determine and compute metrics if given text can be handled by BoringLayout.
|
| open static BoringLayout.Metrics! |
Determine and compute metrics if given text can be handled by BoringLayout.
|
| open static BoringLayout! |
Utility function to construct a BoringLayout instance.
|
| open static BoringLayout! |
Utility function to construct a BoringLayout instance.
|
| open BoringLayout! |
Returns a BoringLayout for the specified text, potentially reusing this one if it is already suitable.
|
| open BoringLayout! |
Returns a BoringLayout for the specified text, potentially reusing this one if it is already suitable.
|
| Inherited functions |
From class Layout
Unit |
draw(c: Canvas!)
Draw this Layout on the specified Canvas.
|
Layout.Alignment! |
getAlignment()
Return the base alignment of this layout.
|
Unit |
getCursorPath(point: Int, dest: Path!, editingBuffer: CharSequence!)
Fills in the specified Path with a representation of a cursor at the specified offset. This will often be a vertical line but can be multiple discontinuous lines in text with multiple directionalities.
|
Float |
getDesiredWidth(source: CharSequence!, paint: TextPaint!)
Return how wide a layout must be in order to display the specified text with one line per paragraph.
As of O, Uses TextDirectionHeuristics#FIRSTSTRONG_LTR as the default text direction heuristics. In the earlier versions uses TextDirectionHeuristics#LTR as the default.
|
Float |
getDesiredWidth(source: CharSequence!, start: Int, end: Int, paint: TextPaint!)
Return how wide a layout must be in order to display the specified text slice with one line per paragraph.
As of O, Uses TextDirectionHeuristics#FIRSTSTRONG_LTR as the default text direction heuristics. In the earlier versions uses TextDirectionHeuristics#LTR as the default.
|
Int |
getLineAscent(line: Int)
Get the ascent of the text on the specified line. The return value is negative to match the Paint.ascent() convention.
|
Int |
getLineBaseline(line: Int)
Return the vertical position of the baseline of the specified line.
|
Int |
getLineBottom(line: Int)
Return the vertical position of the bottom of the specified line.
|
Int |
getLineBounds(line: Int, bounds: Rect!)
Return the baseline for the specified line (0…getLineCount() - 1) If bounds is not null, return the top, left, right, bottom extents of the specified line in it.
|
Int |
getLineEnd(line: Int)
Return the text offset after the last character on the specified line.
|
Int |
getLineForOffset(offset: Int)
Get the line number on which the specified text offset appears. If you ask for a position before 0, you get 0; if you ask for a position beyond the end of the text, you get the last line.
|
Int |
getLineForVertical(vertical: Int)
Get the line number corresponding to the specified vertical position. If you ask for a position above 0, you get 0; if you ask for a position below the bottom of the text, you get the last line.
|
Float |
getLineLeft(line: Int)
Get the leftmost position that should be exposed for horizontal scrolling on the specified line.
|
Float |
getLineRight(line: Int)
Get the rightmost position that should be exposed for horizontal scrolling on the specified line.
|
Int |
getLineVisibleEnd(line: Int)
Return the text offset after the last visible character (so whitespace is not counted) on the specified line.
|
Int |
getOffsetForHorizontal(line: Int, horiz: Float)
Get the character offset on the specified line whose position is closest to the specified horizontal position.
|
Int |
getOffsetToLeftOf(offset: Int)
|
Int |
getOffsetToRightOf(offset: Int)
|
TextPaint! |
getPaint()
Return the base Paint properties for this layout. Do NOT change the paint, which may result in funny drawing for this layout.
|
Layout.Alignment! |
getParagraphAlignment(line: Int)
Get the alignment of the specified paragraph, taking into account markup attached to it.
|
Int |
getParagraphLeft(line: Int)
Get the left edge of the specified paragraph, inset by left margins.
|
Int |
getParagraphRight(line: Int)
Get the right edge of the specified paragraph, inset by right margins.
|
Float |
getPrimaryHorizontal(offset: Int)
Get the primary horizontal position for the specified text offset. This is the location where a new character would be inserted in the paragraph's primary direction.
|
Float |
getSecondaryHorizontal(offset: Int)
Get the secondary horizontal position for the specified text offset. This is the location where a new character would be inserted in the direction other than the paragraph's primary direction.
|
Unit |
getSelectionPath(start: Int, end: Int, dest: Path!)
Fills in the specified Path with a representation of a highlight between the specified offsets. This will often be a rectangle or a potentially discontinuous set of rectangles. If the start and end are the same, the returned path is empty.
|
Float |
getSpacingAdd()
Return the number of units of leading that are added to each line.
|
Float |
getSpacingMultiplier()
Return what the text height is multiplied by to get the line height.
|
CharSequence! |
getText()
Return the text that is displayed by this Layout.
|
Int |
getWidth()
Return the width of this layout.
|
Unit |
increaseWidthTo(wid: Int)
Increase the width of this layout to the specified width. Be careful to use this only when you know it is appropriate— it does not cause the text to reflow to use the full new width.
|
Boolean |
isRtlCharAt(offset: Int)
Returns true if the character at offset is right to left (RTL).
|
Boolean |
isSpanned()
|
|
Public constructors
<init>
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 |
<init>
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 |
Public methods
draw
open fun draw(
c: Canvas!,
highlight: Path!,
highlightpaint: Paint!,
cursorOffset: Int
): Unit
| Parameters |
canvas |
the canvas |
highlight |
Path!: the path of the highlight or cursor; can be null |
highlightPaint |
the paint for the 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
getEllipsisCount
open fun getEllipsisCount(line: Int): Int
getEllipsisStart
open fun getEllipsisStart(line: Int): Int
getEllipsizedWidth
open fun getEllipsizedWidth(): Int
getHeight
open fun getHeight(): Int
getLineContainsTab
open fun getLineContainsTab(line: Int): Boolean
getLineCount
open fun getLineCount(): Int
getLineDescent
open fun getLineDescent(line: Int): Int
getLineMax
open fun getLineMax(line: Int): Float
getLineStart
open fun getLineStart(line: Int): Int
getLineTop
open fun getLineTop(line: Int): Int
getLineWidth
open fun getLineWidth(line: Int): Float
getParagraphDirection
open fun getParagraphDirection(line: Int): Int
getTopPadding
open fun getTopPadding(): Int
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.
| 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. |
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!,
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 |