TextBoundsInfo
class TextBoundsInfo : Parcelable
kotlin.Any | |
↳ | 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 | |
---|---|
The builder class to create a |
Constants | |
---|---|
static Int |
The flag indicating that the character is a linefeed character. |
static Int |
The flag indicating that the character is a punctuation. |
static Int |
The flag indicating that the character is a whitespace. |
static Int |
The flag indicating that the line this character belongs to has RTL line direction. |
Inherited constants | |
---|---|
Public methods | |
---|---|
Int |
Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. |
Int |
getCharacterBidiLevel(index: Int) The BiDi level of the character at the given |
Unit |
getCharacterBounds(index: Int, bounds: RectF) Set the bounds of the character at the given |
Int |
getCharacterFlags(index: Int) Return the flags associated with the character at the given |
Int |
Returns the index of the last character whose bounds information is available in this |
SegmentFinder |
Returns the |
SegmentFinder |
Returns the |
Unit |
Set the given |
Int |
getOffsetForPosition(x: Float, y: Float) Return the index of the closest character to the given position. |
IntArray? |
getRangeForRect(area: RectF, segmentFinder: SegmentFinder, inclusionStrategy: Layout.TextInclusionStrategy) Finds the range of text which is inside the specified rectangle area. |
Int |
Returns the index of the first character whose bounds information is available in this |
SegmentFinder |
Returns the |
Unit |
writeToParcel(dest: Parcel, flags: Int) Flatten this object in to a Parcel. |
Properties | |
---|---|
static Parcelable.Creator<TextBoundsInfo!> |
The CREATOR to make this class Parcelable. |
Constants
FLAG_CHARACTER_LINEFEED
static val FLAG_CHARACTER_LINEFEED: Int
The flag indicating that the character is a linefeed character.
Value: 2
FLAG_CHARACTER_PUNCTUATION
static val FLAG_CHARACTER_PUNCTUATION: Int
The flag indicating that the character is a punctuation.
Value: 4
FLAG_CHARACTER_WHITESPACE
static val FLAG_CHARACTER_WHITESPACE: Int
The flag indicating that the character is a whitespace.
Value: 1
FLAG_LINE_IS_RTL
static val FLAG_LINE_IS_RTL: Int
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.
Value: 8
Public methods
describeContents
fun describeContents(): Int
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 CONTENTS_FILE_DESCRIPTOR
bit.
Return | |
---|---|
Int |
a bitmask indicating the set of special object types marshaled by this Parcelable object instance. |
getCharacterBidiLevel
fun getCharacterBidiLevel(index: Int): Int
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. |
Return | |
---|---|
Int |
the BiDi level of the character, which is an integer in the range of [0, 125]. Value is between 0 and 125 inclusive |
Exceptions | |
---|---|
java.lang.IndexOutOfBoundsException |
if the given index is out of the range from the start to the end . |
getCharacterBounds
fun getCharacterBounds(
index: Int,
bounds: RectF
): Unit
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 . |
Return | |
---|---|
Unit |
This value cannot be null . |
Exceptions | |
---|---|
java.lang.IndexOutOfBoundsException |
if the given index is out of the range from the start to the end . |
getCharacterFlags
fun getCharacterFlags(index: Int): Int
Return the flags associated with the character at the given index
. The flags contain the following information:
- The
FLAG_CHARACTER_WHITESPACE
flag, indicating the character is a whitespace. - The
FLAG_CHARACTER_LINEFEED
flag, indicating the character is a linefeed. - The
FLAG_CHARACTER_PUNCTUATION
flag, indicating the character is a punctuation. - The
FLAG_LINE_IS_RTL
flag, indicating the line this character belongs to has RTL line direction. All characters in the same line must have the same line direction. CheckgetLineSegmentFinder()
for more information of line boundaries.
Parameters | |
---|---|
index |
Int: the index of the queried character. |
Return | |
---|---|
Int |
the flags associated with the queried character. Value is either 0 or a combination of android.view.inputmethod.TextBoundsInfo#FLAG_CHARACTER_WHITESPACE , android.view.inputmethod.TextBoundsInfo#FLAG_CHARACTER_LINEFEED , android.view.inputmethod.TextBoundsInfo#FLAG_CHARACTER_PUNCTUATION , and android.view.inputmethod.TextBoundsInfo#FLAG_LINE_IS_RTL |
Exceptions | |
---|---|
java.lang.IndexOutOfBoundsException |
if the given index is out of the range from the start to the end . |
getEndIndex
fun getEndIndex(): Int
Returns the index of the last character whose bounds information is available in this TextBoundsInfo
, exclusive.
getGraphemeSegmentFinder
fun getGraphemeSegmentFinder(): SegmentFinder
Returns the SegmentFinder
that locates the grapheme boundaries.
Return | |
---|---|
SegmentFinder |
This value cannot be null . |
getLineSegmentFinder
fun getLineSegmentFinder(): SegmentFinder
Returns the SegmentFinder
that locates the line boundaries.
Return | |
---|---|
SegmentFinder |
This value cannot be null . |
getMatrix
fun getMatrix(matrix: Matrix): Unit
Set the given android.graphics.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 . |
Return | |
---|---|
Unit |
This value cannot be null . |
getOffsetForPosition
fun getOffsetForPosition(
x: Float,
y: Float
): Int
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:
- The given
y
coordinate is above the first line or below the last line (the first line or the last line is identified by theSegmentFinder
returned fromgetLineSegmentFinder()
). - There is no character in this
TextBoundsInfo
.
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. |
Return | |
---|---|
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
fun getRangeForRect(
area: RectF,
segmentFinder: SegmentFinder,
inclusionStrategy: Layout.TextInclusionStrategy
): IntArray?
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 . |
Return | |
---|---|
IntArray? |
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
fun getStartIndex(): Int
Returns the index of the first character whose bounds information is available in this TextBoundsInfo
, inclusive.
getWordSegmentFinder
fun getWordSegmentFinder(): SegmentFinder
Returns the SegmentFinder
that locates the word boundaries.
Return | |
---|---|
SegmentFinder |
This value cannot be null . |
writeToParcel
fun writeToParcel(
dest: Parcel,
flags: Int
): Unit
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_WRITE_RETURN_VALUE . |
Properties
CREATOR
static val CREATOR: Parcelable.Creator<TextBoundsInfo!>
The CREATOR to make this class Parcelable.