Added in API level 34

Builder


class Builder
kotlin.Any
   ↳ android.view.inputmethod.TextBoundsInfo.Builder

The builder class to create a TextBoundsInfo object.

Summary

Public constructors
Builder(start: Int, end: Int)

Create a builder for TextBoundsInfo.

Public methods
TextBoundsInfo

Create the TextBoundsInfo using the parameters in this Builder.

TextBoundsInfo.Builder

Clear all the parameters set on this Builder to reuse it.

TextBoundsInfo.Builder
setCharacterBidiLevel(characterBidiLevels: IntArray)

Set the BiDi levels for the character.

TextBoundsInfo.Builder
setCharacterBounds(characterBounds: FloatArray)

Set the characters bounds, in the coordinates of the editor.

TextBoundsInfo.Builder
setCharacterFlags(characterFlags: IntArray)

Set the flags of the characters.

TextBoundsInfo.Builder
setGraphemeSegmentFinder(graphemeSegmentFinder: SegmentFinder)

Set the SegmentFinder that locates the grapheme cluster boundaries.

TextBoundsInfo.Builder
setLineSegmentFinder(lineSegmentFinder: SegmentFinder)

Set the SegmentFinder that locates the line boundaries.

TextBoundsInfo.Builder
setMatrix(matrix: Matrix)

Sets the matrix that transforms local coordinates into screen coordinates.

TextBoundsInfo.Builder
setStartAndEnd(start: Int, end: Int)

Set the start and end index of the TextBoundsInfo.

TextBoundsInfo.Builder
setWordSegmentFinder(wordSegmentFinder: SegmentFinder)

Set the SegmentFinder that locates the word boundaries.

Public constructors

Builder

Added in API level 34
Builder(
    start: Int,
    end: Int)

Create a builder for TextBoundsInfo.

Parameters
start Int: the start index of the TextBoundsInfo, inclusive.
end Int: the end index of the TextBoundsInfo, exclusive.
Exceptions
java.lang.IllegalArgumentException if the given start or end is negative, or end is smaller than the start.

Public methods

build

Added in API level 34
fun build(): TextBoundsInfo

Create the TextBoundsInfo using the parameters in this Builder.

Return
TextBoundsInfo This value cannot be null.
Exceptions
java.lang.IllegalStateException in the following conditions:
  • if the start or end is not set.
  • if the matrix is not set.
  • if characterBounds is not set or its length doesn't equal to 4 * (end - start).
  • if the characterFlags is not set or its length doesn't equal to (end - start).
  • if graphemeSegmentFinder, wordSegmentFinder or lineSegmentFinder is not set.
  • if characters in the same line has inconsistent FLAG_LINE_IS_RTL flag.

clear

Added in API level 34
fun clear(): TextBoundsInfo.Builder

Clear all the parameters set on this Builder to reuse it.

Return
TextBoundsInfo.Builder This value cannot be null.

setCharacterBidiLevel

Added in API level 34
fun setCharacterBidiLevel(characterBidiLevels: IntArray): TextBoundsInfo.Builder

Set the BiDi levels for the character. The bidiLevel of the i-th character in the editor is stored at index (i - start). The length of the given array must equal to (end - start).
BiDi level is defined by the unicode bidirectional algorithm . One can determine whether a character's direction is right-to-left (RTL) or left-to-right (LTR) by checking the last bit of the BiDi level. If it's 1, the character is RTL, otherwise the character is LTR. The BiDi level of a character must be in the range of [0, 125].

Parameters
characterBidiLevels IntArray: the array of the character's BiDi level. This value cannot be null.
Return
TextBoundsInfo.Builder This value cannot be null.
Exceptions
java.lang.NullPointerException if the given characterBidiLevels is null.
java.lang.IllegalArgumentException if the given characterBidiLevels contains an element that's out of the range [0, 125].

setCharacterBounds

Added in API level 34
fun setCharacterBounds(characterBounds: FloatArray): TextBoundsInfo.Builder

Set the characters bounds, in the coordinates of the editor.
The given array should be divided into groups of four where each element represents left, top, right and bottom of the character bounds respectively. The bounds of the i-th character in the editor should be stored at index 4 * (i - start). The length of the given array must equal to 4 * (end - start).
Sometimes multiple characters in a single grapheme are rendered as one symbol on the screen. So those characters only have one shared bounds. In this case, we recommend the editor to assign all the width to the bounds of the first character in the grapheme, and make the rest characters' bounds zero-width.
For example, the string "'0xD83D' '0xDE00'" is rendered as one grapheme - a grinning face emoji. If the bounds of the grapheme is: Rect(5, 10, 15, 20), the character bounds of the string should be: [ Rect(5, 10, 15, 20), Rect(15, 10, 15, 20) ].

