zoukankan      html  css  js  c++  java
  • KeyBord事件从Activtiy层往下分发详细过程代码示例

    step1:调用Activity成员函数dispatchKeyEvent

    public boolean dispatchKeyEvent(KeyEvent event) {

        // Let action bars open menus in response to the menu key prioritized over
    // the window handling it
    if (event.getKeyCode() == KeyEvent.KEYCODE_MENU &&
    mActionBar != null && mActionBar.onMenuKeyEvent(event)) {
    return true;
    }
    Window win = getWindow();
    if (win.superDispatchKeyEvent(event)) {
    return true;
    }
    View decor = mDecor;
    if (decor == null) decor = win.getDecorView();
    return event.dispatch(this, decor != null
    ? decor.getKeyDispatcherState() : null, this);
    }

    step2:Activity成员函数dispatchKeyEvent中调用phoneWindow的成员函数superDispatchKeyEvent
        Window win = getWindow();
    if (win.superDispatchKeyEvent(event)) {
    return true;
    }

    setp3:在PhoneWindow的
    superDispatchKeyEvent函数中调用DecorView的成员函数uperDispatchKeyEvent
        public boolean superDispatchKeyEvent(KeyEvent event) {
            return mDecor.superDispatchKeyEvent(event);
        }

    step4:ViewGroup的成员函数DispatchKeyEvent
    private final class DecorView extends FrameLayout implements RootViewSurfaceTaker {
    ...    
    public DecorView(Context context, int featureId) {
    super(context);
    mFeatureId = featureId;
    }
    @Override
    public boolean superDispatchKeyEvent(KeyEvent event) {
               if (super.dispatchKeyEvent(event)) {
                   return true;
               }
    ...
    }

    step5:通过mFocused的包含关系实现隧道式分发
    public boolean dispatchKeyEvent(KeyEvent event) {
    if (mInputEventConsistencyVerifier != null) {
    mInputEventConsistencyVerifier.onKeyEvent(event, 1);
    }

    if ((mPrivateFlags & (PFLAG_FOCUSED | PFLAG_HAS_BOUNDS))
    == (PFLAG_FOCUSED | PFLAG_HAS_BOUNDS)) {
    if (super.dispatchKeyEvent(event)) {
    return true;
    }
    } else if (mFocused != null && (mFocused.mPrivateFlags & PFLAG_HAS_BOUNDS)
    == PFLAG_HAS_BOUNDS) {
    if (mFocused.dispatchKeyEvent(event)) {
    return true;
    }
    }

    if (mInputEventConsistencyVerifier != null) {
    mInputEventConsistencyVerifier.onUnhandledEvent(event, 1);
    }
    return false;
    }
     
     








  • 相关阅读:
    centos7 安装mysql
    基于flask+requests 个人博客
    python csv、json、pickle数据持久化
    Python之容器、迭代器、生成器
    AJAX常用方法详解
    Python之format详解
    Flask使用MySql数据库
    git 公共服务器
    pci 记录
    检查ept
  • 原文地址:https://www.cnblogs.com/lianghe01/p/5712791.html
Copyright © 2011-2022 走看看