Builder
class Builder
kotlin.Any | |
↳ | android.graphics.text.MeasuredText.Builder |
Helper class for creating a MeasuredText
.
<code> Paint paint = new Paint(); String text = "Hello, Android."; MeasuredText mt = new MeasuredText.Builder(text.toCharArray()) .appendStyleRun(paint, text.length, false) .build(); </code>
Summary
Constants | |
---|---|
static Int |
A value for hyphenation calculation mode. |
static Int |
A value for hyphenation calculation mode. |
static Int |
A value for hyphenation calculation mode. |
Public constructors | |
---|---|
Builder(text: MeasuredText) Construct a builder with existing MeasuredText. |
|
Construct a builder. |
Public methods | |
---|---|
MeasuredText.Builder |
appendReplacementRun(paint: Paint, length: Int, width: Float) Used to inform the text layout that the given length is replaced with the object of given width. |
MeasuredText.Builder |
appendStyleRun(paint: Paint, lineBreakConfig: LineBreakConfig?, length: Int, isRtl: Boolean) Apply styles to the given length. |
MeasuredText.Builder |
appendStyleRun(paint: Paint, length: Int, isRtl: Boolean) Apply styles to the given length. |
MeasuredText |
build() Creates a MeasuredText. |
MeasuredText.Builder |
setComputeHyphenation(computeHyphenation: Boolean) By passing true to this method, the build method will compute all possible hyphenation pieces as well. |
MeasuredText.Builder |
setComputeHyphenation(mode: Int) By passing true to this method, the build method will calculate hyphenation break points faster with ignoring some typographic features, e. |
MeasuredText.Builder |
setComputeLayout(computeLayout: Boolean) By passing true to this method, the build method will compute all full layout information. |
Constants
HYPHENATION_MODE_FAST
static val HYPHENATION_MODE_FAST: Int
A value for hyphenation calculation mode. This value indicates that hyphenation points are calculated with faster algorithm. This algorithm measures text width with ignoring the context of hyphen character shaping, e.g. kerning.
Value: 2
HYPHENATION_MODE_NONE
static val HYPHENATION_MODE_NONE: Int
A value for hyphenation calculation mode. This value indicates that no hyphenation points are calculated.
Value: 0
HYPHENATION_MODE_NORMAL
static val HYPHENATION_MODE_NORMAL: Int
A value for hyphenation calculation mode. This value indicates that hyphenation points are calculated.
Value: 1
Public constructors
Builder
Builder(text: MeasuredText)
Construct a builder with existing MeasuredText. The MeasuredText returned by build method will hold a reference of the text. Developer is not supposed to modify the text.
Parameters | |
---|---|
text |
MeasuredText: a text This value cannot be null . |
Builder
Builder(text: CharArray)
Construct a builder. The MeasuredText returned by build method will hold a reference of the text. Developer is not supposed to modify the text.
Parameters | |
---|---|
text |
CharArray: a text This value cannot be null . |
Public methods
appendReplacementRun
fun appendReplacementRun(
paint: Paint,
length: Int,
width: Float
): MeasuredText.Builder
Used to inform the text layout that the given length is replaced with the object of given width. Keeps an internal offset which increases at every append. The initial value for this offset is zero. After the style is applied the internal offset is moved to offset + length
, and next call will start from this new position. Informs the layout engine that the given length should not be processed, instead the provided width should be used for calculating the width of that range.
Parameters | |
---|---|
length |
Int: a length to be replaced with the object, can not exceed the length of the text Value is 0 or greater |
width |
Float: a replacement width of the range The units of this value are pixels. Value is 0 or greater |
paint |
Paint: This value cannot be null . |
Return | |
---|---|
MeasuredText.Builder |
This value cannot be null . |
appendStyleRun
fun appendStyleRun(
paint: Paint,
lineBreakConfig: LineBreakConfig?,
length: Int,
isRtl: Boolean
): MeasuredText.Builder
Apply styles to the given length. Keeps an internal offset which increases at every append. The initial value for this offset is zero. After the style is applied the internal offset is moved to offset + length
, and next call will start from this new position.
Parameters | |
---|---|
paint |
Paint: a paint This value cannot be null . |
lineBreakConfig |
LineBreakConfig?: a line break configuration. This value may be null . |
length |
Int: a length to be applied with a given paint, can not exceed the length of the text Value is 0 or greater |
isRtl |
Boolean: true if the text is in RTL context, otherwise false. |
Return | |
---|---|
MeasuredText.Builder |
This value cannot be null . |
appendStyleRun
fun appendStyleRun(
paint: Paint,
length: Int,
isRtl: Boolean
): MeasuredText.Builder
Apply styles to the given length. Keeps an internal offset which increases at every append. The initial value for this offset is zero. After the style is applied the internal offset is moved to offset + length
, and next call will start from this new position.
Paint.TEXT_RUN_FLAG_RIGHT_EDGE
and Paint.TEXT_RUN_FLAG_LEFT_EDGE
are ignored and treated as both of them are set.
Parameters | |
---|---|
paint |
Paint: a paint This value cannot be null . |
length |
Int: a length to be applied with a given paint, can not exceed the length of the text Value is 0 or greater |
isRtl |
Boolean: true if the text is in RTL context, otherwise false. |
Return | |
---|---|
MeasuredText.Builder |
This value cannot be null . |
build
fun build(): MeasuredText
Creates a MeasuredText. Once you called build() method, you can't reuse the Builder class again.
Return | |
---|---|
MeasuredText |
This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalStateException |
if the whole text is not covered by one or more runs (style or replacement) |
setComputeHyphenation
funsetComputeHyphenation(computeHyphenation: Boolean): MeasuredText.Builder
Deprecated: use setComputeHyphenation(int) instead.
By passing true to this method, the build method will compute all possible hyphenation pieces as well. If you don't want to use automatic hyphenation, you can pass false to this method and save the computation time of hyphenation. The default value is false. Even if you pass false to this method, you can still enable automatic hyphenation of LineBreaker but line break computation becomes slower.
Parameters | |
---|---|
computeHyphenation |
Boolean: true if you want to use automatic hyphenations. |
Return | |
---|---|
MeasuredText.Builder |
This value cannot be null . |
setComputeHyphenation
fun setComputeHyphenation(mode: Int): MeasuredText.Builder
By passing true to this method, the build method will calculate hyphenation break points faster with ignoring some typographic features, e.g. kerning. HYPHENATION_MODE_NONE
is by default.
Parameters | |
---|---|
mode |
Int: a hyphenation mode. Value is android.graphics.text.MeasuredText.Builder#HYPHENATION_MODE_NONE , android.graphics.text.MeasuredText.Builder#HYPHENATION_MODE_NORMAL , or android.graphics.text.MeasuredText.Builder#HYPHENATION_MODE_FAST |
Return | |
---|---|
MeasuredText.Builder |
This value cannot be null . |
setComputeLayout
fun setComputeLayout(computeLayout: Boolean): MeasuredText.Builder
By passing true to this method, the build method will compute all full layout information. If you don't use MeasuredText.getBounds(int,int,android.graphics.Rect)
, you can pass false to this method and save the memory spaces. The default value is true. Even if you pass false to this method, you can still call getBounds but it becomes slower.
Parameters | |
---|---|
computeLayout |
Boolean: true if you want to retrieve full layout info, e.g. bbox. |
Return | |
---|---|
MeasuredText.Builder |
This value cannot be null . |