接下来,我们继续分析PhoneWindow类的成员函数superDispatchKeyEvent的实现,以便可以了解键盘事件在Activity组件窗口的分发过程。

  Step 8. PhoneWindow.superDispatchKeyEvent

  [java] view plaincopyprint?

  public class PhoneWindow extends Window implements MenuBuilder.Callback {

  ......

  // This is the top-level view of the window, containing the window decor.

  private DecorView mDecor;

  ......

  @Override

  public boolean superDispatchKeyEvent(KeyEvent event) {

  return mDecor.superDispatchKeyEvent(event);

  }

  ......

  }

  public class PhoneWindow extends Window implements MenuBuilder.Callback {

  ......

  // This is the top-level view of the window, containing the window decor.

  private DecorView mDecor;

  ......

  @Override

  public boolean superDispatchKeyEvent(KeyEvent event) {

  return mDecor.superDispatchKeyEvent(event);

  }

  ......

  }

  这个函数定义在文件frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindow.java中。

  PhoneWindow类的成员变量mDecor描述的是当前正在处理的Activity组件窗口的顶层视图,PhoneWindow类的成员函数superDispatchKeyEvent通过调用它所指向的一个DecorView对象的成员函数superDispatchKeyEvent来处理参数event所描述的键盘事件。

  Step 9. DecorView.superDispatchKeyEvent

  [java] view plaincopyprint?

  public class PhoneWindow extends Window implements MenuBuilder.Callback {

  ......

  private final class DecorView extends FrameLayout implements RootViewSurfaceTaker {

  ......

  public boolean superDispatchKeyEvent(KeyEvent event) {

  return super.dispatchKeyEvent(event);

  }

  ......

  }

  ......

  }

  public class PhoneWindow extends Window implements MenuBuilder.Callback {

  ......

  private final class DecorView extends FrameLayout implements RootViewSurfaceTaker {

  ......

  public boolean superDispatchKeyEvent(KeyEvent event) {

  return super.dispatchKeyEvent(event);

  }

  ......

  }

  ......

  }

  这个函数定义在文件frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindow.java中。

  DecorView类的成员函数superDispatchKeyEvent的实现很简单,它只是调用父类ViewGroup的成员函数dispatchKeyEvent来处理参数event所描述的键盘事件。