TextBoundsInfo


public final class TextBoundsInfo
extends Object implements Parcelable

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


The text bounds information of a slice of text in the editor.

This class provides IME the layout information of the text within the range from getStartIndex() to getEndIndex(). It's intended to be used by IME as a supplementary API to support handwriting gestures.

Summary

Nested classes

class TextBoundsInfo.Builder

The builder class to create a TextBoundsInfo object. 

Constants

int FLAG_CHARACTER_LINEFEED

The flag indicating that the character is a linefeed character.

int FLAG_CHARACTER_PUNCTUATION

The flag indicating that the character is a punctuation.

int FLAG_CHARACTER_WHITESPACE

The flag indicating that the character is a whitespace.

int FLAG_LINE_IS_RTL

The flag indicating that the line this character belongs to has RTL line direction.

Inherited constants

Fields

public static final Creator<TextBoundsInfo> CREATOR

The CREATOR to make this class Parcelable.

Public methods

int describeContents()

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.

int getCharacterBidiLevel(int index)

The BiDi level of the character at the given index.

void getCharacterBounds(int index, RectF bounds)

Set the bounds of the character at the given index to the given RectF, in the coordinates of the editor.

int getCharacterFlags(int index)

Return the flags associated with the character at the given index.

int getEndIndex()

Returns the index of the last character whose bounds information is available in this TextBoundsInfo, exclusive.

SegmentFinder getGraphemeSegmentFinder()

Returns the SegmentFinder that locates the grapheme boundaries.

SegmentFinder getLineSegmentFinder()

Returns the SegmentFinder that locates the line boundaries.

void getMatrix(Matrix matrix)

Set the given Matrix to be the transformation matrix that is to be applied other positional data in this class.

int getOffsetForPosition(float x, float y)

Return the index of the closest character to the given position.

int[] getRangeForRect(RectF area, SegmentFinder segmentFinder, Layout.TextInclusionStrategy inclusionStrategy)

Finds the range of text which is inside the specified rectangle area.

int getStartIndex()

Returns the index of the first character whose bounds information is available in this TextBoundsInfo, inclusive.

SegmentFinder getWordSegmentFinder()

Returns the SegmentFinder that locates the word boundaries.

void writeToParcel(Parcel dest, int flags)

Flatten this object in to a Parcel.

Inherited methods

Constants

FLAG_CHARACTER_LINEFEED

Added in API level 34
public static final int FLAG_CHARACTER_LINEFEED

The flag indicating that the character is a linefeed character.

Constant Value: 2 (0x00000002)

FLAG_CHARACTER_PUNCTUATION

Added in API level 34
public static final int FLAG_CHARACTER_PUNCTUATION

The flag indicating that the character is a punctuation.

Constant Value: 4 (0x00000004)

FLAG_CHARACTER_WHITESPACE

Added in API level 34
public static final int FLAG_CHARACTER_WHITESPACE

The flag indicating that the character is a whitespace.

Constant Value: 1 (0x00000001)

FLAG_LINE_IS_RTL

Added in API level 34
public static final int FLAG_LINE_IS_RTL

The flag indicating that the line this character belongs to has RTL line direction. It's required that all characters in the same line must have the same direction.

Constant Value: 8 (0x00000008)

Fields

CREATOR

Added in API level 34
public static final Creator<TextBoundsInfo> CREATOR

The CREATOR to make this class Parcelable.

Public methods

describeContents

Added in API level 34
public int describeContents ()

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. For example, if the object will include a file descriptor in the output of writeToParcel(android.os.Parcel, int), the return value of this method must include the Parcelable.CONTENTS_FILE_DESCRIPTOR bit.

Returns
int a bitmask indicating the set of special object types marshaled by this Parcelable object instance.

getCharacterBidiLevel

Added in API level 34
public int getCharacterBidiLevel (int index)

The BiDi level of the character at the given index.
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
index int: the index of the queried character.

Returns
int the BiDi level of the character, which is an integer in the range of [0, 125]. Value is between 0 and 125 inclusive

Throws
IndexOutOfBoundsException if the given index is out of the range from the start to the end.

getCharacterBounds

Added in API level 34
public void getCharacterBounds (int index, 
                RectF bounds)

Set the bounds of the character at the given index to the given RectF, in the coordinates of the editor.

Parameters
index int: the index of the queried character.

bounds RectF: the RectF used to receive the result. This value cannot be null.

Returns
void This value cannot be null.

