Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Constants](https://developer.android.com/reference/android/graphics/text/MeasuredText.Builder#constants) \| [Ctors](https://developer.android.com/reference/android/graphics/text/MeasuredText.Builder#pubctors) \| [Methods](https://developer.android.com/reference/android/graphics/text/MeasuredText.Builder#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/graphics/text/MeasuredText.Builder#inhmethods)

# MeasuredText.Builder

*** ** * ** ***

` public static final class MeasuredText.Builder `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.graphics.text.MeasuredText.Builder |

<br />

*** ** * ** ***

Helper class for creating a `https://developer.android.com/reference/android/graphics/text/MeasuredText`.

<br />


    Paint paint = new Paint();
    String text = "Hello, Android.";
    MeasuredText mt = new MeasuredText.Builder(text.toCharArray())
         .appendStyleRun(paint, text.length, false)
         .build();

<br />

Note: The appendStyle and appendReplacementRun should be called to cover the text length.

<br />

## Summary

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/graphics/text/MeasuredText.Builder#HYPHENATION_MODE_FAST` A value for hyphenation calculation mode. |
| `int` | `https://developer.android.com/reference/android/graphics/text/MeasuredText.Builder#HYPHENATION_MODE_NONE` A value for hyphenation calculation mode. |
| `int` | `https://developer.android.com/reference/android/graphics/text/MeasuredText.Builder#HYPHENATION_MODE_NORMAL` A value for hyphenation calculation mode. |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/graphics/text/MeasuredText.Builder#Builder(android.graphics.text.MeasuredText)(https://developer.android.com/reference/android/graphics/text/MeasuredText text) ` Construct a builder with existing MeasuredText. |
| ` https://developer.android.com/reference/android/graphics/text/MeasuredText.Builder#Builder(char[])(char[] text) ` Construct a builder. |

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/android/graphics/text/MeasuredText.Builder` | ` https://developer.android.com/reference/android/graphics/text/MeasuredText.Builder#appendReplacementRun(android.graphics.Paint,%20int,%20float)(https://developer.android.com/reference/android/graphics/Paint paint, int length, float width) ` Used to inform the text layout that the given length is replaced with the object of given width. |
| ` https://developer.android.com/reference/android/graphics/text/MeasuredText.Builder` | ` https://developer.android.com/reference/android/graphics/text/MeasuredText.Builder#appendStyleRun(android.graphics.Paint,%20android.graphics.text.LineBreakConfig,%20int,%20boolean)(https://developer.android.com/reference/android/graphics/Paint paint, https://developer.android.com/reference/android/graphics/text/LineBreakConfig lineBreakConfig, int length, boolean isRtl) ` Apply styles to the given length. |
| ` https://developer.android.com/reference/android/graphics/text/MeasuredText.Builder` | ` https://developer.android.com/reference/android/graphics/text/MeasuredText.Builder#appendStyleRun(android.graphics.Paint,%20int,%20boolean)(https://developer.android.com/reference/android/graphics/Paint paint, int length, boolean isRtl) ` Apply styles to the given length. |
| ` https://developer.android.com/reference/android/graphics/text/MeasuredText` | ` https://developer.android.com/reference/android/graphics/text/MeasuredText.Builder#build()() ` Creates a MeasuredText. |
| ` https://developer.android.com/reference/android/graphics/text/MeasuredText.Builder` | ` https://developer.android.com/reference/android/graphics/text/MeasuredText.Builder#setComputeHyphenation(boolean)(boolean computeHyphenation) ` *This method was deprecated in API level 33. use setComputeHyphenation(int) instead.* |
| ` https://developer.android.com/reference/android/graphics/text/MeasuredText.Builder` | ` https://developer.android.com/reference/android/graphics/text/MeasuredText.Builder#setComputeHyphenation(int)(int mode) ` By passing true to this method, the build method will calculate hyphenation break points faster with ignoring some typographic features, e.g. kerning. |
| ` https://developer.android.com/reference/android/graphics/text/MeasuredText.Builder` | ` https://developer.android.com/reference/android/graphics/text/MeasuredText.Builder#setComputeLayout(boolean)(boolean computeLayout) ` By passing true to this method, the build method will compute all full layout information. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.

## Constants

### HYPHENATION_MODE_FAST

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int HYPHENATION_MODE_FAST
```

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.

<br />

Constant Value: 2 (0x00000002)

### HYPHENATION_MODE_NONE

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int HYPHENATION_MODE_NONE
```

A value for hyphenation calculation mode. This value indicates that no hyphenation points are calculated.

<br />

Constant Value: 0 (0x00000000)

### HYPHENATION_MODE_NORMAL

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int HYPHENATION_MODE_NORMAL
```

A value for hyphenation calculation mode. This value indicates that hyphenation points are calculated.

<br />

Constant Value: 1 (0x00000001)

## Public constructors

### Builder

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Builder (MeasuredText text)
```

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.

<br />

| Parameters ||
|---|---|
| `text` | `MeasuredText`: a text. This value cannot be `null`. <br /> |

### Builder

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Builder (char[] text)
```

Construct a builder. The MeasuredText returned by build method will hold a reference of the text. Developer is not supposed to modify the text.

<br />

| Parameters ||
|---|---|
| `text` | `char`: a text. This value cannot be `null`. <br /> |

## Public methods

### appendReplacementRun

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public MeasuredText.Builder appendReplacementRun (Paint paint, 
                int length, 
                float width)
```

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.

<br />

| Parameters ||
|---|---|
| `paint` | `Paint`: This value cannot be `null`. <br /> |
| `length` | `int`: a length to be replaced with the object, can not exceed the length of the text. Value is 0 or greater <br /> |
| `width` | `float`: a replacement width of the range. The units of this value are pixels. Value is 0.0f or greater <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/text/MeasuredText.Builder` | This value cannot be `null`. <br /> |

### appendStyleRun

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public MeasuredText.Builder appendStyleRun (Paint paint, 
                LineBreakConfig lineBreakConfig, 
                int length, 
                boolean isRtl)
```

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.

<br />

| Parameters ||
|---|---|
| `paint` | `Paint`: a paint. This value cannot be `null`. <br /> |
| `lineBreakConfig` | `LineBreakConfig`: a line break configuration. This value may be `null`. <br /> |
| `length` | `int`: a length to be applied with a given paint, can not exceed the length of the text. Value is 0 or greater <br /> |
| `isRtl` | `boolean`: true if the text is in RTL context, otherwise false. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/text/MeasuredText.Builder` | This value cannot be `null`. <br /> |

### appendStyleRun

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public MeasuredText.Builder appendStyleRun (Paint paint, 
                int length, 
                boolean isRtl)
```

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.

`https://developer.android.com/reference/android/graphics/Paint#TEXT_RUN_FLAG_RIGHT_EDGE` and `https://developer.android.com/reference/android/graphics/Paint#TEXT_RUN_FLAG_LEFT_EDGE` are ignored and treated as both of them are set.

<br />

| Parameters ||
|---|---|
| `paint` | `Paint`: a paint. This value cannot be `null`. <br /> |
| `length` | `int`: a length to be applied with a given paint, can not exceed the length of the text. Value is 0 or greater <br /> |
| `isRtl` | `boolean`: true if the text is in RTL context, otherwise false. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/text/MeasuredText.Builder` | This value cannot be `null`. <br /> |

### build

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public MeasuredText build ()
```

Creates a MeasuredText. Once you called build() method, you can't reuse the Builder class again.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/text/MeasuredText` | This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if this Builder is reused. |
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if the whole text is not covered by one or more runs (style or replacement) |

### setComputeHyphenation

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public MeasuredText.Builder setComputeHyphenation (boolean computeHyphenation)
```

<br />

**This method was deprecated in API level 33.**   

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.

<br />

| Parameters ||
|---|---|
| `computeHyphenation` | `boolean`: true if you want to use automatic hyphenations. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/text/MeasuredText.Builder` | This value cannot be `null`. <br /> |

### setComputeHyphenation

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public MeasuredText.Builder setComputeHyphenation (int mode)
```

By passing true to this method, the build method will calculate hyphenation break points faster with ignoring some typographic features, e.g. kerning. `https://developer.android.com/reference/android/graphics/text/MeasuredText.Builder#HYPHENATION_MODE_NONE` is by default.

<br />

| Parameters ||
|---|---|
| `mode` | `int`: a hyphenation mode. Value is one of the following: - `https://developer.android.com/reference/android/graphics/text/MeasuredText.Builder#HYPHENATION_MODE_NONE` - `https://developer.android.com/reference/android/graphics/text/MeasuredText.Builder#HYPHENATION_MODE_NORMAL` - `https://developer.android.com/reference/android/graphics/text/MeasuredText.Builder#HYPHENATION_MODE_FAST` |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/text/MeasuredText.Builder` | This value cannot be `null`. <br /> |

### setComputeLayout

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public MeasuredText.Builder setComputeLayout (boolean computeLayout)
```

By passing true to this method, the build method will compute all full layout information. If you don't use `https://developer.android.com/reference/android/graphics/text/MeasuredText#getBounds(int,%20int,%20android.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.

<br />

| Parameters ||
|---|---|
| `computeLayout` | `boolean`: true if you want to retrieve full layout info, e.g. bbox. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/text/MeasuredText.Builder` | This value cannot be `null`. <br /> |