Parameters
characterBounds FloatArray: the array of the flattened character bounds. This value cannot be null.
Return
TextBoundsInfo.Builder This value cannot be null.
Exceptions
java.lang.NullPointerException if the given characterBounds is null.

setCharacterFlags

Added in API level 34
fun setCharacterFlags(characterFlags: IntArray): TextBoundsInfo.Builder

Set the flags of the characters. The flags of the i-th character in the editor is stored at index (i - start). The length of the given array must equal to (end - start). The flags contain the following information:

Parameters
characterFlags IntArray: the array of the character's flags. This value cannot be null.
Return
TextBoundsInfo.Builder This value cannot be null.
Exceptions
java.lang.NullPointerException if the given characterFlags is null.
java.lang.IllegalArgumentException if the given characterFlags contains invalid flags.

setGraphemeSegmentFinder

Added in API level 34
fun setGraphemeSegmentFinder(graphemeSegmentFinder: SegmentFinder): TextBoundsInfo.Builder

Set the SegmentFinder that locates the grapheme cluster boundaries. Grapheme is defined in the unicode annex #29: unicode text segmentation. It's a user-perspective character. And it's usually the minimal unit for selection, backspace, deletion etc.
Please note that only the grapheme segments within the range from start to end will be available to the IME. The remaining information will be discarded during serialization for better performance.

Parameters
graphemeSegmentFinder SegmentFinder: the SegmentFinder that locates the grapheme cluster boundaries. This value cannot be null.
Return
TextBoundsInfo.Builder This value cannot be null.
Exceptions
java.lang.NullPointerException if the given graphemeSegmentFinder is null.

setLineSegmentFinder

Added in API level 34
fun setLineSegmentFinder(lineSegmentFinder: SegmentFinder): TextBoundsInfo.Builder

Set the SegmentFinder that locates the line boundaries. Aside from the hard breaks in the text, it should also locate the soft line breaks added by the editor. It is expected that the characters within the same line is rendered on the same baseline. (Except for some text formatted as subscript and superscript.)
Please note that only the line segments within the range from start to end will be available to the IME. The remaining information will be discarded during serialization for better performance.

Parameters
lineSegmentFinder SegmentFinder: set the SegmentFinder that locates the line boundaries. This value cannot be null.
Return
TextBoundsInfo.Builder This value cannot be null.
Exceptions
java.lang.NullPointerException if the given lineSegmentFinder is null.

setMatrix

Added in API level 34
fun setMatrix(matrix: Matrix): TextBoundsInfo.Builder

Sets the matrix that transforms local coordinates into screen coordinates.

Parameters
matrix Matrix: transformation matrix from local coordinates into screen coordinates. This value cannot be null.
Return
TextBoundsInfo.Builder This value cannot be null.
Exceptions
java.lang.NullPointerException if the given matrix is null.

setStartAndEnd

Added in API level 34
fun setStartAndEnd(
    start: Int,
    end: Int
): TextBoundsInfo.Builder

Set the start and end index of the TextBoundsInfo. It's the range of the characters whose information is available in the TextBoundsInfo.

Parameters
start Int: the start index of the TextBoundsInfo, inclusive. Value is 0 or greater
end Int: the end index of the TextBoundsInfo, exclusive. Value is 0 or greater
Return
TextBoundsInfo.Builder This value cannot be null.
Exceptions
java.lang.IllegalArgumentException if the given start or end is negative, or end is smaller than the start.

setWordSegmentFinder

Added in API level 34
fun setWordSegmentFinder(wordSegmentFinder: SegmentFinder): TextBoundsInfo.Builder

Set the SegmentFinder that locates the word boundaries.
Please note that only the word segments within the range from start to end will be available to the IME. The remaining information will be discarded during serialization for better performance.

Parameters
wordSegmentFinder SegmentFinder: set the SegmentFinder that locates the word boundaries. This value cannot be null.
Return
TextBoundsInfo.Builder This value cannot be null.
Exceptions
java.lang.NullPointerException if the given wordSegmentFinder is null.