Most visited

Recently visited

Added in API level 3

BaseInputConnection

public class BaseInputConnection
extends Object implements InputConnection

java.lang.Object
   ↳ 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

From interface android.view.inputmethod.InputConnection

Public constructors

BaseInputConnection(View targetView, boolean fullEditor)

Public methods

boolean beginBatchEdit()

Default implementation does nothing.

boolean clearMetaKeyStates(int states)

Default implementation uses MetaKeyKeyListener.clearMetaKeyState(long, int) to clear the state.

void closeConnection()

Default implementation calls finishComposingText().

boolean commitCompletion(CompletionInfo text)

Default implementation does nothing and returns false.

boolean commitCorrection(CorrectionInfo correctionInfo)

Default implementation does nothing and returns false.

boolean commitText(CharSequence text, int newCursorPosition)

Default implementation replaces any existing composing text with the given text.

boolean deleteSurroundingText(int beforeLength, int afterLength)

The default implementation performs the deletion around the current selection position of the editable text.

boolean deleteSurroundingTextInCodePoints(int beforeLength, int afterLength)

The default implementation performs the deletion around the current selection position of the editable text.

boolean endBatchEdit()

Default implementation does nothing.

boolean finishComposingText()

The default implementation removes the composing state from the current editable text.

static int getComposingSpanEnd(Spannable text)
static int getComposingSpanStart(Spannable text)
int getCursorCapsMode(int reqModes)

The default implementation uses TextUtils.getCapsMode to get the cursor caps mode for the current selection position in the editable text, unless in dummy mode in which case 0 is always returned.

Editable getEditable()

Return the target of edit operations.

ExtractedText getExtractedText(ExtractedTextRequest request, int flags)

The default implementation always returns null.

Handler getHandler()

Called by the InputMethodManager to enable application developers to specify a dedicated Handler on which incoming IPC method calls from input methods will be dispatched.

CharSequence getSelectedText(int flags)

The default implementation returns the text currently selected, or null if none is selected.

CharSequence getTextAfterCursor(int length, int flags)

The default implementation returns the given amount of text from the current cursor position in the buffer.

CharSequence getTextBeforeCursor(int length, int flags)

The default implementation returns the given amount of text from the current cursor position in the buffer.

boolean performContextMenuAction(int id)

The default implementation does nothing.

boolean performEditorAction(int actionCode)

The default implementation turns this into the enter key.

boolean performPrivateCommand(String action, Bundle data)

The default implementation does nothing.

static final void removeComposingSpans(Spannable text)
boolean reportFullscreenMode(boolean enabled)

Updates InputMethodManager with the current fullscreen mode.

boolean requestCursorUpdates(int cursorUpdateMode)

The default implementation does nothing.

boolean sendKeyEvent(KeyEvent event)

Provides standard implementation for sending a key event to the window attached to the input connection's view.

boolean setComposingRegion(int start, int end)

Mark a certain region of text as composing text.

static void setComposingSpans(Spannable text)
boolean setComposingText(CharSequence text, int newCursorPosition)

The default implementation places the given text into the editable, replacing any existing composing text.

boolean setSelection(int start, int end)

The default implementation changes the selection position in the current editable text.

Inherited methods

From class java.lang.Object
From interface android.view.inputmethod.InputConnection

Public constructors

BaseInputConnection

Added in API level 3
BaseInputConnection (View targetView, 
                boolean fullEditor)

Parameters
targetView View
fullEditor boolean

Public methods

beginBatchEdit

Added in API level 3
boolean beginBatchEdit ()

Default implementation does nothing.

Returns
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

Added in API level 3
boolean clearMetaKeyStates (int states)

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().
Returns
boolean true on success, false if the input connection is no longer valid.

closeConnection

Added in API level 24
void closeConnection ()

Default implementation calls finishComposingText().

commitCompletion

Added in API level 3
boolean commitCompletion (CompletionInfo text)

Default implementation does nothing and returns false.

Parameters
text CompletionInfo: The committed completion.
Returns
boolean true on success, false if the input connection is no longer valid.

commitCorrection

Added in API level 11
boolean commitCorrection (CorrectionInfo correctionInfo)

Default implementation does nothing and returns false.

Parameters
correctionInfo CorrectionInfo: Detailed information about the correction.
Returns
boolean true on success, false if the input connection is no longer valid. In N and later, returns false when the target application does not implement this method.

commitText

Added in API level 3
boolean commitText (CharSequence text, 
                int newCursorPosition)

Default implementation replaces any existing composing text with the given text. In addition, only if dummy 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.
Returns
boolean true on success, false if the input connection is no longer valid.

deleteSurroundingText

Added in API level 3
boolean deleteSurroundingText (int beforeLength, 
                int afterLength)

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.
Returns
boolean true on success, false if the input connection is no longer valid.

deleteSurroundingTextInCodePoints

Added in API level 24
boolean deleteSurroundingTextInCodePoints (int beforeLength, 
                int afterLength)

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.
Returns
boolean true on success, false if the input connection is no longer valid. Returns false when the target application does not implement this method.

endBatchEdit

Added in API level 3
boolean endBatchEdit ()

Default implementation does nothing.

Returns
boolean true if there is still a batch edit in progress after closing the latest one (in other words, if the nesting count is > 0), false otherwise or if the input connection is no longer valid.

finishComposingText

Added in API level 3
boolean finishComposingText ()

The default implementation removes the composing state from the current editable text. In addition, only if dummy mode, a key event is sent for the new text and the current editable buffer cleared.

Returns
boolean true on success, false if the input connection is no longer valid.

getComposingSpanEnd

Added in API level 3
int getComposingSpanEnd (Spannable text)

Parameters
text Spannable
Returns
int

getComposingSpanStart

Added in API level 3
int getComposingSpanStart (Spannable text)

Parameters
text Spannable
Returns
int

getCursorCapsMode

Added in API level 3
int getCursorCapsMode (int reqModes)

The default implementation uses TextUtils.getCapsMode to get the cursor caps mode for the current selection position in the editable text, unless in dummy 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.
Returns
int the caps mode flags that are in effect at the current cursor position. See TYPE_TEXT_FLAG_CAPS_* in InputType.

getEditable

Added in API level 3
Editable getEditable ()

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.

Returns
Editable

getExtractedText

Added in API level 3
ExtractedText getExtractedText (ExtractedTextRequest request, 
                int flags)

The default implementation always returns null.

Parameters
request ExtractedTextRequest: Description of how the text should be returned. ExtractedTextRequest
flags int: Additional options to control the client, either 0 or GET_EXTRACTED_TEXT_MONITOR.
Returns
ExtractedText an 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

Added in API level 24
Handler getHandler ()

Called by the InputMethodManager to enable application developers to specify a dedicated Handler on which incoming IPC method calls from input methods will be dispatched.

Note: This does nothing when called from input methods.

Returns
Handler null to use the default Handler.

getSelectedText

Added in API level 9
CharSequence getSelectedText (int flags)

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.
Returns
CharSequence the text that is currently selected, if any, or null if no text is selected. In N and later, returns false when the target application does not implement this method.

getTextAfterCursor

Added in API level 3
CharSequence getTextAfterCursor (int length, 
                int flags)

The default implementation returns the given amount of text from the current cursor position in the buffer.

Parameters
length int: The expected length of the text.
flags int: Supplies additional options controlling how the text is returned. May be either 0 or GET_TEXT_WITH_STYLES.
Returns
CharSequence the text after the cursor position; the length of the returned text might be less than n.

getTextBeforeCursor

Added in API level 3
CharSequence getTextBeforeCursor (int length, 
                int flags)

The default implementation returns the given amount of text from the current cursor position in the buffer.

Parameters
length int: The expected length of the text.
flags int: Supplies additional options controlling how the text is returned. May be either 0 or GET_TEXT_WITH_STYLES.
Returns
CharSequence the text before the cursor position; the length of the returned text might be less than n.

performContextMenuAction

Added in API level 3
boolean performContextMenuAction (int id)

The default implementation does nothing.

Parameters
id int
Returns
boolean

performEditorAction

Added in API level 3
boolean performEditorAction (int actionCode)

The default implementation turns this into the enter key.

Parameters
actionCode int: This must be one of the action constants for EditorInfo.editorType, such as EditorInfo.EDITOR_ACTION_GO.
Returns
boolean true on success, false if the input connection is no longer valid.

performPrivateCommand

Added in API level 3
boolean performPrivateCommand (String action, 
                Bundle data)

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.
Returns
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

Added in API level 3
void removeComposingSpans (Spannable text)

Parameters
text Spannable

reportFullscreenMode

Added in API level 3
boolean reportFullscreenMode (boolean enabled)

Updates InputMethodManager with the current fullscreen mode.

Parameters
enabled boolean
Returns
boolean true on success, false if the input connection is no longer valid.

requestCursorUpdates

Added in API level 21
boolean requestCursorUpdates (int cursorUpdateMode)

The default implementation does nothing.

Parameters
cursorUpdateMode int: CURSOR_UPDATE_IMMEDIATE and/or CURSOR_UPDATE_MONITOR. Pass 0 to disable the effect of CURSOR_UPDATE_MONITOR.
Returns
boolean true if the request is scheduled. false to indicate that when the application will not call updateCursorAnchorInfo(android.view.View, CursorAnchorInfo). In N and later, returns false also when the target application does not implement this method.

sendKeyEvent

Added in API level 3
boolean sendKeyEvent (KeyEvent event)

Provides standard implementation for sending a key event to the window attached to the input connection's view.

Parameters
event KeyEvent: The key event.
Returns
boolean true on success, false if the input connection is no longer valid.

setComposingRegion

Added in API level 9
boolean setComposingRegion (int start, 
                int end)

Mark a certain region of text as composing text. If there was a composing region, the characters are left as they were and the composing span removed, as if finishComposingText() has been called. The default style for composing text is used.

The passed indices are clipped to the contents bounds. If the resulting region is zero-sized, no region is marked and the effect is the same as that of calling finishComposingText(). 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.

Since this does not change the contents of the text, editors should not call updateSelection(View, int, int, int, int) and IMEs should not receive onUpdateSelection(int, int, int, int, int, int).

This has no impact on the cursor/selection position. It may result in the cursor being anywhere inside or outside the composing region, including cases where the selection and the composing region overlap partially or entirely.

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
Returns
boolean true on success, false if the input connection is no longer valid. In N and later, false is returned when the target application does not implement this method.

setComposingSpans

Added in API level 3
void setComposingSpans (Spannable text)

Parameters
text Spannable

setComposingText

Added in API level 3
boolean setComposingText (CharSequence text, 
                int newCursorPosition)

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 Spanned for how to attach style object to the text. SpannableString and SpannableStringBuilder are two implementations of the interface 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.
Returns
boolean true on success, false if the input connection is no longer valid.

setSelection

Added in API level 3
boolean setSelection (int start, 
                int end)

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.
Returns
boolean true on success, false if the input connection is no longer valid.

Hooray!