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 |
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 |
void
|
getCharacterBounds(int index, RectF bounds)
Set the bounds of the character at the given |
int
|
getCharacterFlags(int index)
Return the flags associated with the character at the given |
int
|
getEndIndex()
Returns the index of the last character whose bounds information is available in this
|
SegmentFinder
|
getGraphemeSegmentFinder()
Returns the |
SegmentFinder
|
getLineSegmentFinder()
Returns the |
void
|
getMatrix(Matrix matrix)
Set the given |
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
|
SegmentFinder
|
getWordSegmentFinder()
Returns the |
void
|
writeToParcel(Parcel dest, int flags)
Flatten this object in to a Parcel. |
Inherited methods | |
---|---|
Constants
FLAG_CHARACTER_LINEFEED
public static final int FLAG_CHARACTER_LINEFEED
The flag indicating that the character is a linefeed character.
Constant Value: 2 (0x00000002)
FLAG_CHARACTER_PUNCTUATION
public static final int FLAG_CHARACTER_PUNCTUATION
The flag indicating that the character is a punctuation.
Constant Value: 4 (0x00000004)
FLAG_CHARACTER_WHITESPACE
public static final int FLAG_CHARACTER_WHITESPACE
The flag indicating that the character is a whitespace.
Constant Value: 1 (0x00000001)
FLAG_LINE_IS_RTL
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
public static final Creator<TextBoundsInfo> CREATOR
The CREATOR to make this class Parcelable.
Public methods
describeContents
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
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
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
public int getCharacterFlags (int index)
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. |
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
public int getEndIndex ()
Returns the index of the last character whose bounds information is available in this
TextBoundsInfo
, exclusive.
Returns | |
---|---|
int |
getGraphemeSegmentFinder
public SegmentFinder getGraphemeSegmentFinder ()
Returns the SegmentFinder
that locates the grapheme boundaries.
Returns | |
---|---|
SegmentFinder |
This value cannot be null . |
getLineSegmentFinder
public SegmentFinder getLineSegmentFinder ()
Returns the SegmentFinder
that locates the line boundaries.
Returns | |
---|---|
SegmentFinder |
This value cannot be null . |
getMatrix
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
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:
- 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. |
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
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
public int getStartIndex ()
Returns the index of the first character whose bounds information is available in this
TextBoundsInfo
, inclusive.
Returns | |
---|---|
int |
getWordSegmentFinder
public SegmentFinder getWordSegmentFinder ()
Returns the SegmentFinder
that locates the word boundaries.
Returns | |
---|---|
SegmentFinder |
This value cannot be null . |
writeToParcel
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 . |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2024-04-04 UTC.