public class BaseInputConnection
extends Object
implements InputConnection
java.lang.Object | |
↳ | android.view.inputmethod.BaseInputConnection |
InputConnection接口的实现者的基类,负责提供与Editable连接的大多数常见行为。 这个类的实现者希望确保实现getEditable()
来访问他们自己的可编辑对象,并参考InputConnection
的文档。
Inherited constants |
---|
From interface android.view.inputmethod.InputConnection
|
Public constructors |
|
---|---|
BaseInputConnection(View targetView, boolean fullEditor) |
Public methods |
|
---|---|
boolean |
beginBatchEdit() 默认实现什么都不做。 |
boolean |
clearMetaKeyStates(int states) 默认实现使用 |
void |
closeConnection() 默认实现调用 |
boolean |
commitCompletion(CompletionInfo text) 默认实现什么也不做,并返回false。 |
boolean |
commitCorrection(CorrectionInfo correctionInfo) 默认实现什么也不做,并返回false。 |
boolean |
commitText(CharSequence text, int newCursorPosition) 默认实现用给定文本替换任何现有的组合文本。 |
boolean |
deleteSurroundingText(int beforeLength, int afterLength) 默认实现在可编辑文本的当前选择位置周围执行删除。 |
boolean |
deleteSurroundingTextInCodePoints(int beforeLength, int afterLength) 默认实现在可编辑文本的当前选择位置周围执行删除。 |
boolean |
endBatchEdit() 默认实现什么都不做。 |
boolean |
finishComposingText() 默认实现从当前可编辑文本中删除撰写状态。 |
static int |
getComposingSpanEnd(Spannable text) |
static int |
getComposingSpanStart(Spannable text) |
int |
getCursorCapsMode(int reqModes) 默认实现使用TextUtils.getCapsMode获取可编辑文本中当前选择位置的光标大小模式,除非在虚拟模式下总是返回0。 |
Editable |
getEditable() 返回编辑操作的目标。 |
ExtractedText |
getExtractedText(ExtractedTextRequest request, int flags) 默认实现总是返回null。 |
Handler |
getHandler() 由 |
CharSequence |
getSelectedText(int flags) 默认实现返回当前选中的文本,如果没有选中,则返回null。 |
CharSequence |
getTextAfterCursor(int length, int flags) 默认实现从缓冲区中的当前光标位置返回给定量的文本。 |
CharSequence |
getTextBeforeCursor(int length, int flags) 默认实现从缓冲区中的当前光标位置返回给定量的文本。 |
boolean |
performContextMenuAction(int id) 默认实现什么都不做。 |
boolean |
performEditorAction(int actionCode) 默认实现将其转换为输入密钥。 |
boolean |
performPrivateCommand(String action, Bundle data) 默认实现什么都不做。 |
static final void |
removeComposingSpans(Spannable text) |
boolean |
reportFullscreenMode(boolean enabled) 使用当前的全屏模式更新InputMethodManager。 |
boolean |
requestCursorUpdates(int cursorUpdateMode) 默认实现什么都不做。 |
boolean |
sendKeyEvent(KeyEvent event) 提供将关键事件发送到附加到输入连接视图的窗口的标准实现。 |
boolean |
setComposingRegion(int start, int end) 将文字的某个区域标记为撰写文字。 |
static void |
setComposingSpans(Spannable text) |
boolean |
setComposingText(CharSequence text, int newCursorPosition) 默认实现将给定的文本放入可编辑的文本中,替换任何现有的构成文本。 |
boolean |
setSelection(int start, int end) 默认实现更改当前可编辑文本中的选择位置。 |
Inherited methods |
|
---|---|
From class java.lang.Object
|
|
From interface android.view.inputmethod.InputConnection
|
BaseInputConnection (View targetView, boolean fullEditor)
Parameters | |
---|---|
targetView |
View
|
fullEditor |
boolean
|
boolean beginBatchEdit ()
默认实现什么都不做。
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. |
boolean clearMetaKeyStates (int states)
默认实现使用 MetaKeyKeyListener.clearMetaKeyState(long, int)
来清除状态。
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. |
boolean commitCompletion (CompletionInfo text)
默认实现什么也不做,并返回false。
Parameters | |
---|---|
text |
CompletionInfo : The committed completion. |
Returns | |
---|---|
boolean |
true on success, false if the input connection is no longer valid. |
boolean commitCorrection (CorrectionInfo correctionInfo)
默认实现什么也不做,并返回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. |
boolean commitText (CharSequence text, int newCursorPosition)
默认实现用给定文本替换任何现有的组合文本。 此外,只有在虚拟模式下,才会为新文本发送关键事件,并清除当前可编辑缓冲区。
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. |
boolean deleteSurroundingText (int beforeLength, int afterLength)
默认实现在可编辑文本的当前选择位置周围执行删除。
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. |
boolean deleteSurroundingTextInCodePoints (int beforeLength, int afterLength)
默认实现在可编辑文本的当前选择位置周围执行删除。
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. |
boolean endBatchEdit ()
默认实现什么都不做。
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. |
boolean finishComposingText ()
默认实现从当前可编辑文本中删除撰写状态。 此外,只有在虚拟模式下,才会为新文本发送关键事件,并清除当前可编辑缓冲区。
Returns | |
---|---|
boolean |
true on success, false if the input connection is no longer valid. |
int getComposingSpanEnd (Spannable text)
Parameters | |
---|---|
text |
Spannable
|
Returns | |
---|---|
int |
int getComposingSpanStart (Spannable text)
Parameters | |
---|---|
text |
Spannable
|
Returns | |
---|---|
int |
int getCursorCapsMode (int reqModes)
默认实现使用TextUtils.getCapsMode获取可编辑文本中当前选择位置的光标大小模式,除非在虚拟模式下总是返回0。
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 . |
Editable getEditable ()
返回编辑操作的目标。 默认实现返回它自己的伪造的可编辑,它只用于编写文本; 真正的文本编辑器的子类应该覆盖它并提供它们自己的。
Returns | |
---|---|
Editable |
ExtractedText getExtractedText (ExtractedTextRequest request, int flags)
默认实现总是返回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. |
Handler getHandler ()
由 InputMethodManager
调用,以使应用程序开发人员能够指定一个专用的 Handler
,其中来自输入方法的传入IPC方法调用将被分派。
注意:从输入法调用时,这没有任何作用。
Returns | |
---|---|
Handler |
null to use the default Handler . |
CharSequence getSelectedText (int flags)
默认实现返回当前选中的文本,如果没有选中,则返回null。
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. |
CharSequence getTextAfterCursor (int length, int flags)
默认实现从缓冲区中的当前光标位置返回给定量的文本。
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. |
CharSequence getTextBeforeCursor (int length, int flags)
默认实现从缓冲区中的当前光标位置返回给定量的文本。
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. |
boolean performContextMenuAction (int id)
默认实现什么都不做。
Parameters | |
---|---|
id |
int
|
Returns | |
---|---|
boolean |
boolean performEditorAction (int actionCode)
默认实现将其转换为输入密钥。
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. |
boolean performPrivateCommand (String action, Bundle data)
默认实现什么都不做。
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. |
void removeComposingSpans (Spannable text)
Parameters | |
---|---|
text |
Spannable
|
boolean reportFullscreenMode (boolean enabled)
使用当前的全屏模式更新InputMethodManager。
Parameters | |
---|---|
enabled |
boolean
|
Returns | |
---|---|
boolean |
true on success, false if the input connection is no longer valid. |
boolean requestCursorUpdates (int cursorUpdateMode)
默认实现什么都不做。
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. |
boolean sendKeyEvent (KeyEvent event)
提供将关键事件发送到附加到输入连接视图的窗口的标准实现。
Parameters | |
---|---|
event |
KeyEvent : The key event. |
Returns | |
---|---|
boolean |
true on success, false if the input connection is no longer valid. |
boolean setComposingRegion (int start, int end)
将文字的某个区域标记为撰写文字。 如果存在组合区域,则字符将保持原样并且删除组合范围,就好像finishComposingText()
。 使用编写文本的默认样式。
通过的索引被剪裁到内容边界。 如果结果区域为零,则不标记区域,其效果与调用finishComposingText()
的效果相同。 开始和结束的顺序并不重要。 实际上,从开始到结束的区域和从结束到开始的区域是相同的。 编辑作者,准备好接受比结束更大的开始。
由于这不会改变文本的内容,所以编辑不应该调用 updateSelection(View, int, int, int, int)
,IME不应该得到 onUpdateSelection(int, int, int, int, int, int)
。
这对光标/选择位置没有影响。 这可能导致光标位于组合区域内部或外部的任何位置,包括选择和组合区域部分或全部重叠的情况。
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. |
void setComposingSpans (Spannable text)
Parameters | |
---|---|
text |
Spannable
|
boolean setComposingText (CharSequence text, int newCursorPosition)
默认实现将给定的文本放入可编辑的文本中,替换任何现有的构成文本。 新文本被标记为处于合成状态并具有撰写风格。
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. |
boolean setSelection (int start, int end)
默认实现更改当前可编辑文本中的选择位置。
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. |