Android输入法架构件.ppt_第1页
Android输入法架构件.ppt_第2页
Android输入法架构件.ppt_第3页
Android输入法架构件.ppt_第4页
Android输入法架构件.ppt_第5页
已阅读5页,还剩30页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Android输入法架构,1,.,输入法,为系统中其他模块提供输入功能的模块1硬键盘2软键盘3手写4语音输入问题:输入法和应用分属不同的模块,如何输入内容?,2,输入法,问题:输入法和应用分属不同模块,不同进程,如何交互?,?,3,输入法整体架构图,注:虚线框用于区分不同的进程,输入法管理器InputMethodManager,Application,InputMethodManagerService输入法管理服务,WindowManagerService窗口管理服务,InputMethodService,服务框架,UI模块inputViewcandView全屏,桥接器跨进程调用,BINDER,BINDER,BINDER,4,输入法应用进程部分,输入应用的内部架构,UI模块inputViewcandView全屏,InputMehtodService,AbstractInputMethodService,Service,KeyEvent.Callback,classAbstractInputMethodImplImplementInputMethod,classAbstractInputMethodSessionImplImplementInputMethodSession,extends,extends,implement,接口InputMethod作用:1创建时绑定到系统服务中2绑定Ime到应用程序上下文3开启或结束输入过程4InputMethodSession操作InputMethodSession:可提供给App使用的输入法功能接口,5,InputMethodService,InputMethodService功能接口部分,InputMethodService,InputMethodImplextendsAbstractInputMethodImpl,InputMethodSessionImplextendsAbstractInputMethodSessionImpl,1attachToken2bindInput3unbindInput4startInput5restartInput6hideSoftInput7showSoftInput,1finishInput2displayCompletions3updateExtractedText4updateSelection5updateCursor6appPrivateCommand7toggleSoftInput,6,InputMethodService,InputMethodServiceGUI部分,InputMethodService,SoftInputWindowextendsDialog,1显示全屏视图的容器:ViewGroupmFullscreenArea2横屏模式下的编辑框和按钮容器:FrameLayoutmExtractFrame3候选栏视图容器:FrameLayoutmCandidatesFrame4输入主视图容器FrameLayoutmInputFrame,窗口内容视图ViewmRootView,包含,7,InputMethodService,InputMethodServiceGUI部分,mCandidatesFrame,mInputFrame,mExtractFrame,横屏模式,竖屏模式,8,Application端,App端:,InputMethodManager,TextView,InputMethodManagerService,ViewRoot,onWindowFocus,showSoftInput,焦点切换及绑定,请求调用输入法,BINDER,WindowManagerService,焦点认证,9,系统服务端,系统服务端:,InputMethodManager,InputMethodManagerServiceextendsIInputMethodManager.Stub,BINDER,ServiceConnection,Handler.Callback,接口实现,SessionState,IInputMethodIInputMethodSessionClientState,IInputMethodClientIInputContext,APP端,系统服务端,InputMethodService,输入法应用端,BINDER,10,模块和接口分析,IInputMethodManager提供的接口方法列表:-ListgetInputMethodList();ListgetEnabledInputMethodList();-voidaddClient();voidremoveClient();-InputBindResultstartInput(,EditorInfo,);voidfinishInput();-voidshowSoftInput();voidhideSoftInput();voidshowInputMethodPickerFromClient();voidhideMySoftInput();-voidsetInputMethod();booleansetInputMethodEnabled();-voidupdateStatusIcon();voidwindowGainedFocus();,11,输入法接口之IInputMethod,IInputMethod定义的接口作用:一个连接输入法部件的顶层接口。,voidattachToken();voidbindInput(inInputBinding);voidunbindInput();/绑定相关-voidstartInput(inEditorInfo);voidrestartInput(inEditorInfo);-voidcreateSession(IInputMethodCallback);/会话相关voidsetSessionEnabled(IInputMethodSession,boolean);voidrevokeSession(IInputMethodSession);-voidshowSoftInput(booleanexplicit);voidhideSoftInput();/软键盘显示、隐藏,12,IInputMethod及其使用,IInputMethodWrapper,AbstractInputMethodService,IInputMethod.Stub,HandlerCaller.Callback,extends,implements,HandlerCaller,InputMethod,包含,IInputContext,BINDER调用,系统服务端,输入法应用端,系统服务端采用了代理机制跨进程调用输入法应用端何为代理机制?,13,输入法服务框架中的代理机制,14,输入法接口之IInputMehtodSession,IInputMehtodSession接口简介作用:Sub-interfaceofIInputMethodwhichissafetogivetoclientapplications.,15,IInputMehtodSession及其使用,IInputMethodSessionWrapper,AbstractInputMethodService.AbstractInputMethodSessionImpl,IInputMethodSession.Stub,HandlerCaller.Callback,extends,implements,HandlerCaller,InputMethodSession,包含,InputMethodSession,调用,系统服务端,输入法应用端,InputMethodService.InputMethodSessionImpl,extends,16,输入法接口之IInputMethodClient,IInputMethodClient接口简介作用:作为输入法管理服务的客户端实现,用于标识自我并接收来自管理服务端的状态变化.,17,IInputMethodClient及其使用,InputMethodManager,InputMethodManagerService,IInputMethodClient.StubmClient,APP端,系统服务端,BINDER,调用服务接口时将mClient传到服务端如:mService.showSoftInput(mClient,flags,resultReceiver)服务端使用该client进行合法性判断及回调,18,输入法接口之IInputContext,IInputContext在框架中,它是输入法到应用的一个桥接器,十分重要!作用:使输入法可以在当前的编辑区进行编辑,并执行与应用的其他交互功能.,主要功能:1获取光标前后文本及大小写模式;2提交、删除文本;3选择文本;4锁定编辑;5发送键值及清除按键状态;6编辑框命令操作7通知当前输入法是否全屏的标志,19,IInputContext及其使用,IInputConnectionWrapper,APP,IInputContext.Stub,extends,HandlermH,InputConnectionmInputConnection,包含,InputConnection,输入法应用端,APP应用端,问题:这个是怎么调用的?,20,输入法接口之InputConnection,publicinterfaceInputConnection简介作用:,App,InputMethod,InputConnection作为从输入法到应用的一个通信通道,功能描述:1、文本编辑;2、编辑框命令执行;3、键值操作;4、其他信息传递和操作它的实例由客户端创建之后传递给输入法使用。,抽象类BaseInputConnection实现了该接口,实现了通用的系统导向部分的功能。InputConnection在输入法和客户端之间建立了一个连接,输入法可以使用该连接获取或发送信息给客户端。,21,22,应用到输入法间的连接,经过上一步的过程,做到了:1App端将InputConnection实例传给了输入法应用;2输入法应用将InputMethodSession的客户端接口IInputMethodSession传递给App应用;3输入法管理服务与app和输入法建立了连接;4App端调起了输入法。,23,桥接器另外一个方向的问题,App端,输入法应用端,?,InputConnection,24,输入法的窗口动画,android输入法与应用窗口的交互过程:生硬,改进:输入法窗口弹出时,慢慢挤开应用的窗口界面,使得整个弹出过程平滑流畅。,修改涉及的地方:SoftInputWindow、InputMethodService、View、ViewRoot、WindowManagerServicesDialog,25,输入法实现部件介绍,输入法实现部件该部件以服务的部件来提供,它是Service类的间接子类。,InputMethodService,服务框架,UI模块inputViewcandView全屏,classService,classAbstractInputMethodService,26,输入法实现部件介绍,InputMethodService成员简介1、服务相关:voidonCreate();voidonDestroy();voidonBindInput();voidonUnbindInput();voidonStartInput(EditorInfo,boolean);voidonStartInputView(EditorInfo,boolean);voidonFinishInput();voidonFinishInputView(boolean);voidonFinishCandidatesView(boolean),27,输入法实现部件介绍,InputMethodService成员简介2、获取状态相关:voidInputBindinggetCurrentInputBinding();/获得当前激活的输入法绑定信息voidInputConnectiongetCurrentInputConnection();/获得当前与输入法通信的通信通道publicbooleangetCurrentInputStarted();/获得当前输入法启动状态的标志。publicEditorInfogetCurrentInputEditorInfo();/获得当前输入法所服务的输入框的信息。publicLayoutInflatergetLayoutInflater();DialoggetWindow();/获取LayoutInflater和软键盘输入窗口句柄:,28,输入法实现部件介绍,InputMethodService成员简介3、切换及视图操作相关:voidswitchInputMethod(Stringid);voidonShowRequested(intflags);voiddismissSoftInput(intflags);4、响应键事件:booleanonKeyDown(intkeyCode,KeyEventevent);booleanonKeyMultiple(intkeyCode,intcount,KeyEventevent);booleanonKeyUp(intkeyCode,KeyEventevent);,29,输入法的启动:InputMethodManagerService,元素:客户端、输入法管理服务、具体输入法输入法管理服务是在启动Activity的过程中完成。,ZygoteInit.java启动系统、apk包-startSystemServer(),RuntimeInit.java-zygoteInit(),调用invokeStaticMain(),SystemServer.java-main()Inti1()Init2(),SystemServer.java-生成一个ServerThread并启动它run(),SystemServer.java-在run()中:创建并添加服务:StatusBarServiceInputMethodManagerService,30,输入法管理服务模块的启动,在创建InputMethodManagerService对象时,完成了输入法的查询和加载使用:,1、通过包管理器查询SERVICE_INTERFACE=“android.view.InputMethod”的包的接口,并获得它们的ResolveInfo信息保存到列表;2、检查所得的ResolveInfo对应的输入法服务是否具有BIND_INPUT_METHOD权限,有则将其加入已知的输入法相关列表中。,InputMethodManagerService构造函数调用:buildInputMethodListLocked(mMethodList,mMethodMap)/查询符合所给的Intent的服务(具体输入法服务);如果没有可用的输入法,则使能所有已知的输入法,31,输入法管理服务模块的启动,所有具体的输入法服务模块,要在AndroidManifest.xml文件种进行规范的配置。,1、通过包管理器查询SERVICE_INTERFACE=“android.view.InputMethod”的包的接口,并获得它们的ResolveInfo信息保存到列表;2、检查所得的ResolveInfo对应的输入法服务是否

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论