BaseInputConnection
open class BaseInputConnection : InputConnection
kotlin.Any | |
↳ | android.view.inputmethod.BaseInputConnection |
Base class for implementors of the InputConnection interface, taking care of most of the common behavior for providing a connection to an Editable. Implementors of this class will want to be sure to implement getEditable
to provide access to their own editable object, and to refer to the documentation in InputConnection
.
Summary
Inherited constants | |
---|---|
Public constructors | |
---|---|
BaseInputConnection(targetView: View, fullEditor: Boolean) |
Public methods | |
---|---|
open Boolean |
Default implementation does nothing. |
open Boolean |
clearMetaKeyStates(states: Int) Default implementation uses |
open Unit |
Default implementation calls |
open Boolean |
commitCompletion(text: CompletionInfo!) Default implementation does nothing and returns false. |
open Boolean |
commitContent(inputContentInfo: InputContentInfo, flags: Int, opts: Bundle?) Default implementation which invokes |
open Boolean |
commitCorrection(correctionInfo: CorrectionInfo!) Default implementation does nothing and returns false. |
open Boolean |
commitText(text: CharSequence!, newCursorPosition: Int) Default implementation replaces any existing composing text with the given text. |
open Boolean |
deleteSurroundingText(beforeLength: Int, afterLength: Int) The default implementation performs the deletion around the current selection position of the editable text. |
open Boolean |
deleteSurroundingTextInCodePoints(beforeLength: Int, afterLength: Int) The default implementation performs the deletion around the current selection position of the editable text. |
open Boolean |
Default implementation does nothing. |
open Boolean |
The default implementation removes the composing state from the current editable text. |
open static Int |
getComposingSpanEnd(text: Spannable) Return the end of the range of composing text, or -1 if there's no composing text. |
open static Int |
getComposingSpanStart(text: Spannable) Return the beginning of the range of composing text, or -1 if there's no composing text. |
open Int |
getCursorCapsMode(reqModes: Int) The default implementation uses TextUtils. |
open Editable? |
Return the target of edit operations. |
open ExtractedText? |
getExtractedText(request: ExtractedTextRequest!, flags: Int) The default implementation always returns null. |
open Handler? |
Called by the system to enable application developers to specify a dedicated thread on which |
open CharSequence? |
getSelectedText(flags: Int) The default implementation returns the text currently selected, or null if none is selected. |
open SurroundingText? |
getSurroundingText(beforeLength: Int, afterLength: Int, flags: Int) The default implementation returns the given amount of text around the current cursor position in the buffer. |
open CharSequence? |
getTextAfterCursor(length: Int, flags: Int) The default implementation returns the given amount of text from the current cursor position in the buffer. |
open CharSequence? |
getTextBeforeCursor(length: Int, flags: Int) The default implementation returns the given amount of text from the current cursor position in the buffer. |
open Boolean |
The default implementation does nothing. |
open Boolean |
performEditorAction(actionCode: Int) The default implementation turns this into the enter key. |
open Boolean |
performPrivateCommand(action: String!, data: Bundle!) The default implementation does nothing. |
static Unit |
removeComposingSpans(text: Spannable) Removes the composing spans from the given text if any. |
open Boolean |
replaceText(start: Int, end: Int, text: CharSequence, newCursorPosition: Int, textAttribute: TextAttribute?) Replace the specific range in the editor with suggested text. |
open Boolean |
reportFullscreenMode(enabled: Boolean) Updates InputMethodManager with the current fullscreen mode. |
open Boolean |
requestCursorUpdates(cursorUpdateMode: Int) The default implementation does nothing. |
open Boolean |
sendKeyEvent(event: KeyEvent!) Provides standard implementation for sending a key event to the window attached to the input connection's view. |
open Boolean |
setComposingRegion(start: Int, end: Int) |
open static Unit |
setComposingSpans(text: Spannable) Removes the composing spans from the given text if any. |
open Boolean |
setComposingText(text: CharSequence!, newCursorPosition: Int) The default implementation places the given text into the editable, replacing any existing composing text. |
open Boolean |
setSelection(start: Int, end: Int) The default implementation changes the selection position in the current editable text. |
open TextSnapshot? |
Default implementation that constructs |
Inherited functions | |
---|---|
Public constructors
BaseInputConnection
BaseInputConnection(
targetView: View,
fullEditor: Boolean)
Parameters | |
---|---|
targetView |
View: This value cannot be null . |
Public methods
beginBatchEdit
open fun beginBatchEdit(): Boolean
Default implementation does nothing.
Return | |
---|---|
Boolean |
true if a batch edit is now in progress, false otherwise. Since this method starts a batch edit, that means it will always return true unless the input connection is no longer valid. |
clearMetaKeyStates
open fun clearMetaKeyStates(states: Int): Boolean
Default implementation uses MetaKeyKeyListener.clearMetaKeyState(long, int)
to clear the state.
Parameters | |
---|---|
states |
Int: The states to be cleared, may be one or more bits as per KeyEvent.getMetaState() . |
Return | |
---|---|
Boolean |
true on success, false if the input connection is no longer valid. |
closeConnection
open fun closeConnection(): Unit
Default implementation calls finishComposingText()
and setImeConsumesInput(false)
.
If you override this method you must call through to the superclass implementation.
commitCompletion
open fun commitCompletion(text: CompletionInfo!): Boolean
Default implementation does nothing and returns false.
Parameters | |
---|---|
text |
CompletionInfo!: The committed completion. |
Return | |
---|---|
Boolean |
true on success, false if the input connection is no longer valid. |
commitContent
open fun commitContent(
inputContentInfo: InputContentInfo,
flags: Int,
opts: Bundle?
): Boolean
Default implementation which invokes View#performReceiveContent
on the target view if the view allows
content insertion; otherwise returns false without any side effects.
Parameters | |
---|---|
inputContentInfo |
InputContentInfo: Content to be inserted. This value cannot be null . |
flags |
Int: INPUT_CONTENT_GRANT_READ_URI_PERMISSION if the content provider allows grantUriPermissions or 0 if the application does not need to call InputContentInfo#requestPermission() . |
opts |
Bundle?: optional bundle data. This can be null . |
Return | |
---|---|
Boolean |
true if this request is accepted by the application, whether the request is already handled or still being handled in background, false otherwise. |
commitCorrection
open fun commitCorrection(correctionInfo: CorrectionInfo!): Boolean
Default implementation does nothing and returns false.
Parameters | |
---|---|
correctionInfo |
CorrectionInfo!: Detailed information about the correction. |
Return | |
---|---|
Boolean |
true on success, false if the input connection is no longer valid. Since Android android.os.Build.VERSION_CODES#N until android.os.Build.VERSION_CODES#TIRAMISU , this API returned false when the target application does not implement this method. |
commitText
open fun commitText(
text: CharSequence!,
newCursorPosition: Int
): Boolean
Default implementation replaces any existing composing text with the given text. In addition, only if fallback mode, a key event is sent for the new text and the current editable buffer cleared.
Parameters | |
---|---|
text |
CharSequence!: The text to commit. This may include styles. |
newCursorPosition |
Int: The new cursor position around the text, in Java characters. If > 0, this is relative to the end of the text - 1; if <= 0, this is relative to the start of the text. So a value of 1 will always advance the cursor to the position after the full text being inserted. Note that this means you can't position the cursor within the text, because the editor can make modifications to the text you are providing so it is not possible to correctly specify locations there. |
Return | |
---|---|
Boolean |
true on success, false if the input connection is no longer valid. |
deleteSurroundingText
open fun deleteSurroundingText(
beforeLength: Int,
afterLength: Int
): Boolean
The default implementation performs the deletion around the current selection position of the editable text.
Parameters | |
---|---|
beforeLength |
Int: The number of characters before the cursor to be deleted, in code unit. If this is greater than the number of existing characters between the beginning of the text and the cursor, then this method does not fail but deletes all the characters in that range. |
afterLength |
Int: The number of characters after the cursor to be deleted, in code unit. If this is greater than the number of existing characters between the cursor and the end of the text, then this method does not fail but deletes all the characters in that range. |
Return | |
---|---|
Boolean |
true when selected text is deleted, false when either the selection is invalid or not yet attached (i.e. selection start or end is -1), or the editable text is null . |
deleteSurroundingTextInCodePoints
open fun deleteSurroundingTextInCodePoints(
beforeLength: Int,
afterLength: Int
): Boolean
The default implementation performs the deletion around the current selection position of the editable text.
Parameters | |
---|---|
beforeLength |
Int: The number of characters before the cursor to be deleted, in code points. If this is greater than the number of existing characters between the beginning of the text and the cursor, then this method does not fail but deletes all the characters in that range. |
afterLength |
Int: The number of characters after the cursor to be deleted, in code points. If this is greater than the number of existing characters between the cursor and the end of the text, then this method does not fail but deletes all the characters in that range. |
Return | |
---|---|
Boolean |
true on success, false if the input connection is no longer valid. Before Android android.os.Build.VERSION_CODES#TIRAMISU , this API returned false when the target application does not implement this method. |
endBatchEdit
open fun endBatchEdit(): Boolean
Default implementation does nothing.
Return | |
---|---|
Boolean |
For editor authors, you must return true if a batch edit is still in progress after closing the latest one (in other words, if the nesting count is still a positive number). Return false otherwise. For IME authors, you will always receive true as long as the request was sent to the editor, and receive false only if the input connection is no longer valid. |
finishComposingText
open fun finishComposingText(): Boolean
The default implementation removes the composing state from the current editable text. In addition, only if fallback mode, a key event is sent for the new text and the current editable buffer cleared.
Return | |
---|---|
Boolean |
true on success, false if the input connection is no longer valid. |
getComposingSpanEnd
open static fun getComposingSpanEnd(text: Spannable): Int
Return the end of the range of composing text, or -1 if there's no composing text.
Parameters | |
---|---|
text |
Spannable: This value cannot be null . |
getComposingSpanStart
open static fun getComposingSpanStart(text: Spannable): Int
Return the beginning of the range of composing text, or -1 if there's no composing text.
Parameters | |
---|---|
text |
Spannable: This value cannot be null . |
getCursorCapsMode
open fun getCursorCapsMode(reqModes: Int): Int
The default implementation uses TextUtils.getCapsMode to get the cursor caps mode for the current selection position in the editable text, unless in fallback mode in which case 0 is always returned.
Parameters | |
---|---|
reqModes |
Int: The desired modes to retrieve, as defined by TextUtils.getCapsMode . These constants are defined so that you can simply pass the current TextBoxAttribute.contentType value directly in to here. |
Return | |
---|---|
Int |
the caps mode flags that are in effect at the current cursor position. See TYPE_TEXT_FLAG_CAPS_* in android.text.InputType . |
getEditable
open fun getEditable(): Editable?
Return the target of edit operations. The default implementation returns its own fake editable that is just used for composing text; subclasses that are real text editors should override this and supply their own.
Subclasses could override this method to turn null.
getExtractedText
open fun getExtractedText(
request: ExtractedTextRequest!,
flags: Int
): ExtractedText?
The default implementation always returns null.
Parameters | |
---|---|
request |
ExtractedTextRequest!: Description of how the text should be returned. android.view.inputmethod.ExtractedTextRequest |
flags |
Int: Additional options to control the client, either 0 or GET_EXTRACTED_TEXT_MONITOR . |
Return | |
---|---|
ExtractedText? |
an android.view.inputmethod.ExtractedText object describing the state of the text view and containing the extracted text itself, or null if the input connection is no longer valid of the editor can't comply with the request for some reason. |
getHandler
open fun getHandler(): Handler?
Called by the system to enable application developers to specify a dedicated thread on which InputConnection
methods are called back.
Editor authors: although you can return your custom subclasses of Handler
, the system only uses android.os.Looper
returned from Handler#getLooper()
. You cannot intercept or cancel InputConnection
callbacks by implementing this method.
IME authors: This method is not intended to be called from the IME. You will always receive null
.
Return | |
---|---|
Handler? |
This value may be null . |
getSelectedText
open fun getSelectedText(flags: Int): CharSequence?
The default implementation returns the text currently selected, or null if none is selected.
Parameters | |
---|---|
flags |
Int: Supplies additional options controlling how the text is returned. May be either 0 or GET_TEXT_WITH_STYLES . |
Return | |
---|---|
CharSequence? |
the text that is currently selected, if any, or null if no text is selected. |
getSurroundingText
open fun getSurroundingText(
beforeLength: Int,
afterLength: Int,
flags: Int
): SurroundingText?
The default implementation returns the given amount of text around the current cursor position in the buffer.
Parameters | |
---|---|
beforeLength |
Int: Value is 0 or greater |
afterLength |
Int: Value is 0 or greater |
flags |
Int: Supplies additional options controlling how the text is returned. May be either 0 or GET_TEXT_WITH_STYLES . Value is either 0 or android.view.inputmethod.InputConnection#GET_TEXT_WITH_STYLES |
Return | |
---|---|
SurroundingText? |
This value may be null . |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if beforeLength or afterLength is negative. |
getTextAfterCursor
open fun getTextAfterCursor(
length: Int,
flags: Int
): CharSequence?
The default implementation returns the given amount of text from the current cursor position in the buffer.
Parameters | |
---|---|
n |
The expected length of the text. This must be non-negative. Value is 0 or greater |
flags |
Int: Supplies additional options controlling how the text is returned. May be either 0 or GET_TEXT_WITH_STYLES . |
length |
Int: Value is 0 or greater |
Return | |
---|---|
CharSequence? |
This value may be null . |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if n is negative. |
getTextBeforeCursor
open fun getTextBeforeCursor(
length: Int,
flags: Int
): CharSequence?
The default implementation returns the given amount of text from the current cursor position in the buffer.
Parameters | |
---|---|
n |
The expected length of the text. This must be non-negative. Value is 0 or greater |
flags |
Int: Supplies additional options controlling how the text is returned. May be either 0 or GET_TEXT_WITH_STYLES . |
length |
Int: Value is 0 or greater |
Return | |
---|---|
CharSequence? |
This value may be null . |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if n is negative. |
performContextMenuAction
open fun performContextMenuAction(id: Int): Boolean
The default implementation does nothing.
performEditorAction
open fun performEditorAction(actionCode: Int): Boolean
The default implementation turns this into the enter key.
Parameters | |
---|---|
editorAction |
This must be one of the action constants for EditorInfo.imeOptions , such as EditorInfo.EDITOR_ACTION_GO , or the value of EditorInfo.actionId if a custom action is available. |
Return | |
---|---|
Boolean |
true on success, false if the input connection is no longer valid. |
performPrivateCommand
open fun performPrivateCommand(
action: String!,
data: Bundle!
): Boolean
The default implementation does nothing.
Parameters | |
---|---|
action |
String!: Name of the command to be performed. This must be a scoped name, i.e. prefixed with a package name you own, so that different developers will not create conflicting commands. |
data |
Bundle!: Any data to include with the command. |
Return | |
---|---|
Boolean |
true if the command was sent (whether or not the associated editor understood it), false if the input connection is no longer valid. |
removeComposingSpans
static fun removeComposingSpans(text: Spannable): Unit
Removes the composing spans from the given text if any.
Parameters | |
---|---|
text |
Spannable: the spannable text to remove composing spans This value cannot be null . |
replaceText
open fun replaceText(
start: Int,
end: Int,
text: CharSequence,
newCursorPosition: Int,
textAttribute: TextAttribute?
): Boolean
Replace the specific range in the editor with suggested text.
This method finishes whatever composing text is currently active and leaves the text as-it, replaces the specific range of text with the passed CharSequence, and then moves the cursor according to newCursorPosition
. This behaves like calling finishComposingText()
, setSelection(start, end)
, and then commitText(text, newCursorPosition,
.
Similar to setSelection(int,int)
, the order of start and end is not important. In effect, the region from start to end and the region from end to start is the same. Editor authors, be ready to accept a start that is greater than end.
Parameters | |
---|---|
start |
Int: Value is 0 or greater |
end |
Int: Value is 0 or greater |
newCursorPosition |
Int: the new cursor position around the text. If > 0, this is relative to the end of the text - 1; if <= 0, this is relative to the start of the text. So a value of 1 will always advance you to the position after the full text being inserted. Note that this means you can't position the cursor within the text. |
text |
CharSequence: This value cannot be null . |
textAttribute |
TextAttribute?: This value may be null . |
Return | |
---|---|
Boolean |
true if the replace command was sent to the associated editor (regardless of whether the replacement is success or not), false otherwise. |
reportFullscreenMode
open fun reportFullscreenMode(enabled: Boolean): Boolean
Updates InputMethodManager with the current fullscreen mode.
Return | |
---|---|
Boolean |
For editor authors, the return value will always be ignored. For IME authors, this always returns true on android.os.Build.VERSION_CODES#N_MR1 and prior devices and false on android.os.Build.VERSION_CODES#O and later devices. |
requestCursorUpdates
open fun requestCursorUpdates(cursorUpdateMode: Int): Boolean
The default implementation does nothing.
Parameters | |
---|---|
cursorUpdateMode |
Int: any combination of update modes and filters: CURSOR_UPDATE_IMMEDIATE , CURSOR_UPDATE_MONITOR , and data filters: CURSOR_UPDATE_FILTER_CHARACTER_BOUNDS , CURSOR_UPDATE_FILTER_EDITOR_BOUNDS , CURSOR_UPDATE_FILTER_INSERTION_MARKER , CURSOR_UPDATE_FILTER_VISIBLE_LINE_BOUNDS , CURSOR_UPDATE_FILTER_TEXT_APPEARANCE . Pass 0 to disable them. However, if an unknown flag is provided, request will be rejected and method will return false . |
Return | |
---|---|
Boolean |
true if the request is scheduled. false to indicate that when the application will not call InputMethodManager#updateCursorAnchorInfo( . Since Android android.os.Build.VERSION_CODES#N until android.os.Build.VERSION_CODES#TIRAMISU , this API returned false when the target application does not implement this method. |
sendKeyEvent
open fun sendKeyEvent(event: KeyEvent!): Boolean
Provides standard implementation for sending a key event to the window attached to the input connection's view.
Parameters | |
---|---|
event |
KeyEvent!: The key event. |
Return | |
---|---|
Boolean |
true on success, false if the input connection is no longer valid. |
setComposingRegion
open fun setComposingRegion(
start: Int,
end: Int
): Boolean
Parameters | |
---|---|
start |
Int: the position in the text at which the composing region begins |
end |
Int: the position in the text at which the composing region ends |
Return | |
---|---|
Boolean |
true on success, false if the input connection is no longer valid. Since Android android.os.Build.VERSION_CODES#N until android.os.Build.VERSION_CODES#TIRAMISU , this API returned false when the target application does not implement this method. |
setComposingSpans
open static fun setComposingSpans(text: Spannable): Unit
Removes the composing spans from the given text if any.
Parameters | |
---|---|
text |
Spannable: the spannable text to remove composing spans This value cannot be null . |
setComposingText
open fun setComposingText(
text: CharSequence!,
newCursorPosition: Int
): Boolean
The default implementation places the given text into the editable, replacing any existing composing text. The new text is marked as in a composing state with the composing style.
Parameters | |
---|---|
text |
CharSequence!: The composing text with styles if necessary. If no style object attached to the text, the default style for composing text is used. See android.text.Spanned for how to attach style object to the text. android.text.SpannableString and android.text.SpannableStringBuilder are two implementations of the interface android.text.Spanned . |
newCursorPosition |
Int: The new cursor position around the text. If > 0, this is relative to the end of the text - 1; if <= 0, this is relative to the start of the text. So a value of 1 will always advance you to the position after the full text being inserted. Note that this means you can't position the cursor within the text, because the editor can make modifications to the text you are providing so it is not possible to correctly specify locations there. |
Return | |
---|---|
Boolean |
true on success, false if the input connection is no longer valid. |
setSelection
open fun setSelection(
start: Int,
end: Int
): Boolean
The default implementation changes the selection position in the current editable text.
Parameters | |
---|---|
start |
Int: the character index where the selection should start. |
end |
Int: the character index where the selection should end. |
Return | |
---|---|
Boolean |
true on success, false if the input connection is no longer valid. |
takeSnapshot
open fun takeSnapshot(): TextSnapshot?
Default implementation that constructs TextSnapshot
with information extracted from BaseInputConnection
.
Return | |
---|---|
TextSnapshot? |
null when TextSnapshot cannot be fully taken. |