From 785f309512f7632b74ae23bc8edd97ff417eff6e Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 17 Nov 2014 11:09:07 -0800 Subject: [PATCH] use slightly more advanced event handling in native glue main --- gvr-interface/src/main.cpp | 42 ++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/gvr-interface/src/main.cpp b/gvr-interface/src/main.cpp index 2d3db0d843..775b23cfca 100644 --- a/gvr-interface/src/main.cpp +++ b/gvr-interface/src/main.cpp @@ -12,12 +12,46 @@ #include #include -#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; + } + } + } } \ No newline at end of file