开发学院手机开发Android 开发 Android 事件处理流程 阅读

Android 事件处理流程

 2010-03-19 07:14:00 来源:WEB开发网   
核心提示:switch (ev.classType)case RawInputEvent.CLASS_KEYBOARD:...dispatchKey((KeyEvent)ev.event, 0, 0);mQueue.recycleEvent(ev);break;case RawInputEvent.CLASS_TOUCHSCRE

switch (ev.classType)

case RawInputEvent.CLASS_KEYBOARD:

...

dispatchKey((KeyEvent)ev.event, 0, 0);

mQueue.recycleEvent(ev);

break;

case RawInputEvent.CLASS_TOUCHSCREEN:

//Log.i(TAG, "Read next event " + ev);

dispatchPointer(ev, (MotionEvent)ev.event, 0, 0);

break;

===============================================================

KeyInputQueue.java (frameworksaseservicesjavacomandroidserver):

的线程 Thread mThread = new Thread("InputDeviceReader") 本地调用:

readEvent(ev);读取按键。readEvent 调用的是文件:

com_android_server_KeyInputQueue.cpp (frameworksaseservicesjni)中的函数:

static jboolean android_server_KeyInputQueue_readEvent(JNIEnv* env, jobject clazz,

jobject event)

android_server_KeyInputQueue_readEvent中有:

hub = new EventHub;

bool res = hub->getEvent(&deviceId, &type, &scancode, &keycode,

&flags, &value, &when);

hub->getEvent 调用的是

EventHub.cpp (frameworksaselibsui) 文件中的函数:

bool EventHub::getEvent(int32_t* outDeviceId, int32_t* outType,

int32_t* outScancode, int32_t* outKeycode, uint32_t *outFlags,

int32_t* outValue, nsecs_t* outWhen)

读取按键。

class RefBase::weakref_impl : public RefBase::weakref_type

在系统启动后,android 会通过

static const char *device_path = "/dev/input";

bool EventHub::openPlatformInput(void)

res = scan_dir(device_path);

通过下面的函数打开设备。

int EventHub::open_device(const char *deviceName)

{

...

fd = open(deviceName, O_RDWR);

...

mFDs[mFDCount].fd = fd;

mFDs[mFDCount].events = POLLIN;

...

ioctl(mFDs[mFDCount].fd, EVIOCGNAME(sizeof(devname)-1), devname);

上一页  1 2 3 4 5 6 7 8  下一页

Tags:Android 事件 处理

编辑录入:coldstar [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接