Throws
IndexOutOfBoundsException if the given index is out of the range from the start to the end.

getCharacterFlags

Added in API level 34
public int getCharacterFlags (int index)

Return the flags associated with the character at the given index. The flags contain the following information:

Parameters
index int: the index of the queried character.

Returns
int the flags associated with the queried character. Value is either 0 or a combination of FLAG_CHARACTER_WHITESPACE, FLAG_CHARACTER_LINEFEED, FLAG_CHARACTER_PUNCTUATION, and FLAG_LINE_IS_RTL

Throws
IndexOutOfBoundsException if the given index is out of the range from the start to the end.

getEndIndex

Added in API level 34
public int getEndIndex ()

Returns the index of the last character whose bounds information is available in this TextBoundsInfo, exclusive.

Returns
int

getGraphemeSegmentFinder

Added in API level 34
public SegmentFinder getGraphemeSegmentFinder ()

Returns the SegmentFinder that locates the grapheme boundaries.

Returns
SegmentFinder This value cannot be null.

getLineSegmentFinder

Added in API level 34
public SegmentFinder getLineSegmentFinder ()

Returns the SegmentFinder that locates the line boundaries.

Returns
SegmentFinder This value cannot be null.

getMatrix

Added in API level 34
public void getMatrix (Matrix matrix)

Set the given Matrix to be the transformation matrix that is to be applied other positional data in this class.

Parameters
matrix Matrix: This value cannot be null.

Returns
void This value cannot be null.

getOffsetForPosition

Added in API level 34
public int getOffsetForPosition (float x, 
                float y)

Return the index of the closest character to the given position. It's similar to the text layout API Layout#getOffsetForHorizontal(int, float). And it's mainly used to find the cursor index (the index of the character before which the cursor should be placed) for the given position. It's guaranteed that the returned index is a grapheme break. Check getGraphemeSegmentFinder() for more information.

It's assumed that the editor lays out text in horizontal lines from top to bottom and each line is laid out according to the display algorithm specified in unicode bidirectional algorithm.

This method won't check the text ranges whose line information is missing. For example, the TextBoundsInfo's range is from index 5 to 15. If the associated SegmentFinder only identifies one line range from 7 to 12. Then this method won't check the text in the ranges of [5, 7) and [12, 15).

Under the following conditions, this method will return -1 indicating that no valid character is found:

Parameters
x float: the x coordinates of the interested location, in the editor's coordinates.

y float: the y coordinates of the interested location, in the editor's coordinates.

Returns
int the index of the character whose position is closest to the given location. It will return -1 if it can't find a character.

getRangeForRect

Added in API level 34
public int[] getRangeForRect (RectF area, 
                SegmentFinder segmentFinder, 
                Layout.TextInclusionStrategy inclusionStrategy)

Finds the range of text which is inside the specified rectangle area. This method is a counterpart of the Layout#getRangeForRect(RectF, SegmentFinder, Layout.TextInclusionStrategy).

It's assumed that the editor lays out text in horizontal lines from top to bottom and each line is laid out according to the display algorithm specified in unicode bidirectional algorithm.

This method won't check the text ranges whose line information is missing. For example, the TextBoundsInfo's range is from index 5 to 15. If the associated line SegmentFinder only identifies one line range from 7 to 12. Then this method won't check the text in the ranges of [5, 7) and [12, 15).

Parameters
area RectF: area for which the text range will be found This value cannot be null.

segmentFinder SegmentFinder: SegmentFinder for determining the ranges of text to be considered as a text segment This value cannot be null.

inclusionStrategy Layout.TextInclusionStrategy: strategy for determining whether a text segment is inside the specified area This value cannot be null.

Returns
int[] the text range stored in a two element int array. The first element is the start (inclusive) of the text range, and the second element is the end (exclusive) character offsets of the text range, or null if there are no text segments inside the area.

getStartIndex

Added in API level 34
public int getStartIndex ()

Returns the index of the first character whose bounds information is available in this TextBoundsInfo, inclusive.

Returns
int

getWordSegmentFinder

Added in API level 34
public SegmentFinder getWordSegmentFinder ()

Returns the SegmentFinder that locates the word boundaries.

Returns
SegmentFinder This value cannot be null.

writeToParcel

Added in API level 34
public void writeToParcel (Parcel dest, 
                int flags)

Flatten this object in to a Parcel.

Parameters
dest Parcel: The Parcel in which the object should be written. This value cannot be null.

flags int: Additional flags about how the object should be written. May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE.