public class BaseInputConnection extends Object implements InputConnection
getEditable()
to provide access to their own editable object, and
to refer to the documentation in InputConnection
.Modifier and Type | Field and Description |
---|---|
protected InputMethodManager |
mIMM |
CURSOR_UPDATE_IMMEDIATE, CURSOR_UPDATE_MONITOR, GET_EXTRACTED_TEXT_MONITOR, GET_TEXT_WITH_STYLES, INPUT_CONTENT_GRANT_READ_URI_PERMISSION
Constructor and Description |
---|
BaseInputConnection(View targetView,
boolean fullEditor) |
Modifier and Type | Method and Description |
---|---|
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 |
commitContent(InputContentInfo inputContentInfo,
int flags,
Bundle opts)
The default implementation does nothing.
|
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 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) |
static void |
setComposingSpans(Spannable text,
int start,
int end) |
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.
|
protected final InputMethodManager mIMM
public BaseInputConnection(View targetView, boolean fullEditor)
public static final void removeComposingSpans(Spannable text)
public static void setComposingSpans(Spannable text)
public static void setComposingSpans(Spannable text, int start, int end)
public static int getComposingSpanStart(Spannable text)
public static int getComposingSpanEnd(Spannable text)
public Editable getEditable()
public boolean beginBatchEdit()
beginBatchEdit
in interface InputConnection
public boolean endBatchEdit()
endBatchEdit
in interface InputConnection
public void closeConnection()
finishComposingText()
.closeConnection
in interface InputConnection
public boolean clearMetaKeyStates(int states)
MetaKeyKeyListener.clearMetaKeyState(long, int)
to clear the state.clearMetaKeyStates
in interface InputConnection
states
- The states to be cleared, may be one or more bits as
per KeyEvent.getMetaState()
.public boolean commitCompletion(CompletionInfo text)
commitCompletion
in interface InputConnection
text
- The committed completion.public boolean commitCorrection(CorrectionInfo correctionInfo)
commitCorrection
in interface InputConnection
correctionInfo
- Detailed information about the correction.Build.VERSION_CODES.N
and later, returns false
when the target application does not implement this method.public boolean commitText(CharSequence text, int newCursorPosition)
commitText
in interface InputConnection
text
- The text to commit. This may include styles.newCursorPosition
- 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.public boolean deleteSurroundingText(int beforeLength, int afterLength)
deleteSurroundingText
in interface InputConnection
beforeLength
- 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
- 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.public boolean deleteSurroundingTextInCodePoints(int beforeLength, int afterLength)
deleteSurroundingTextInCodePoints
in interface InputConnection
beforeLength
- 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
- 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.false
when the target application does not implement this method.InputConnection.deleteSurroundingText(int, int)
public boolean finishComposingText()
finishComposingText
in interface InputConnection
public int getCursorCapsMode(int reqModes)
getCursorCapsMode
in interface InputConnection
reqModes
- 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.InputType
.public ExtractedText getExtractedText(ExtractedTextRequest request, int flags)
getExtractedText
in interface InputConnection
request
- Description of how the text should be returned.
ExtractedTextRequest
flags
- Additional options to control the client, either 0 or
InputConnection.GET_EXTRACTED_TEXT_MONITOR
.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.public CharSequence getTextBeforeCursor(int length, int flags)
getTextBeforeCursor
in interface InputConnection
length
- The expected length of the text.flags
- Supplies additional options controlling how the text is
returned. May be either 0 or InputConnection.GET_TEXT_WITH_STYLES
.public CharSequence getSelectedText(int flags)
getSelectedText
in interface InputConnection
flags
- Supplies additional options controlling how the text is
returned. May be either 0 or InputConnection.GET_TEXT_WITH_STYLES
.Build.VERSION_CODES.N
and
later, returns false when the target application does not implement
this method.public CharSequence getTextAfterCursor(int length, int flags)
getTextAfterCursor
in interface InputConnection
length
- The expected length of the text.flags
- Supplies additional options controlling how the text is
returned. May be either 0 or InputConnection.GET_TEXT_WITH_STYLES
.public boolean performEditorAction(int actionCode)
performEditorAction
in interface InputConnection
actionCode
- This must be one of the action constants for
EditorInfo.editorType
, such as
EditorInfo.EDITOR_ACTION_GO
.public boolean performContextMenuAction(int id)
performContextMenuAction
in interface InputConnection
public boolean performPrivateCommand(String action, Bundle data)
performPrivateCommand
in interface InputConnection
action
- 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
- Any data to include with the command.public boolean requestCursorUpdates(int cursorUpdateMode)
requestCursorUpdates
in interface InputConnection
cursorUpdateMode
- InputConnection.CURSOR_UPDATE_IMMEDIATE
and/or
InputConnection.CURSOR_UPDATE_MONITOR
. Pass 0
to disable the effect of
InputConnection.CURSOR_UPDATE_MONITOR
.true
if the request is scheduled. false
to indicate that when the
application will not call
InputMethodManager.updateCursorAnchorInfo(android.view.View, CursorAnchorInfo)
.
In Build.VERSION_CODES.N
and later, returns false
also when the
target application does not implement this method.public Handler getHandler()
InputConnection
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.
getHandler
in interface InputConnection
null
to use the default Handler
.public boolean setComposingText(CharSequence text, int newCursorPosition)
setComposingText
in interface InputConnection
text
- 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
- 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.public boolean setComposingRegion(int start, int end)
InputConnection
InputConnection.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 InputConnection.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
InputMethodManager.updateSelection(View, int, int, int, int)
and
IMEs should not receive
InputMethodService.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.
setComposingRegion
in interface InputConnection
start
- the position in the text at which the composing region beginsend
- the position in the text at which the composing region endsBuild.VERSION_CODES.N
and later, false is returned when the
target application does not implement this method.public boolean setSelection(int start, int end)
setSelection
in interface InputConnection
start
- the character index where the selection should start.end
- the character index where the selection should end.public boolean sendKeyEvent(KeyEvent event)
sendKeyEvent
in interface InputConnection
event
- The key event.KeyEvent
,
KeyCharacterMap.NUMERIC
,
KeyCharacterMap.PREDICTIVE
,
KeyCharacterMap.ALPHA
public boolean reportFullscreenMode(boolean enabled)
reportFullscreenMode
in interface InputConnection
public boolean commitContent(InputContentInfo inputContentInfo, int flags, Bundle opts)
commitContent
in interface InputConnection
inputContentInfo
- Content to be inserted.flags
- InputConnection.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
- optional bundle data. This can be null
.true
if this request is accepted by the application, whether the request
is already handled or still being handled in background, false
otherwise.