设为首页 加入收藏

TOP

Android NDK处理用户交互事件(三)
2015-03-06 01:05:18 来源: 作者: 【 】 浏览:94
Tags:Android NDK 处理 用户 交互 事件
_init_display(engine);
? ? ? ? ? ? }
? ? ? ? ? ? break;
? ? ? ? case APP_CMD_TERM_WINDOW:
? ? ? ? ? ? // The window is being hidden or closed, clean it up.
? ? ? ? ? ? engine_term_display(engine);
? ? ? ? ? ? break;
? ? ? ? case APP_CMD_GAINED_FOCUS:


? ? ? ? ? ? break;
? ? ? ? case APP_CMD_LOST_FOCUS:


? ? ? ? ? ? break;
? ? }
}


/**
?* This is the main entry point of a native application that is using
?* android_native_app_glue.? It runs in its own thread, with its own
?* event loop for receiving input events and doing other things.
?*/
void android_main(struct android_app* state) {
? ? struct engine engine;


? ? // Make sure glue isn't stripped.
? ? app_dummy();


? ? memset(&engine, 0, sizeof(engine));
? ? state->userData = &engine;
? ? state->onAppCmd = engine_handle_cmd;
? ? state->onInputEvent = engine_handle_input;
? ? engine.app = state;


? ? // Prepare to monitor accelerometer
? ? engine.sensorManager = ASensorManager_getInstance();
? ? engine.accelerometerSensor = ASensorManager_getDefaultSensor(engine.sensorManager,
? ? ? ? ? ? ASENSOR_TYPE_ACCELEROMETER);


? ? if (state->savedState != NULL) {
? ? ? ? // We are starting with a previous saved state; restore from it.
? ? ? ? engine.state = *(struct saved_state*)state->savedState;
? ? }


? ? int ident, events;
? ? struct android_poll_source* source;


? ? while (true)
? ? {
? ? ? ? while ((ident = ALooper_pollAll(0, NULL, &events, (void**)&source)) >= 0)
? ? ? ? {
? ? ? ? ? ? if (source != NULL)
? ? ? ? ? ? ? ? source->process(state, source);


? ? ? ? ? ? if (state->destroyRequested != 0)
? ? ? ? ? ? ? ? return;
? ? ? ? }


? ? ? ? engine_draw_frame(&engine);
? ? }


}


效果如图所示。



首页 上一页 1 2 3 下一页 尾页 3/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇二叉树遍历的非递归实现 下一篇Java文件获取路径方式

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: