TextBoundsInfo.Builder


public static final class TextBoundsInfo.Builder
extends Object

java.lang.Object
   ↳ android.view.inputmethod.TextBoundsInfo.Builder


The builder class to create a TextBoundsInfo object.

Summary

Public constructors

Builder(int start, int end)

Create a builder for TextBoundsInfo.

Public methods

TextBoundsInfo build()

Create the TextBoundsInfo using the parameters in this Builder.

TextBoundsInfo.Builder clear()

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

TextBoundsInfo.Builder setCharacterBidiLevel(int[] characterBidiLevels)

Set the BiDi levels for the character.

TextBoundsInfo.Builder setCharacterBounds(float[] characterBounds)

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

TextBoundsInfo.Builder setCharacterFlags(int[] characterFlags)

Set the flags of the characters.

TextBoundsInfo.Builder setGraphemeSegmentFinder(SegmentFinder graphemeSegmentFinder)

Set the SegmentFinder that locates the grapheme cluster boundaries.

TextBoundsInfo.Builder setLineSegmentFinder(SegmentFinder lineSegmentFinder)

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(int start, int end)

Set the start and end index of the TextBoundsInfo.

TextBoundsInfo.Builder setWordSegmentFinder(SegmentFinder wordSegmentFinder)

Set the SegmentFinder that locates the word boundaries.

Inherited methods

Public constructors

Builder

Added in API level 34
public Builder (int start, 
                int end)

Create a builder for TextBoundsInfo.

Parameters
start int: the start index of the TextBoundsInfo, inclusive.

end int: the end index of the TextBoundsInfo, exclusive.

Throws
IllegalArgumentException if the given start or end is negative, or end is smaller than the start.

Public methods

build

Added in API level 34
public TextBoundsInfo build ()

Create the TextBoundsInfo using the parameters in this Builder.

Returns
TextBoundsInfo This value cannot be null.

Throws
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 TextBoundsInfo.FLAG_LINE_IS_RTL flag.

clear

Added in API level 34
public TextBoundsInfo.Builder clear ()

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

Returns
TextBoundsInfo.Builder This value cannot be null.

setCharacterBidiLevel

Added in API level 34
public TextBoundsInfo.Builder setCharacterBidiLevel (int[] characterBidiLevels)

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 int: the array of the character's BiDi level. This value cannot be null.

Returns
TextBoundsInfo.Builder This value cannot be null.

Throws
NullPointerException if the given characterBidiLevels is null.
IllegalArgumentException if the given characterBidiLevels contains an element that's out of the range [0, 125].

setCharacterBounds

Added in API level 34
public TextBoundsInfo.Builder setCharacterBounds (float[] characterBounds)

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 float: the array of the flattened character bounds. This value cannot be null.

Returns
TextBoundsInfo.Builder This value cannot be null.

Throws
NullPointerException if the given characterBounds is null.

setCharacterFlags

Added in API level 34
public TextBoundsInfo.Builder setCharacterFlags (int[] characterFlags)

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 int: the array of the character's flags. This value cannot be null.

Returns
TextBoundsInfo.Builder This value cannot be null.

Throws
NullPointerException if the given characterFlags is null.
IllegalArgumentException if the given characterFlags contains invalid flags.

setGraphemeSegmentFinder

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

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.

Returns
TextBoundsInfo.Builder This value cannot be null.

Throws
NullPointerException if the given graphemeSegmentFinder is null.

setLineSegmentFinder

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

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.

Returns
TextBoundsInfo.Builder This value cannot be null.

Throws
NullPointerException if the given lineSegmentFinder is null.

setMatrix

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

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.

Returns
TextBoundsInfo.Builder This value cannot be null.

Throws
NullPointerException if the given matrix is null.

setStartAndEnd

Added in API level 34
public TextBoundsInfo.Builder setStartAndEnd (int start, 
                int end)

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

Returns
TextBoundsInfo.Builder This value cannot be null.

Throws
IllegalArgumentException if the given start or end is negative, or end is smaller than the start.

setWordSegmentFinder

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

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.

Returns
TextBoundsInfo.Builder This value cannot be null.

Throws
NullPointerException if the given wordSegmentFinder is null.