/**
* The InputConnection interface is the communication channel from an
* {@link InputMethod} back to the application that is receiving its
* input. It is used to perform such things as reading text around the
* cursor, committing text to the text box, and sending raw key events
* to the application.
*InputConnection 是介于输入法和应用程序之间的通信通道。应用程序接收InputConnection的输入,InputConnection的作用就是循环从Cursor中读取text,往输入框中提交这些text。并且发送关键指令给应用程序。
*
Applications should never directly implement this interface, but
* instead subclass from {@link BaseInputConnection}. This will ensure
* that the application does not break when new methods are added to
* the interface.
*应用程序不应直接实现此接口,而是实现其子类BaseInputConnection。子类会保证应用程序在运行中不会停止运行,假如InputConnection增加了新的方法。
*
Implementing an IME or an editor
*
Text input is the result of the synergy of two essential components:
* an Input Method Engine (IME) and an editor. The IME can be a
* software keyboard, a handwriting interface, an emoji palette, a
* speech-to-text engine, and so on. There are typically several IMEs
* installed on any given Android device. In Android, IMEs extend
* {@link android.inputmethodservice.InputMethodService}.
* For more information about how to create an IME, see the
*
* Creating an input method guide.
*文字输入是由两个要素共同作用的结果。输入法应用程序和控件。
第一个要素:输入法应用程序。输入法程序可以是软键盘、手写板、表情符号,语音输入引擎等等。
android系统默认安装了几款输入法程序在android设备上。在android中,输入法应用程序继承自InputMethodService。
* The editor is the component that receives text and displays it.
* Typically, this is an {@link android.widget.EditText} instance, but
* some applications may choose to implement their own editor for
* various reasons. This is a large and complicated task, and an
* application that does this needs to make sure the behavior is
* consistent with standard EditText behavior in Android. An editor
* needs to interact with the IME, receiving commands through
* this InputConnection interface, and sending commands through
* {@link android.view.inputmethod.InputMethodManager}. An editor
* should start by implementing
* {@link android.view.View#onCreateInputConnection(EditorInfo)}
* to return its own input connection.
*第二个要素:编辑器。编辑器是用于接收输入法提交的文字并显示的控件。默认这个控件叫做EditText,但是很多应用程序基于特定需求也会实现他们自己的控件。实现自定义控件是一个大而且复杂的工作。
同时应用程序还要保证他们实现的控件符合android标准EditText行为规范。
控件需要和输入法保持沟通,控件可以通过InputConnection接收输入法提交的文字,通过InputMethodManager发送指令给输入法。
控件通过onCreateINputConnection得到自己的InputConnection对象。
*
If you are implementing your own IME, you will need to call the
* methods in this interface to interact with the application. Be sure
* to test your IME with a wide range of applications, including
* browsers and rich text editors, as some may have peculiarities you
* need to deal with. Remember your IME may not be the only source of
* changes on the text, and try to be as conservative as possible in
* the data you send and as liberal as possible in the data you
* receive.
*假如你实现了自己的输入法程序,你需要调用方法和应用程序保持沟通。并且确保你的输入法程序通过了大量应用程序的测试,例如
浏览器、往控件中提交大量的数据,因为有些应用程序含有特定的输入规格,你需要处理特定输入规则。
记住,你的输入法程序不是唯一一个改变控件内文字内容的来源,故而对待你提交的text和你接收的数据,尽可能保持谨慎。
*
If you are implementing your own editor, you will probably need
* to provide your own subclass of {@link BaseInputConnection} to
* answer to the commands from IMEs. Please be sure to test your
* editor with as many IMEs as you can as their behavior can vary a
* lot. Also be sure to test with various languages, including CJK
* languages and right-to-left languages like Arabic, as these may
* h