public class BaseInputConnection extends Object implements InputConnection
getEditable()
to provide access to their own editable object.Modifier and Type | Field and Description |
---|---|
protected InputMethodManager |
mIMM |
GET_EXTRACTED_TEXT_MONITOR, GET_TEXT_WITH_STYLES
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. |
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 |
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.
|
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) |
protected void |
reportFinish()
Called when this InputConnection is no longer used by the InputMethodManager.
|
boolean |
reportFullscreenMode(boolean enabled)
Updates InputMethodManager with the current fullscreen mode.
|
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
protected void reportFinish()
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.public boolean commitText(CharSequence text, int newCursorPosition)
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 deleteSurroundingText(int beforeLength, int afterLength)
deleteSurroundingText
in interface InputConnection
beforeLength
- afterLength
- 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.public ExtractedText getExtractedText(ExtractedTextRequest request, int flags)
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 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
.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 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 {#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 setSelection(int start, int end)
setSelection
in interface InputConnection
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