use slightly more advanced event handling in native glue main

This commit is contained in:
Stephen Birarda 2014-11-17 11:09:07 -08:00
parent 05cab9a3ba
commit 785f309512

View file

@ -12,12 +12,46 @@
#include <android_native_app_glue.h>
#include <android/log.h>
#define APPNAME "Interface"
// usage of log
#define APP_NAME "Interface"
// usage of log
#define LOGINFO(x...) __android_log_print(ANDROID_LOG_INFO, APP_NAME, x)
// handle commands
static void custom_handle_cmd(struct android_app* app, int32_t cmd) {
switch(cmd) {
case APP_CMD_INIT_WINDOW:
LOGINFO("GearVR Interface, reporting for duty");
break;
}
}
void android_main(struct android_app* state) {
// Make sure glue isn't stripped.
app_dummy();
int events;
__android_log_print(ANDROID_LOG_INFO, APPNAME, "GearVR Interface, reporting for duty");
ANativeActivity_finish(state->activity);
// set up so when commands happen we call our custom handler
state->onAppCmd = custom_handle_cmd;
while (1) {
struct android_poll_source* source;
// we block for events
while (ALooper_pollAll(-1, NULL, &events, (void**)&source) >= 0) {
// Process this event.
if (source != NULL) {
source->process(state, source);
}
// Check if we are exiting.
if (state->destroyRequested != 0) {
LOGINFO("We are exiting");
return;
}
}
}
}