public class InputConnectionWrapper extends Object implements InputConnection
Wrapper class for proxying calls to another InputConnection. Subclass and have fun!
GET_EXTRACTED_TEXT_MONITOR, GET_TEXT_WITH_STYLES
Constructor and Description |
---|
InputConnectionWrapper(InputConnection target,
boolean mutable) |
Modifier and Type | Method and Description |
---|---|
boolean |
beginBatchEdit()
Tell the editor that you are starting a batch of editor operations.
|
boolean |
clearMetaKeyStates(int states)
Clear the given meta key pressed states in the given input connection.
|
boolean |
commitCompletion(CompletionInfo text)
Commit a completion the user has selected from the possible ones
previously reported to
InputMethodSession.displayCompletions() . |
boolean |
commitCorrection(CorrectionInfo correctionInfo)
Commit a correction automatically performed on the raw user's input.
|
boolean |
commitText(CharSequence text,
int newCursorPosition)
Commit text to the text box and set the new cursor position.
|
boolean |
deleteSurroundingText(int beforeLength,
int afterLength)
Delete beforeLength characters of text before the current cursor
position, and delete afterLength characters of text after the
current cursor position, excluding composing text.
|
boolean |
endBatchEdit()
Tell the editor that you are done with a batch edit previously
initiated with
InputConnection.beginBatchEdit() . |
boolean |
finishComposingText()
Have the text editor finish whatever composing text is currently
active.
|
int |
getCursorCapsMode(int reqModes)
Retrieve the current capitalization mode in effect at the current
cursor position in the text.
|
ExtractedText |
getExtractedText(ExtractedTextRequest request,
int flags)
Retrieve the current text in the input connection's editor, and monitor
for any changes to it.
|
CharSequence |
getSelectedText(int flags)
Gets the selected text, if any.
|
CharSequence |
getTextAfterCursor(int n,
int flags)
Get n characters of text after the current cursor position.
|
CharSequence |
getTextBeforeCursor(int n,
int flags)
Get n characters of text before the current cursor position.
|
boolean |
performContextMenuAction(int id)
Perform a context menu action on the field.
|
boolean |
performEditorAction(int editorAction)
Have the editor perform an action it has said it can do.
|
boolean |
performPrivateCommand(String action,
Bundle data)
API to send private commands from an input method to its connected
editor.
|
boolean |
reportFullscreenMode(boolean enabled)
Called by the IME to tell the client when it switches between fullscreen
and normal modes.
|
boolean |
sendKeyEvent(KeyEvent event)
Send a key event to the process that is currently attached through
this input connection.
|
boolean |
setComposingRegion(int start,
int end)
Mark a certain region of text as composing text.
|
boolean |
setComposingText(CharSequence text,
int newCursorPosition)
Set composing text around the current cursor position with the given text,
and set the new cursor position.
|
boolean |
setSelection(int start,
int end)
Set the selection of the text editor.
|
void |
setTarget(InputConnection target)
Change the target of the input connection.
|
public InputConnectionWrapper(InputConnection target, boolean mutable)
public void setTarget(InputConnection target)
public CharSequence getTextBeforeCursor(int n, int flags)
InputConnection
This method may fail either if the input connection has become invalid (such as its process crashing) or the client is taking too long to respond with the text (it is given a couple seconds to return). In either case, a null is returned.
getTextBeforeCursor
in interface InputConnection
n
- 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 getTextAfterCursor(int n, int flags)
InputConnection
This method may fail either if the input connection has become invalid (such as its process crashing) or the client is taking too long to respond with the text (it is given a couple seconds to return). In either case, a null is returned.
getTextAfterCursor
in interface InputConnection
n
- 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)
InputConnection
This method may fail if either the input connection has become invalid (such as its process crashing) or the client is taking too long to respond with the text (it is given a couple of seconds to return). In either case, a null is returned.
getSelectedText
in interface InputConnection
flags
- Supplies additional options controlling how the text is
returned. May be either 0 or InputConnection.GET_TEXT_WITH_STYLES
.public int getCursorCapsMode(int reqModes)
InputConnection
TextUtils.getCapsMode
for
more information.
This method may fail either if the input connection has become invalid (such as its process crashing) or the client is taking too long to respond with the text (it is given a couple seconds to return). In either case, a 0 is returned.
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.public ExtractedText getExtractedText(ExtractedTextRequest request, int flags)
InputConnection
This method may fail either if the input connection has become invalid (such as its process crashing) or the client is taking too long to respond with the text (it is given a couple seconds to return). In either case, a null is returned.
getExtractedText
in interface InputConnection
request
- Description of how the text should be returned.flags
- Additional options to control the client, either 0 or
InputConnection.GET_EXTRACTED_TEXT_MONITOR
.public boolean deleteSurroundingText(int beforeLength, int afterLength)
InputConnection
deleteSurroundingText
in interface InputConnection
beforeLength
- The number of characters to be deleted before the
current cursor position.afterLength
- The number of characters to be deleted after the
current cursor position.public boolean setComposingText(CharSequence text, int newCursorPosition)
InputConnection
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 {#link android.text.Spanned} for how to attach style
object to the text. {#link android.text.SpannableString} and
{#link android.text.SpannableStringBuilder} are two
implementations of the interface {#link android.text.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
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 endspublic boolean finishComposingText()
InputConnection
finishComposingText
in interface InputConnection
public boolean commitText(CharSequence text, int newCursorPosition)
InputConnection
commitText
in interface InputConnection
text
- The committed text.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 commitCompletion(CompletionInfo text)
InputConnection
InputMethodSession.displayCompletions()
. This will result in the
same behavior as if the user had selected the completion from the
actual UI.commitCompletion
in interface InputConnection
text
- The committed completion.public boolean commitCorrection(CorrectionInfo correctionInfo)
InputConnection
commitCorrection
in interface InputConnection
correctionInfo
- Detailed information about the correction.public boolean setSelection(int start, int end)
InputConnection
setSelection
in interface InputConnection
public boolean performEditorAction(int editorAction)
InputConnection
performEditorAction
in interface InputConnection
editorAction
- This must be one of the action constants for
EditorInfo.editorType
, such as
EditorInfo.EDITOR_ACTION_GO
.public boolean performContextMenuAction(int id)
InputConnection
android.R.id#selectAll
,
android.R.id#startSelectingText
, android.R.id#stopSelectingText
,
android.R.id#cut
, android.R.id#copy
,
android.R.id#paste
, android.R.id#copyUrl
,
or android.R.id#switchInputMethod
performContextMenuAction
in interface InputConnection
public boolean beginBatchEdit()
InputConnection
InputConnection.endBatchEdit()
is called.beginBatchEdit
in interface InputConnection
public boolean endBatchEdit()
InputConnection
InputConnection.beginBatchEdit()
.endBatchEdit
in interface InputConnection
public boolean sendKeyEvent(KeyEvent event)
InputConnection
This method can be used to send key events to the application. For example, an on-screen keyboard may use this method to simulate a hardware keyboard. There are three types of standard keyboards, numeric (12-key), predictive (20-key) and ALPHA (QWERTY). You can specify the keyboard type by specify the device id of the key event.
You will usually want to set the flag
KeyEvent.FLAG_SOFT_KEYBOARD
on all
key event objects you give to this API; the flag will not be set
for you.
Note that it's discouraged to send such key events in normal operation;
this is mainly for use with InputType.TYPE_NULL
type
text fields. Use the InputConnection.commitText(java.lang.CharSequence, int)
family of methods to send text
to the application instead.
sendKeyEvent
in interface InputConnection
event
- The key event.KeyEvent
,
KeyCharacterMap.NUMERIC
,
KeyCharacterMap.PREDICTIVE
,
KeyCharacterMap.ALPHA
public boolean clearMetaKeyStates(int states)
InputConnection
clearMetaKeyStates
in interface InputConnection
states
- The states to be cleared, may be one or more bits as
per KeyEvent.getMetaState()
.public boolean reportFullscreenMode(boolean enabled)
InputConnection
InputMethodService
.reportFullscreenMode
in interface InputConnection
public boolean performPrivateCommand(String action, Bundle data)
InputConnection
EditorInfo
to determine if
a client supports a particular command.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.