/**

 * 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。而且发送关键指令给应用程序。

 * <p>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.</p>

 *应用程序不应直接实现此接口,而是实现其子类BaseInputConnection。子类会保证应用程序在执行中不会停止执行。假如InputConnection添加了新的方法。

* <h3>Implementing an IME or an editor</h3>

 * <p>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

 * <a href="{@docRoot}guide/topics/text/creating-input-method.html">

 * Creating an input method</a> 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.</p>

 *第二个要素:编辑器。

编辑器是用于接收输入法提交的文字并显示的控件。默认这个控件叫做EditText,可是非常多应用程序基于特定需求也会实现他们自己的控件。实现自己定义控件是一个大并且复杂的工作。

同一时候应用程序还要保证他们实现的控件符合android标准EditText行为规范。

控件须要和输入法保持沟通,控件能够通过InputConnection接收输入法提交的文字,通过InputMethodManager发送指令给输入法。

控件通过onCreateINputConnection得到自己的InputConnection对象。

 * <p>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.</p>

 *假如你实现了自己的输入法程序,你须要调用方法和应用程序保持沟通。而且确保你的输入法程序通过了大量应用程序的測试。比如浏览器、往控件中提交大量的数据,由于有些应用程序含有特定的输入规格。你须要处理特定输入规则。

记住,你的输入法程序不是唯一一个改变控件内文字内容的来源,故而对待你提交的text和你接收的数据,尽可能保持慎重。

* <p>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

 * have different input requirements. When in doubt about the

 * behavior you should adopt for a particular call, please mimic the

 * default TextView implementation in the latest Android version, and

 * if you decide to drift from it, please consider carefully that

 * inconsistencies in text edition behavior is almost universally felt

 * as a bad thing by users.</p>

 *假如你实现了自己的编辑器,你就须要提供你自己实现的BaseInputConnection子类实例。此实例用于和输入法应用程序保持应答。

确保你的控件通过了大部分输入法的測试,由于他们的行为变化多端。

同一时候确保在多语言下进行測试,包含CJK或者从右到左的语言,比如arabic。

由于这些语言有非常多不同的输入要求。

当你对实现的控件的行为存有疑问时。你能够通话我们。或者模仿近期的android版本号的TextView实现。假如你确定在你的系统中使用它,请考虑清楚控件的文字输入可能让用户体验非常坏。

 * <h3>Cursors, selections and compositions</h3>

 * <p>In Android, the cursor and the selection are one and the same

 * thing. A "cursor" is just the special case of a zero-sized

 * selection. As such, this documentation uses them

 * interchangeably. Any method acting "before the cursor" would act

 * before the start of the selection if there is one, and any method

 * acting "after the cursor" would act after the end of the

 * selection.</p>

 *在android中。光标和所选内容一件事。光标就是一个0内容的所选内容。因而在android中,他们能够互换。

不论什么方法提交在光标前行为就是在提交所选内容之前,同理。在光标之后。就是提交在所选内容之后一样的行为。

* <p>An editor needs to be able to keep track of a currently

 * "composing" region, like the standard edition widgets do. The

 * composition is marked in a specific style: see

 * {@link android.text.Spanned#SPAN_COMPOSING}. IMEs use this to help

 * the user keep track of what part of the text they are currently

 * focusing on, and interact with the editor using

 * {@link InputConnection#setComposingText(CharSequence, int)},

 * {@link InputConnection#setComposingRegion(int, int)} and

 * {@link InputConnection#finishComposingText()}.

 * The composing region and the selection are completely independent

 * of each other, and the IME may use them however they see fit.</p>

 */

编辑器控件须要可以保持写作内容区域的能力,就像标准的编辑小部件一样。

写作区域会被应用特定样式。比如:android.text.Spanned#SPAN_COMPOSING,输入法使用这样来帮助用户保持和当前获取焦点的文字内容追踪的能力,通过setComposingText或者finishComposingText等方法。

