android_输入法介绍

 

 

 

 

 

  单态模式:直接初始化的静态变量;静态变量,第一次调用时初始化(线程安全);


  InputDevice类:Describes the capabilities of a particular input device.
  InputManager类:Provides information about input devices and available key layouts.
  InputMethodManager类:
  For the rare people amongst us writing their own text editors, you will need to implement onCreateInputConnection(EditorInfo) to return a new instance of your own InputConnection interface allowing the IME to interact with your editor.
  Only the system is allowed to directly access an IME's InputMethod interface, via the BIND_INPUT_METHOD permission.
  Only the active client's InputConnection will accept operations.
  A client application can ask that the system let the user pick a new IME, but can not programmatically switch to one itself.
  InputMethodSession接口:实现该接口的有AbstractInputMethodService.AbstractInputMethodSessionImpl, InputMethodService.InputMethodSessionImpl
  The InputMethodSession interface provides the per-client functionality of InputMethod that is safe to expose to applications.
  Applications will not normally use this interface themselves, instead relying on the standard interaction provided by TextView and EditText.
  InputConnection接口:实现该接口的有BaseInputConnection,InputConnectionWrapper;
  The InputConnection interface is the communication channel from an InputMethod back to the application that is receiving its input.
  An editor needs to interact with the IME, receiving commands through this InputConnection interface, and sending commands through InputMethodManager. An editor should start by implementing onCreateInputConnection(EditorInfo) to return its own input connection.
  EditorInfo类:An EditorInfo describes several attributes of a text editing object that an input method is communicating with (typically an EditText), most importantly the type of text content it contains.
  mViewGroup.removeView(mView) Note: do not invoke this method from draw(android.graphics.Canvas), onDraw(android.graphics.Canvas), dispatchDraw(android.graphics.Canvas) or any related method.
  mViewGroup.dispatchDraw(mCanvas) Called by draw to draw the child views. This may be overridden by derived classes to gain control just before its children are drawn (but after its own view has been drawn).
  TaskStackBuilder类:Utility class for constructing synthetic back stacks for cross-task navigation on Android 3.0 and newer. TaskStackBuilder provides a way to obey the correct conventions around cross-task navigation.

 

  ImePreferences的Demo
  在Android系统中,除了输入法窗口之外,还有一种窗口称为输入法对话框,它们总是位于输入窗口的上面。Activity窗口、输入法窗口和输入法对话框;WmS服务是使用堆栈来组织系统中的窗口的。
  WmS服务的职能之一就是要时刻关注系统中是否有窗口需要使用输入法。WmS服务一旦发现有窗口需要使用输入法,那么就会调整输入法窗口以及输入法对话框在窗口堆栈中的位置,使得它们放置在需要使用输入法的窗口的上面。
  输入法窗口,WmS则调用WmS类的成员函数addInputMethodWindowToListLocked来将该WindowState对象插入到窗口堆栈的合适位置去。
  输入法对话框,WmS则调用WmS类的成员函数addWindowToListInOrderLocked和adjustInputMethodDialogsLocked来将该WindowState对象插入到窗口堆栈的合适位置去。
  InputMethodService类 --> AbstractInputMethodService --> Service --> ContextWrapper --> Context --> Object.
  In addition to the normal Service lifecycle methods, this class introduces some new specific callbacks that most subclasses will want to make use of:
  onInitializeInterface() for user-interface initialization, in particular to deal with configuration changes while the service is running.
  onBindInput() to find out about switching to a new client.
  onStartInput(EditorInfo, boolean) to deal with an input session starting with the client.
  onCreateInputView(), onCreateCandidatesView(), and onCreateExtractTextView() for non-demand generation of the UI.
  onStartInputView(EditorInfo, boolean) to deal with input starting within the input area of the IME.
  Soft Input View;  Candidates View; 
  Generating Text,The key part of an IME is of course generating text for the application. This is done through calls to the InputConnection interface to the application, which can be retrieved from getCurrentInputConnection(). This interface allows you to generate raw key events or, if the target supports it, directly edit in strings of candidates and committed text.
  PreferenceActivity类 --> ListActivity --> Activity --> ContextThemeWrapper --> ContextWrapper --> Context --> Object.
  This is the base class for an activity to show a hierarchy of preferences to the user.
  Preference类,Represents the basic Preference UI building block displayed by a PreferenceActivity in the form of a ListView. This class provides the View to be displayed in the activity and associates with a SharedPreferences to store/retrieve the preference data.
  SharedPreferences类,Interface for accessing and modifying preference data returned by getSharedPreferences(String, int).
  app的service具有BIND_INPUT_METHOD权限,表明这是一个输入法服务。在intent-filter中使用android.view.InputMethod action来定义,最后通过name为android.view.im的meta-data来描述该输入法的一些属性,meta-data引用的是一个XML文件,该文件是输入法的配置文件,用来配置一些信息,例如是否为默认输入法,是否具有配置Activity来配置输入法的一些选项,如果指定了配置Activity则在系统设置界面中的输入法设置中可以启动该Activity来设置输入法的配置项。
  mInputMethodService.getCurrentInputConnection();获取InputConnection对象;

 


   罗升阳博客:http://blog.csdn.net/luoshengyang/article/details/8526644
  在Android系统中,输入法窗口是一种特殊类型的窗口,它总是位于需要使用输入法的窗口的上面。也就是说,一旦WindowManagerService服务检测到焦点窗口需要使用输入法,那么它就会调整输入法窗口在窗口堆栈中的位置,使得输入法窗口位于在焦点窗口的上面,这样用户可以通过输入法窗口来录入字母或者文字。
  在Android系统中,除了输入法窗口之外,还有一种窗口称为输入法对话框,它们总是位于输入窗口的上面。Activity窗口、输入法窗口和输入法对话框。
  WindowManagerService服务是使用堆栈来组织系统中的窗口。
  WindowManagerService服务的职能之一就是要时刻关注系统中是否有窗口需要使用输入法。WindowManagerService服务一旦发现有窗口需要使用输入法,那么就会调整输入法窗口以及输入法对话框在窗口堆栈中的位置,使得它们放置在需要使用输入法的窗口的上面。
  首先分析两个需要调整输入法窗口以及输入法对话框在窗口堆栈中的位置的情景,然后再分析它们是如何在窗口堆栈中进行调整的。
  第一个需要调整输入法窗口以及输入法对话框在窗口堆栈中的位置的情景是增加一个窗口到WindowManagerService服务去的时候。通过调用WindowManagerService类的成员函数addWindow来实现的。
  如果当前增加到WindowManagerService服务来的是一个输入法窗口,那么就会将前面为它所创建的一个WindowState对象win保存在WindowManagerService类的成员变量mInputMethodWindow中,接着还会调用WindowManagerService类的成员函数addInputMethodWindowToListLocked来将该WindowState对象插入到窗口堆栈的合适位置去。
  如果当前增加到WindowManagerService服务来的是一个输入法对话框,即参数attrs所描述的一个WindowManager.LayoutParams对象的成员变量type的值等于TYPE_INPUT_METHOD_DIALOG,那么就会将前面为它所创建的一个WindowState对象win添加到WindowManagerService类的成员变量mInputMethodDialogs所描述的一个ArrayList中去,并且先后调用WindowManagerService类的成员函数addWindowToListInOrderLocked和adjustInputMethodDialogsLocked来将该WindowState对象插入到窗口堆栈的合适位置去。
  在上述两种情况中,由于用来描述输入法窗口或者输入法对话框的WindowState对象已经被插入到了窗口堆栈中的合适位置,因此,接下来就不再需要考虑移动该输入法窗口或者输入法对话框了,这时候变量imMayMove的值就会被设置为false。
  另一方面,如果当前增加到WindowManagerService服务来的既不是一个输入法窗口,也不是一个输入法对话框,并且该窗口需要接收键盘事件,即前面所创建的WindowState对象win的成员函数canReceiveKeys的返回值为true,那么就可能会导致系统当前获得焦点的窗口发生变化,这时候就需要调用WindowManagerService类的成员函数updateFocusedWindowLocked来重新计算系统当前获得焦点的窗口。如果系统当前获得焦点的窗口发生了变化,那么WindowManagerService类的成员函数updateFocusedWindowLocked的返回值focusChanged就会等于true,同时系统的输入法窗口和输入法对话框在窗口堆栈中的位置也会得到调整,即位它们会位于系统当前获得焦点的窗口的上面,因此,这时候变量imMayMove的值也会被设置为false,表示接下来不再需要考虑移动系统中的输入法窗口或者输入法对话框在窗口堆栈中的位置。
  可能需要调用WindowManagerService类的成员函数addInputMethodWindowToListLocked、addWindowToListInOrderLocked、adjustInputMethodDialogsLocked和moveInputMethodWindowsIfNeededLocked来移动系统的输入法窗口和输入法对话框;
  第二个需要调整输入法窗口以及输入法对话框在窗口堆栈中的位置的情景是一个应用程序进程请求WindowManagerService服务重新布局一个窗口的时候。应用程序进程请求WindowManagerService服务重新布局一个窗口最终是通过调用WindowManagerService类的成员函数relayoutWindow来实现的。
  应用程序进程在请求WindowManagerService服务重新布局一个窗口的时候,这个窗口的一些布局参数可能会发生变化,而这些变化可能会同时引发系统的输入法窗口以及输入法对话框在窗口堆栈中的位置发生变化。如果系统的输入法窗口以及输入法对话框在窗口堆栈中的位置发生了变化,那么就需要调整它们在窗口堆栈中的位置。

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值