InputMethod Framework

引用注明出处,出错见谅!http://write.blog.csdn.net/postedit/6664806

研究了一下输入法:

frameworks/base/services/java/com/android/server/SystemServer.java

系统启动过程中建立InputMethodManager服务,并添加到ServiceManger维护的列表中:

try {
                Slog.i(TAG, "Input Method Service");
                imm = new InputMethodManagerService(context, statusBar);
                ServiceManager.addService(Context.INPUT_METHOD_SERVICE, imm);
            } catch (Throwable e) {
                Slog.e(TAG, "Failure starting Input Manager Service", e);
            }

}

frameworks/base/services/java/com/android/server/InputMethodManagerService.java

获取系统已经安装的所有输入法:

List<ResolveInfo> services = pm.queryIntentServices(
                new Intent(InputMethod.SERVICE_INTERFACE),
                PackageManager.GET_META_DATA);

然后将系统所有输入法添加到InutMethodManagerService列表中。

systemReady , Input Start.

public void systemReady() {
        synchronized (mMethodMap) {
            if (!mSystemReady) {
                mSystemReady = true;
                try {
                    startInputInnerLocked();
                } catch (RuntimeException e) {
                    Slog.w(TAG, "Unexpected exception", e);
                }
            }
        }
    }

开机启动输入法完成。

切换window:

frameworks/base/core/java/android/view/ViewRoot.java

ViewRoot 接收来自WindowManagerService 的焦点变化消息:WINDOW_FOCUS_CHANGED, 启动输入法:

                if (hasWindowFocus) {
                    if (imm != null && mLastWasImTarget) {
                        imm.onWindowFocus(mView, mView.findFocus(),
                                mWindowAttributes.softInputMode,
                                !mHasHadWindowFocus, mWindowAttributes.flags);
                    }
                    // Clear the forward bit.  We can just do this directly, since
                    // the window manager doesn't care about it.
                    mWindowAttributes.softInputMode &=
                            ~WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION;
                    ((WindowManager.LayoutParams)mView.getLayoutParams())
                            .softInputMode &=
                                ~WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION;
                    mHasHadWindowFocus = true;
                }

客户端进程的InputMethodManager发起启动输入法的过程:

frameworks/base/core/java/android/view/inputmethod/InputMethodManager.java

首先获取服务的对象的信息:

FocusInLocked() 获取当前服务对象:

void focusInLocked(View view) {
        if (DEBUG) Log.v(TAG, "focusIn: " + view);
         
        if (mCurRootView != view.getRootView()) {
            // This is a request from a window that isn't in the window with
            // IME focus, so ignore it.
            if (DEBUG) Log.v(TAG, "Not IME target window, ignoring");
            return;
        }   
            
        mNextServedView = view;
        scheduleCheckFocusLocked(view);
    }




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值