输入法InputConnection的更多相关文章

  1. Android源码剖析之Framwork层后记篇(硬件消息传递、apk管理、输入法框架、编译过程)

    本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 既然写到后记篇,就代表本系列到此为止,暂时告一段落:其他一些Manager随后有时间再补,就像源码的 ...

  2. Android InputMethodManager输入法简介

    正文 一.结构 public final class InputMethodManager extends Object Java.lang.Object android.view.inputmeth ...

  3. Android输入法开发

    1. 概念 * IMF: 输入法框架(Input Method Framework) * IM: 输入法(Input Method) * IMS: 输入法服务(Input Method Service ...

  4. Android输入法扩展之外接键盘中文输入

    大家想不想要这样一台Android  Surface平板,看着就过瘾吧. watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvSVRsZWFrcw==/font/ ...

  5. Android简易项目--傻瓜式阿拉伯语输入法(Dummy Arabic Input)

    一.应用名称 Android简易项目--傻瓜式阿拉伯语输入法(Dummy Arabic Input) 二.应用图标 三.应用说明 现在通行的阿拉伯语键盘布局并无规律可循,阿拉伯语使用者需要花费较多时间 ...

  6. Android输入法框架系统(下)

    程序焦点获取事件导致输入法显示 从上面可以知道程序获得焦点时,程序端会先间接的调用IMMS的startInput将焦点View绑定到输入法,然后会调用IMMS的windowGainFocus函数,这个 ...

  7. Android输入法框架系统(上)

    输入法,就是用来输入字符(包括英文,俄文,中文)的工具.输入法你可以看成是一种字符发生器,它将输入数据触摸事件或者按键事件转化为其他更丰富的字符.在PC时代,输入法的原始输入来自实体键盘,鼠标,然后输 ...

  8. Android输入法架构学习总结

    此文为本人学习输入法之后所做的一个总结报告.与大家分享. 安卓输入法框架(Input Method Framework)IMF 一.输入法框架简介 自Android平台1.5版本以后,Google开放 ...

  9. 写一个Android输入法02——候选窗、转换

    上一篇介绍了完成Android输入法的最小化步骤,它只能将按键对应的字符上屏.一般的东亚语言都有一个转换的过程,比如汉语输入拼音,需要由拼音转成汉字再上屏.本文将在前文基础上加入完成转换过程所必需的候 ...

随机推荐

  1. [Apple开发者帐户帮助]八、管理档案(4)

    您可以编辑,下载或删除在开发人员帐户中创建的配置文件.例如,如果您撤消了证书或禁用了配置文件中包含的设备,请编辑配置文件.或重新置备的个人资料,如果因为你它是无效的功能的应用程式服务. 注意: Xco ...

  2. [Swift通天遁地]二、表格表单-(5)实现表格下拉和上拉刷新效果

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  3. Akka源码分析-ask模式

    在我之前的博文中,已经介绍过要慎用Actor的ask.这里我们要分析一下ask的源码,看看它究竟是怎么实现的. 开发时,如果要使用ask方法,必须要引入akka.pattern._,这样才能使用ask ...

  4. Python/Django 下载Excel2003

    一.安装 目前支持Excel2003的第三方库多少还有几个,本文使用的是xlwt,安装方式命令行:pip install xlwt 二.使用 首先.引入该库,例如:from xlwt import * ...

  5. python 画图

    1.根据实际图形,用符号画出原来图形 from PIL import Image import argparse #命令行输入参数处理 parser = argparse.ArgumentParser ...

  6. SVD 学习笔记

    本文主要学习了这篇博客:http://www.cnblogs.com/LeftNotEasy/archive/2011/01/19/svd-and-applications.html,将SVD讲的恨透 ...

  7. ASP.NET 之正则表达式

    转载自:http://www.regexlib.com/cheatsheet.htm?AspxAutoDetectCookieSupport=1 Metacharacters Defined MCha ...

  8. C语言关键字之sizeof

    C语言关键字 sizeof 是一个操作符,返回对象或类型所占内存字节数,类型为size_t(定义在<stddef.h>),有2种用法: sizeof unary-expression si ...

  9. 学习java编程能往哪些方向发展

    当下Java训练非常热,是因为通过学习java能够快速的就业,这对于今年就业压力非常大的大学生来说,无疑是一条就业的捷路,虽然培教育费动辄过万,但还是非常值得的. 可是你可曾想过,学习了java编程后 ...

  10. 【技术累积】【点】【java】【21】序列化二三事

    基础概念 把对象等转为二进制进行传输的是序列化,反之为反序列化: 应用场景一般为读写文件,传输数据/接口调用: Externalizable和Serializable java的序列化方式有两种: S ...