public final class TextInputClient extends Object
SystemCapability.Miscservices#INPUTMETHOD| 限定符和类型 | 方法 | 说明 |
|---|---|---|
boolean |
deleteBackward(int length) |
Deletes characters of a specified length behind the cursor in the edit box.
|
boolean |
deleteForward(int length) |
Deletes characters of a specified length in front of the cursor in the edit box.
|
int |
getAutoCapitalizeMode(int reqModes) |
Obtains the letter case of the text at the cursor position in the edit box.
|
String |
getBackward(int length) |
Obtains a specified length of characters behind the cursor.
|
EditingText |
getEditingText(int token,
EditingCapability capability) |
Obtains the text being edited in the edit box.
|
EditorAttribute |
getEditorAttribute() |
Obtains the input content attributes, such as numbers, email addresses, and passwords.
|
String |
getForward(int length) |
Obtains a specified length of characters in front of the cursor.
|
boolean |
insertRichContent(RichContent richContent) |
Submits rich content to an application through the input method.
|
boolean |
insertText(String text) |
Submits the text entered by a user to an application's edit box through the input method.
|
boolean |
markText(int start,
int end) |
Marks the texts between the specified start and end positions in the edit box in English input mode.
|
boolean |
replaceMarkedText(String text) |
Replaces the marked text with a string of English characters.
|
boolean |
requestCurrentCursorContext() |
Allows the input method to obtain the cursor context from the control.
|
boolean |
reviseText(int startOffset,
String originalText,
String correctedText) |
Submits the revised text to the edit box.
|
boolean |
selectText(int startPos,
int endPos) |
Moves the cursor to a specified position, or selects a section of text between the specified start and
end positions.
|
boolean |
sendKeyEvent(KeyEvent keyEvent) |
Sends a key press event to an application.
|
boolean |
sendKeyFunction(int action) |
Allows an input method to instruct the edit box to perform an action based on its available attribute.
|
boolean |
subscribeCursorContext() |
Enables the control to update the real-time cursor context to the input method.
|
boolean |
subscribeEditingText(int token,
EditingCapability capability) |
Subscribes to the text in the current edit box and notifies the input method of text changes.
|
boolean |
unmarkText() |
Cancels the mark state of the text in the edit box in English input mode.
|
boolean |
unsubscribeCursorContext() |
Disables real-time updates of the cursor context from the control to the input method.
|
boolean |
unsubscribeEditingText(int token) |
Unsubscribes from the text in the current edit box.
|
public EditorAttribute getEditorAttribute()
EditorAttribute.public boolean insertText(String text)
The text is added behind the cursor in the current edit box.
text - Indicates the texts entered behind the cursor.true if the operation is successful; returns false otherwise.public boolean insertRichContent(RichContent richContent)
Rich content includes emoticons and images, which are usually provided by the input method to the edit box based on the content entered by the user. After obtaining the rich content, the edit box accesses it and displays it on the screen.
richContent - Indicates the rich content sent by the input method to the target application.true if the operation is successful; returns false otherwise.RichContentpublic boolean deleteBackward(int length)
After characters behind the cursor are deleted, the content in the edit box is updated in real time.
length - Indicates a length of characters to delete. If the length is greater than that of all
characters behind the cursor, all characters behind are deleted. If the length is smaller than or equal
to 0, no character is deleted and true is returned.true if the operation is successful; returns false otherwise.public boolean deleteForward(int length)
After characters in front of the cursor are deleted, the content in the edit box is updated in real time.
length - Indicates the length of the characters to delete. If the length is greater than that of all
characters in front of the cursor, all characters in front are deleted. If the length is smaller than or
equal to 0, no character is deleted and true is returned.true if the operation is successful; returns false otherwise.public String getForward(int length)
The input method can implement extended functions based on the context in front of and behind the cursor, for example, autocomplete and intelligent analysis.
length - Indicates the length of the characters to obtain.public String getBackward(int length)
The input method can implement extended functions based on the context in front of and behind the cursor, for example, autocomplete and intelligent analysis.
length - Indicates the length of the characters to obtain.public boolean subscribeEditingText(int token,
EditingCapability capability)
token - Indicates the ID of the current input session.capability - Indicates the control capability of the input method, including the maximum number of lines
and characters.true if the operation is successful; returns false otherwise.public EditingText getEditingText(int token, EditingCapability capability)
token - Indicates the ID of the current input session.capability - Indicates the control capability of the input method, including the maximum number of lines
and characters.public boolean unsubscribeEditingText(int token)
token - Indicates the ID of the current input session.true if the operation is successful; returns false otherwise.public boolean sendKeyEvent(KeyEvent keyEvent)
This method simulates a key press event from a physical keyboard to the focused edit box. Note that the focus may change when the event is received due to asynchronous protocols. This method applies only to the scenario where special keys are pressed, such as the Enter key.
keyEvent - Indicates the key event to send.true if the operation is successful; returns false otherwise.public boolean sendKeyFunction(int action)
The input method has a key whose function varies depending on the edit box attribute. It can function as
the Send, Search, or Enter key.
action - Indicates one of the edit box attributes, for example, Send, Search, or
Enter, as specified in ohos.miscservices.inputmethod.EditorAttribute#enterKeyType.true if the operation is successful; returns false otherwise.public boolean selectText(int startPos,
int endPos)
Generally, the start and end positions overlap. In this case, the editor moves the cursor to the position specified by the input parameters. To select a section of text in the text box, set the start position to a value smaller than the end position.
startPos - Indicates the start position of the cursor.endPos - Indicates the end position of the cursor.true if the operation is successful; returns false otherwise.public boolean requestCurrentCursorContext()
For physical keyboards, you can use this method to obtain the current cursor position immediately.
true if the operation is successful; returns false otherwise.public boolean subscribeCursorContext()
For physical keyboards, you can use this method to inform the input method of cursor position changes.
true if the operation is successful; returns false otherwise.public boolean unsubscribeCursorContext()
For physical keyboards, you can use this method to unsubscribe from the cursor position changes.
true if the operation is successful; returns false otherwise.public int getAutoCapitalizeMode(int reqModes)
reqModes - Indicates the automatic letter case specified by the input method. For example, the sentence
case, title case, and all caps.0 if the case of the text at the cursor position is in lowercase; returns
the value of the input parameter if the text is in uppercase.public boolean reviseText(int startOffset,
String originalText,
String correctedText)
startOffset - Indicates the start cursor position of the text to revise.originalText - Indicates the text to revise.correctedText - Indicates the revised text to submit.true if the operation is successful; returns false otherwise.public boolean markText(int start,
int end)
The previous mark state is automatically removed.
start - Indicates the start position.end - Indicates the end position.true if the operation is successful; returns false otherwise.public boolean unmarkText()
This method is called when the UI is switched, the edit box loses focus, or a space is entered behind the text to be confirmed.
true if the operation is successful; returns false otherwise.public boolean replaceMarkedText(String text)
text - Indicates the characters used to replace the marked text.true if the operation is successful; returns false otherwise.