WEB开发网
开发学院手机开发Android 开发 Android事件处理:按键、触摸屏和滚动球的一些实现... 阅读

Android事件处理:按键、触摸屏和滚动球的一些实现细节

 2010-08-22 04:56:00 来源:WEB开发网   
核心提示: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, keycod

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;

}

readEvent调用hub->getEvent读了取事件,然后转换成JAVA的结构。

事件中转线程

在frameworks/base/services/java/com/android/server/KeyInputQueue.java 里创建了一个线程,它循环的读取事件,然后把事件放入事件队列里。

Java代码

Thread mThread = new Thread("InputDeviceReader") {

public void run() {

android.os.Process.setThreadPriority(

android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY);

try {

RawInputEvent ev = new RawInputEvent();

while (true) {

InputDevice di;

readEvent(ev);

send = preprocessEvent(di, ev);

addLocked(di, curTime, ev.flags, ..., me);

}

}

};

Thread mThread = new Thread("InputDeviceReader") {

public void run() {

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

Tags:Android 事件 处理

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