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

Android 事件处理流程

 2010-03-19 07:14:00 来源:WEB开发网   
核心提示:代码static jbooleanandroid_server_KeyInputQueue_readEvent(JNIEnv* env, jobject clazz,jobject event){gLock.lock();sp hub = gHub;if (hub == NULL) {hub = new EventHu

代码

static jboolean

android_server_KeyInputQueue_readEvent(JNIEnv* env, jobject clazz,

jobject event)

{

gLock.lock();

sp hub = gHub;

if (hub == NULL) {

hub = new EventHub;

gHub = hub;

}

gLock.unlock();

int32_t deviceId;

int32_t type;

int32_t scancode, keycode;

uint32_t flags;

int32_t value;

nsecs_t when;

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

&flags, &value, &when);

env->SetIntField(event, gInputOffsets.mDeviceId, (jint)deviceId);

env->SetIntField(event, gInputOffsets.mType, (jint)type);

env->SetIntField(event, gInputOffsets.mScancode, (jint)scancode);

env->SetIntField(event, gInputOffsets.mKeycode, (jint)keycode);

env->SetIntField(event, gInputOffsets.mFlags, (jint)flags);

env->SetIntField(event, gInputOffsets.mValue, value);

env->SetLongField(event, gInputOffsets.mWhen,

(jlong)(nanoseconds_to_milliseconds(when)));

return res;

}

输入事件分发线程

在frameworks/base/services/java/com/android/server/WindowManagerService.java里创建了一个输入事件分发线程,它负责把事件分发到相应的窗口上去。

Java代码

mQueue.getEvent

dispatchKey/dispatchPointer/dispatchTrackball

mQueue.getEvent

dispatchKey/dispatchPointer/dispatchTrackball

按键,触摸屏流程分析

按键触摸屏流程分析:

WindowManagerService类的构造函数

WindowManagerService()

mQueue = new KeyQ();

因为 WindowManagerService.java (frameworksaseservicesjavacomandroidserver)中有:

private class KeyQ extends KeyInputQueue

KeyQ 是抽象类 KeyInputQueue 的实现,所以 new KeyQ类的时候实际上在 KeyInputQueue 类中创建了

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

Tags:Android 事件 处理

编辑录入:coldstar [复制链接] [打 印]
赞助商链接