3dphotoshoot

annotate src/android/native_glue.c @ 1:7eb73ce46dd0

fucking jni man ... wtf
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 14 May 2015 23:46:56 +0300
parents src/android/android_native_app_glue.c@a4bf2687e406
children cf5964db7ff3
rev   line source
nuclear@0 1 /*
nuclear@0 2 * Copyright (C) 2010 The Android Open Source Project
nuclear@0 3 *
nuclear@0 4 * Licensed under the Apache License, Version 2.0 (the "License");
nuclear@0 5 * you may not use this file except in compliance with the License.
nuclear@0 6 * You may obtain a copy of the License at
nuclear@0 7 *
nuclear@0 8 * http://www.apache.org/licenses/LICENSE-2.0
nuclear@0 9 *
nuclear@0 10 * Unless required by applicable law or agreed to in writing, software
nuclear@0 11 * distributed under the License is distributed on an "AS IS" BASIS,
nuclear@0 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
nuclear@0 13 * See the License for the specific language governing permissions and
nuclear@0 14 * limitations under the License.
nuclear@0 15 *
nuclear@0 16 */
nuclear@0 17
nuclear@0 18 #include <jni.h>
nuclear@0 19
nuclear@0 20 #include <errno.h>
nuclear@0 21 #include <string.h>
nuclear@0 22 #include <unistd.h>
nuclear@0 23 #include <sys/resource.h>
nuclear@0 24
nuclear@1 25 #include "native_glue.h"
nuclear@0 26 #include <android/log.h>
nuclear@0 27
nuclear@1 28 #define ACTIVITY_NAME "com/mutantstargoat/photoshoot3d/MainActivity"
nuclear@1 29
nuclear@1 30 #define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, APP_NAME, __VA_ARGS__))
nuclear@1 31 #define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, APP_NAME, __VA_ARGS__))
nuclear@0 32
nuclear@0 33 /* For debug builds, always enable the debug traces in this library */
nuclear@0 34 #ifndef NDEBUG
nuclear@1 35 # define LOGV(...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, APP_NAME, __VA_ARGS__))
nuclear@0 36 #else
nuclear@0 37 # define LOGV(...) ((void)0)
nuclear@0 38 #endif
nuclear@0 39
nuclear@0 40 static void free_saved_state(struct android_app* android_app) {
nuclear@0 41 pthread_mutex_lock(&android_app->mutex);
nuclear@0 42 if (android_app->savedState != NULL) {
nuclear@0 43 free(android_app->savedState);
nuclear@0 44 android_app->savedState = NULL;
nuclear@0 45 android_app->savedStateSize = 0;
nuclear@0 46 }
nuclear@0 47 pthread_mutex_unlock(&android_app->mutex);
nuclear@0 48 }
nuclear@0 49
nuclear@0 50 int8_t android_app_read_cmd(struct android_app* android_app) {
nuclear@0 51 int8_t cmd;
nuclear@0 52 if (read(android_app->msgread, &cmd, sizeof(cmd)) == sizeof(cmd)) {
nuclear@0 53 switch (cmd) {
nuclear@0 54 case APP_CMD_SAVE_STATE:
nuclear@0 55 free_saved_state(android_app);
nuclear@0 56 break;
nuclear@0 57 }
nuclear@0 58 return cmd;
nuclear@0 59 } else {
nuclear@0 60 LOGE("No data on command pipe!");
nuclear@0 61 }
nuclear@0 62 return -1;
nuclear@0 63 }
nuclear@0 64
nuclear@0 65 static void print_cur_config(struct android_app* android_app) {
nuclear@0 66 char lang[2], country[2];
nuclear@0 67 AConfiguration_getLanguage(android_app->config, lang);
nuclear@0 68 AConfiguration_getCountry(android_app->config, country);
nuclear@0 69
nuclear@0 70 LOGV("Config: mcc=%d mnc=%d lang=%c%c cnt=%c%c orien=%d touch=%d dens=%d "
nuclear@0 71 "keys=%d nav=%d keysHid=%d navHid=%d sdk=%d size=%d long=%d "
nuclear@0 72 "modetype=%d modenight=%d",
nuclear@0 73 AConfiguration_getMcc(android_app->config),
nuclear@0 74 AConfiguration_getMnc(android_app->config),
nuclear@0 75 lang[0], lang[1], country[0], country[1],
nuclear@0 76 AConfiguration_getOrientation(android_app->config),
nuclear@0 77 AConfiguration_getTouchscreen(android_app->config),
nuclear@0 78 AConfiguration_getDensity(android_app->config),
nuclear@0 79 AConfiguration_getKeyboard(android_app->config),
nuclear@0 80 AConfiguration_getNavigation(android_app->config),
nuclear@0 81 AConfiguration_getKeysHidden(android_app->config),
nuclear@0 82 AConfiguration_getNavHidden(android_app->config),
nuclear@0 83 AConfiguration_getSdkVersion(android_app->config),
nuclear@0 84 AConfiguration_getScreenSize(android_app->config),
nuclear@0 85 AConfiguration_getScreenLong(android_app->config),
nuclear@0 86 AConfiguration_getUiModeType(android_app->config),
nuclear@0 87 AConfiguration_getUiModeNight(android_app->config));
nuclear@0 88 }
nuclear@0 89
nuclear@0 90 void android_app_pre_exec_cmd(struct android_app* android_app, int8_t cmd) {
nuclear@0 91 switch (cmd) {
nuclear@0 92 case APP_CMD_INPUT_CHANGED:
nuclear@0 93 LOGV("APP_CMD_INPUT_CHANGED\n");
nuclear@0 94 pthread_mutex_lock(&android_app->mutex);
nuclear@0 95 if (android_app->inputQueue != NULL) {
nuclear@0 96 AInputQueue_detachLooper(android_app->inputQueue);
nuclear@0 97 }
nuclear@0 98 android_app->inputQueue = android_app->pendingInputQueue;
nuclear@0 99 if (android_app->inputQueue != NULL) {
nuclear@0 100 LOGV("Attaching input queue to looper");
nuclear@0 101 AInputQueue_attachLooper(android_app->inputQueue,
nuclear@0 102 android_app->looper, LOOPER_ID_INPUT, NULL,
nuclear@0 103 &android_app->inputPollSource);
nuclear@0 104 }
nuclear@0 105 pthread_cond_broadcast(&android_app->cond);
nuclear@0 106 pthread_mutex_unlock(&android_app->mutex);
nuclear@0 107 break;
nuclear@0 108
nuclear@0 109 case APP_CMD_INIT_WINDOW:
nuclear@0 110 LOGV("APP_CMD_INIT_WINDOW\n");
nuclear@0 111 pthread_mutex_lock(&android_app->mutex);
nuclear@0 112 android_app->window = android_app->pendingWindow;
nuclear@0 113 pthread_cond_broadcast(&android_app->cond);
nuclear@0 114 pthread_mutex_unlock(&android_app->mutex);
nuclear@0 115 break;
nuclear@0 116
nuclear@0 117 case APP_CMD_TERM_WINDOW:
nuclear@0 118 LOGV("APP_CMD_TERM_WINDOW\n");
nuclear@0 119 pthread_cond_broadcast(&android_app->cond);
nuclear@0 120 break;
nuclear@0 121
nuclear@0 122 case APP_CMD_RESUME:
nuclear@0 123 case APP_CMD_START:
nuclear@0 124 case APP_CMD_PAUSE:
nuclear@0 125 case APP_CMD_STOP:
nuclear@0 126 LOGV("activityState=%d\n", cmd);
nuclear@0 127 pthread_mutex_lock(&android_app->mutex);
nuclear@0 128 android_app->activityState = cmd;
nuclear@0 129 pthread_cond_broadcast(&android_app->cond);
nuclear@0 130 pthread_mutex_unlock(&android_app->mutex);
nuclear@0 131 break;
nuclear@0 132
nuclear@0 133 case APP_CMD_CONFIG_CHANGED:
nuclear@0 134 LOGV("APP_CMD_CONFIG_CHANGED\n");
nuclear@0 135 AConfiguration_fromAssetManager(android_app->config,
nuclear@0 136 android_app->activity->assetManager);
nuclear@0 137 print_cur_config(android_app);
nuclear@0 138 break;
nuclear@0 139
nuclear@0 140 case APP_CMD_DESTROY:
nuclear@0 141 LOGV("APP_CMD_DESTROY\n");
nuclear@0 142 android_app->destroyRequested = 1;
nuclear@0 143 break;
nuclear@0 144 }
nuclear@0 145 }
nuclear@0 146
nuclear@0 147 void android_app_post_exec_cmd(struct android_app* android_app, int8_t cmd) {
nuclear@0 148 switch (cmd) {
nuclear@0 149 case APP_CMD_TERM_WINDOW:
nuclear@0 150 LOGV("APP_CMD_TERM_WINDOW\n");
nuclear@0 151 pthread_mutex_lock(&android_app->mutex);
nuclear@0 152 android_app->window = NULL;
nuclear@0 153 pthread_cond_broadcast(&android_app->cond);
nuclear@0 154 pthread_mutex_unlock(&android_app->mutex);
nuclear@0 155 break;
nuclear@0 156
nuclear@0 157 case APP_CMD_SAVE_STATE:
nuclear@0 158 LOGV("APP_CMD_SAVE_STATE\n");
nuclear@0 159 pthread_mutex_lock(&android_app->mutex);
nuclear@0 160 android_app->stateSaved = 1;
nuclear@0 161 pthread_cond_broadcast(&android_app->cond);
nuclear@0 162 pthread_mutex_unlock(&android_app->mutex);
nuclear@0 163 break;
nuclear@0 164
nuclear@0 165 case APP_CMD_RESUME:
nuclear@0 166 free_saved_state(android_app);
nuclear@0 167 break;
nuclear@0 168 }
nuclear@0 169 }
nuclear@0 170
nuclear@0 171 void app_dummy() {
nuclear@0 172
nuclear@0 173 }
nuclear@0 174
nuclear@0 175 static void android_app_destroy(struct android_app* android_app) {
nuclear@0 176 LOGV("android_app_destroy!");
nuclear@0 177 free_saved_state(android_app);
nuclear@0 178 pthread_mutex_lock(&android_app->mutex);
nuclear@0 179 if (android_app->inputQueue != NULL) {
nuclear@0 180 AInputQueue_detachLooper(android_app->inputQueue);
nuclear@0 181 }
nuclear@0 182 AConfiguration_delete(android_app->config);
nuclear@0 183 android_app->destroyed = 1;
nuclear@0 184 pthread_cond_broadcast(&android_app->cond);
nuclear@0 185 pthread_mutex_unlock(&android_app->mutex);
nuclear@0 186 // Can't touch android_app object after this.
nuclear@0 187 }
nuclear@0 188
nuclear@0 189 static void process_input(struct android_app* app, struct android_poll_source* source) {
nuclear@0 190 AInputEvent* event = NULL;
nuclear@0 191 while (AInputQueue_getEvent(app->inputQueue, &event) >= 0) {
nuclear@0 192 LOGV("New input event: type=%d\n", AInputEvent_getType(event));
nuclear@0 193 if (AInputQueue_preDispatchEvent(app->inputQueue, event)) {
nuclear@0 194 continue;
nuclear@0 195 }
nuclear@0 196 int32_t handled = 0;
nuclear@0 197 if (app->onInputEvent != NULL) handled = app->onInputEvent(app, event);
nuclear@0 198 AInputQueue_finishEvent(app->inputQueue, event, handled);
nuclear@0 199 }
nuclear@0 200 }
nuclear@0 201
nuclear@0 202 static void process_cmd(struct android_app* app, struct android_poll_source* source) {
nuclear@0 203 int8_t cmd = android_app_read_cmd(app);
nuclear@0 204 android_app_pre_exec_cmd(app, cmd);
nuclear@0 205 if (app->onAppCmd != NULL) app->onAppCmd(app, cmd);
nuclear@0 206 android_app_post_exec_cmd(app, cmd);
nuclear@0 207 }
nuclear@0 208
nuclear@0 209 static void* android_app_entry(void* param) {
nuclear@0 210 struct android_app* android_app = (struct android_app*)param;
nuclear@0 211
nuclear@0 212 android_app->config = AConfiguration_new();
nuclear@0 213 AConfiguration_fromAssetManager(android_app->config, android_app->activity->assetManager);
nuclear@0 214
nuclear@0 215 print_cur_config(android_app);
nuclear@0 216
nuclear@0 217 android_app->cmdPollSource.id = LOOPER_ID_MAIN;
nuclear@0 218 android_app->cmdPollSource.app = android_app;
nuclear@0 219 android_app->cmdPollSource.process = process_cmd;
nuclear@0 220 android_app->inputPollSource.id = LOOPER_ID_INPUT;
nuclear@0 221 android_app->inputPollSource.app = android_app;
nuclear@0 222 android_app->inputPollSource.process = process_input;
nuclear@0 223
nuclear@0 224 ALooper* looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS);
nuclear@0 225 ALooper_addFd(looper, android_app->msgread, LOOPER_ID_MAIN, ALOOPER_EVENT_INPUT, NULL,
nuclear@0 226 &android_app->cmdPollSource);
nuclear@0 227 android_app->looper = looper;
nuclear@0 228
nuclear@0 229 pthread_mutex_lock(&android_app->mutex);
nuclear@0 230 android_app->running = 1;
nuclear@0 231 pthread_cond_broadcast(&android_app->cond);
nuclear@0 232 pthread_mutex_unlock(&android_app->mutex);
nuclear@0 233
nuclear@0 234 android_main(android_app);
nuclear@0 235
nuclear@0 236 android_app_destroy(android_app);
nuclear@0 237 return NULL;
nuclear@0 238 }
nuclear@0 239
nuclear@0 240 // --------------------------------------------------------------------
nuclear@0 241 // Native activity interaction (called from main thread)
nuclear@0 242 // --------------------------------------------------------------------
nuclear@0 243
nuclear@0 244 static struct android_app* android_app_create(ANativeActivity* activity,
nuclear@0 245 void* savedState, size_t savedStateSize) {
nuclear@1 246 JNIEnv *jni = activity->env;
nuclear@1 247 struct android_app* android_app = malloc(sizeof(struct android_app));
nuclear@0 248 memset(android_app, 0, sizeof(struct android_app));
nuclear@0 249 android_app->activity = activity;
nuclear@0 250
nuclear@1 251 {
nuclear@1 252 jclass foo = (*jni)->FindClass(jni, "java/lang/String");
nuclear@1 253 if(!foo) {
nuclear@1 254 LOGE("String class not found!!!!!!\n");
nuclear@1 255 } else {
nuclear@1 256 LOGE("Found String class!!!!!!\n");
nuclear@1 257 }
nuclear@1 258 }
nuclear@1 259
nuclear@1 260 if(!(android_app->activity_class = (*jni)->FindClass(jni, ACTIVITY_NAME))) {
nuclear@1 261 LOGE("could not find activity: " ACTIVITY_NAME);
nuclear@1 262 return 0;
nuclear@1 263 }
nuclear@1 264
nuclear@0 265 pthread_mutex_init(&android_app->mutex, NULL);
nuclear@0 266 pthread_cond_init(&android_app->cond, NULL);
nuclear@0 267
nuclear@0 268 if (savedState != NULL) {
nuclear@0 269 android_app->savedState = malloc(savedStateSize);
nuclear@0 270 android_app->savedStateSize = savedStateSize;
nuclear@0 271 memcpy(android_app->savedState, savedState, savedStateSize);
nuclear@0 272 }
nuclear@0 273
nuclear@0 274 int msgpipe[2];
nuclear@0 275 if (pipe(msgpipe)) {
nuclear@0 276 LOGE("could not create pipe: %s", strerror(errno));
nuclear@0 277 return NULL;
nuclear@0 278 }
nuclear@0 279 android_app->msgread = msgpipe[0];
nuclear@0 280 android_app->msgwrite = msgpipe[1];
nuclear@0 281
nuclear@1 282 pthread_attr_t attr;
nuclear@0 283 pthread_attr_init(&attr);
nuclear@0 284 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
nuclear@0 285 pthread_create(&android_app->thread, &attr, android_app_entry, android_app);
nuclear@0 286
nuclear@0 287 // Wait for thread to start.
nuclear@0 288 pthread_mutex_lock(&android_app->mutex);
nuclear@0 289 while (!android_app->running) {
nuclear@0 290 pthread_cond_wait(&android_app->cond, &android_app->mutex);
nuclear@0 291 }
nuclear@0 292 pthread_mutex_unlock(&android_app->mutex);
nuclear@0 293
nuclear@0 294 return android_app;
nuclear@0 295 }
nuclear@0 296
nuclear@0 297 static void android_app_write_cmd(struct android_app* android_app, int8_t cmd) {
nuclear@0 298 if (write(android_app->msgwrite, &cmd, sizeof(cmd)) != sizeof(cmd)) {
nuclear@0 299 LOGE("Failure writing android_app cmd: %s\n", strerror(errno));
nuclear@0 300 }
nuclear@0 301 }
nuclear@0 302
nuclear@0 303 static void android_app_set_input(struct android_app* android_app, AInputQueue* inputQueue) {
nuclear@0 304 pthread_mutex_lock(&android_app->mutex);
nuclear@0 305 android_app->pendingInputQueue = inputQueue;
nuclear@0 306 android_app_write_cmd(android_app, APP_CMD_INPUT_CHANGED);
nuclear@0 307 while (android_app->inputQueue != android_app->pendingInputQueue) {
nuclear@0 308 pthread_cond_wait(&android_app->cond, &android_app->mutex);
nuclear@0 309 }
nuclear@0 310 pthread_mutex_unlock(&android_app->mutex);
nuclear@0 311 }
nuclear@0 312
nuclear@0 313 static void android_app_set_window(struct android_app* android_app, ANativeWindow* window) {
nuclear@0 314 pthread_mutex_lock(&android_app->mutex);
nuclear@0 315 if (android_app->pendingWindow != NULL) {
nuclear@0 316 android_app_write_cmd(android_app, APP_CMD_TERM_WINDOW);
nuclear@0 317 }
nuclear@0 318 android_app->pendingWindow = window;
nuclear@0 319 if (window != NULL) {
nuclear@0 320 android_app_write_cmd(android_app, APP_CMD_INIT_WINDOW);
nuclear@0 321 }
nuclear@0 322 while (android_app->window != android_app->pendingWindow) {
nuclear@0 323 pthread_cond_wait(&android_app->cond, &android_app->mutex);
nuclear@0 324 }
nuclear@0 325 pthread_mutex_unlock(&android_app->mutex);
nuclear@0 326 }
nuclear@0 327
nuclear@0 328 static void android_app_set_activity_state(struct android_app* android_app, int8_t cmd) {
nuclear@0 329 pthread_mutex_lock(&android_app->mutex);
nuclear@0 330 android_app_write_cmd(android_app, cmd);
nuclear@0 331 while (android_app->activityState != cmd) {
nuclear@0 332 pthread_cond_wait(&android_app->cond, &android_app->mutex);
nuclear@0 333 }
nuclear@0 334 pthread_mutex_unlock(&android_app->mutex);
nuclear@0 335 }
nuclear@0 336
nuclear@0 337 static void android_app_free(struct android_app* android_app) {
nuclear@0 338 pthread_mutex_lock(&android_app->mutex);
nuclear@0 339 android_app_write_cmd(android_app, APP_CMD_DESTROY);
nuclear@0 340 while (!android_app->destroyed) {
nuclear@0 341 pthread_cond_wait(&android_app->cond, &android_app->mutex);
nuclear@0 342 }
nuclear@0 343 pthread_mutex_unlock(&android_app->mutex);
nuclear@0 344
nuclear@0 345 close(android_app->msgread);
nuclear@0 346 close(android_app->msgwrite);
nuclear@0 347 pthread_cond_destroy(&android_app->cond);
nuclear@0 348 pthread_mutex_destroy(&android_app->mutex);
nuclear@0 349 free(android_app);
nuclear@0 350 }
nuclear@0 351
nuclear@0 352 static void onDestroy(ANativeActivity* activity) {
nuclear@0 353 LOGV("Destroy: %p\n", activity);
nuclear@0 354 android_app_free((struct android_app*)activity->instance);
nuclear@0 355 }
nuclear@0 356
nuclear@0 357 static void onStart(ANativeActivity* activity) {
nuclear@0 358 LOGV("Start: %p\n", activity);
nuclear@0 359 android_app_set_activity_state((struct android_app*)activity->instance, APP_CMD_START);
nuclear@0 360 }
nuclear@0 361
nuclear@0 362 static void onResume(ANativeActivity* activity) {
nuclear@0 363 LOGV("Resume: %p\n", activity);
nuclear@0 364 android_app_set_activity_state((struct android_app*)activity->instance, APP_CMD_RESUME);
nuclear@0 365 }
nuclear@0 366
nuclear@0 367 static void* onSaveInstanceState(ANativeActivity* activity, size_t* outLen) {
nuclear@0 368 struct android_app* android_app = (struct android_app*)activity->instance;
nuclear@0 369 void* savedState = NULL;
nuclear@0 370
nuclear@0 371 LOGV("SaveInstanceState: %p\n", activity);
nuclear@0 372 pthread_mutex_lock(&android_app->mutex);
nuclear@0 373 android_app->stateSaved = 0;
nuclear@0 374 android_app_write_cmd(android_app, APP_CMD_SAVE_STATE);
nuclear@0 375 while (!android_app->stateSaved) {
nuclear@0 376 pthread_cond_wait(&android_app->cond, &android_app->mutex);
nuclear@0 377 }
nuclear@0 378
nuclear@0 379 if (android_app->savedState != NULL) {
nuclear@0 380 savedState = android_app->savedState;
nuclear@0 381 *outLen = android_app->savedStateSize;
nuclear@0 382 android_app->savedState = NULL;
nuclear@0 383 android_app->savedStateSize = 0;
nuclear@0 384 }
nuclear@0 385
nuclear@0 386 pthread_mutex_unlock(&android_app->mutex);
nuclear@0 387
nuclear@0 388 return savedState;
nuclear@0 389 }
nuclear@0 390
nuclear@0 391 static void onPause(ANativeActivity* activity) {
nuclear@0 392 LOGV("Pause: %p\n", activity);
nuclear@0 393 android_app_set_activity_state((struct android_app*)activity->instance, APP_CMD_PAUSE);
nuclear@0 394 }
nuclear@0 395
nuclear@0 396 static void onStop(ANativeActivity* activity) {
nuclear@0 397 LOGV("Stop: %p\n", activity);
nuclear@0 398 android_app_set_activity_state((struct android_app*)activity->instance, APP_CMD_STOP);
nuclear@0 399 }
nuclear@0 400
nuclear@0 401 static void onConfigurationChanged(ANativeActivity* activity) {
nuclear@0 402 struct android_app* android_app = (struct android_app*)activity->instance;
nuclear@0 403 LOGV("ConfigurationChanged: %p\n", activity);
nuclear@0 404 android_app_write_cmd(android_app, APP_CMD_CONFIG_CHANGED);
nuclear@0 405 }
nuclear@0 406
nuclear@0 407 static void onLowMemory(ANativeActivity* activity) {
nuclear@0 408 struct android_app* android_app = (struct android_app*)activity->instance;
nuclear@0 409 LOGV("LowMemory: %p\n", activity);
nuclear@0 410 android_app_write_cmd(android_app, APP_CMD_LOW_MEMORY);
nuclear@0 411 }
nuclear@0 412
nuclear@0 413 static void onWindowFocusChanged(ANativeActivity* activity, int focused) {
nuclear@0 414 LOGV("WindowFocusChanged: %p -- %d\n", activity, focused);
nuclear@0 415 android_app_write_cmd((struct android_app*)activity->instance,
nuclear@0 416 focused ? APP_CMD_GAINED_FOCUS : APP_CMD_LOST_FOCUS);
nuclear@0 417 }
nuclear@0 418
nuclear@0 419 static void onNativeWindowCreated(ANativeActivity* activity, ANativeWindow* window) {
nuclear@0 420 LOGV("NativeWindowCreated: %p -- %p\n", activity, window);
nuclear@0 421 android_app_set_window((struct android_app*)activity->instance, window);
nuclear@0 422 }
nuclear@0 423
nuclear@0 424 static void onNativeWindowDestroyed(ANativeActivity* activity, ANativeWindow* window) {
nuclear@0 425 LOGV("NativeWindowDestroyed: %p -- %p\n", activity, window);
nuclear@0 426 android_app_set_window((struct android_app*)activity->instance, NULL);
nuclear@0 427 }
nuclear@0 428
nuclear@0 429 static void onInputQueueCreated(ANativeActivity* activity, AInputQueue* queue) {
nuclear@0 430 LOGV("InputQueueCreated: %p -- %p\n", activity, queue);
nuclear@0 431 android_app_set_input((struct android_app*)activity->instance, queue);
nuclear@0 432 }
nuclear@0 433
nuclear@0 434 static void onInputQueueDestroyed(ANativeActivity* activity, AInputQueue* queue) {
nuclear@0 435 LOGV("InputQueueDestroyed: %p -- %p\n", activity, queue);
nuclear@0 436 android_app_set_input((struct android_app*)activity->instance, NULL);
nuclear@0 437 }
nuclear@0 438
nuclear@0 439 void ANativeActivity_onCreate(ANativeActivity* activity,
nuclear@0 440 void* savedState, size_t savedStateSize) {
nuclear@0 441 LOGV("Creating: %p\n", activity);
nuclear@0 442 activity->callbacks->onDestroy = onDestroy;
nuclear@0 443 activity->callbacks->onStart = onStart;
nuclear@0 444 activity->callbacks->onResume = onResume;
nuclear@0 445 activity->callbacks->onSaveInstanceState = onSaveInstanceState;
nuclear@0 446 activity->callbacks->onPause = onPause;
nuclear@0 447 activity->callbacks->onStop = onStop;
nuclear@0 448 activity->callbacks->onConfigurationChanged = onConfigurationChanged;
nuclear@0 449 activity->callbacks->onLowMemory = onLowMemory;
nuclear@0 450 activity->callbacks->onWindowFocusChanged = onWindowFocusChanged;
nuclear@0 451 activity->callbacks->onNativeWindowCreated = onNativeWindowCreated;
nuclear@0 452 activity->callbacks->onNativeWindowDestroyed = onNativeWindowDestroyed;
nuclear@0 453 activity->callbacks->onInputQueueCreated = onInputQueueCreated;
nuclear@0 454 activity->callbacks->onInputQueueDestroyed = onInputQueueDestroyed;
nuclear@0 455
nuclear@0 456 activity->instance = android_app_create(activity, savedState, savedStateSize);
nuclear@0 457 }