void SensorCollector::DisableSensors() { bool success = true; int result = ASensorEventQueue_disableSensor(sensorQueue,accelSensor); if (result < 0) { LOGE("Error disabling accelerometer"); success = false; } result = ASensorEventQueue_disableSensor(sensorQueue,gyroSensor); if (result < 0) { LOGE("Error disabling gyro sensor"); success = false; } result = ASensorEventQueue_disableSensor(sensorQueue,magnetoSensor); if (result < 0) { LOGE("Error disabling magnetic sensor"); success = false; } if (success) LOGI(LOGTAG_SENSOR,"All sensors disabled successfully!"); }
void Engine::SuspendSensors() { // When our app loses focus, we stop monitoring the accelerometer. // This is to avoid consuming battery while not being used. if (accelerometer_sensor_ != NULL) { ASensorEventQueue_disableSensor(sensor_event_queue_, accelerometer_sensor_); } }
void SensorManager::Suspend() { // When the app loses focus, stop monitoring the accelerometer. // This is to avoid consuming battery while not being used. if (accelerometerSensor_ != NULL) { ASensorEventQueue_disableSensor(sensorEventQueue_, accelerometerSensor_); } }
void CSensorAndroidBuiltIn::closePort() { if (m_pSensor && m_pSensorEventQueue) { ASensorEventQueue_disableSensor(m_pSensorEventQueue, m_pSensor); } if (m_pSensorManager && m_pSensorEventQueue) { ASensorManager_destroyEventQueue(m_pSensorManager, m_pSensorEventQueue); } strcpy(m_strVendor, ""); strcpy(m_strSensor, ""); m_pSensorManager = NULL; m_pSensor = NULL; m_pSensorEventQueue = NULL; m_pLooper = NULL; m_fResolution = 0.0f; m_minDelayMsec = 0; memset(m_xyz, 0x00, sizeof(float) * 3); memset(m_strSensor, 0x00, _MAX_PATH); memset(m_strVendor, 0x00, _MAX_PATH); setType(); setPort(); }
void SensorImpl::setEnabled(bool enabled) { if (enabled) ASensorEventQueue_enableSensor(sensorEventQueue, m_sensor); else ASensorEventQueue_disableSensor(sensorEventQueue, m_sensor); }
static void setDisableAccelerometer(){ if(sensors.accelerometerSensor){ ASensorEventQueue_disableSensor( sensors.sensorEventQueue, sensors.accelerometerSensor); } }
/** * 繝。繧、繝ウ繧ウ繝槭Φ繝峨�蜃ヲ逅� */ static void engine_handle_cmd(struct android_app* app, int32_t cmd) { struct engine* engine = (struct engine*) app->userData; switch (cmd) { case APP_CMD_SAVE_STATE: engine->app->savedState = malloc(sizeof(struct saved_state)); *((struct saved_state*) engine->app->savedState) = engine->state; engine->app->savedStateSize = sizeof(struct saved_state); break; case APP_CMD_INIT_WINDOW: if (engine->app->window != NULL) { engine_init_display(engine); engine_draw_frame(engine); } break; case APP_CMD_TERM_WINDOW: engine_term_display(engine); break; case APP_CMD_GAINED_FOCUS: if (engine->accelerometerSensor != NULL) { ASensorEventQueue_enableSensor(engine->sensorEventQueue, engine->accelerometerSensor); ASensorEventQueue_setEventRate(engine->sensorEventQueue, engine->accelerometerSensor, (1000L / 60) * 1000); } break; case APP_CMD_LOST_FOCUS: if (engine->accelerometerSensor != NULL) { ASensorEventQueue_disableSensor(engine->sensorEventQueue, engine->accelerometerSensor); } engine->animating = 0; engine_draw_frame(engine); break; } }
static TCGvoid EngineHandleCmd(struct android_app* app, TCGint cmd) { struct Engine* engine = (struct Engine*)app->userData; switch (cmd) { case APP_CMD_SAVE_STATE: // The system has asked us to save our current state. Do so. engine->app->savedState = TCG_MALLOC(sizeof(struct SavedState), eTCG_MAIN); *((struct SavedState*)engine->app->savedState) = engine->state; engine->app->savedStateSize = sizeof(struct SavedState); break; case APP_CMD_INIT_WINDOW: //窗口初始化 _Lock.Lock(); g_bWindowMax = TCG_TRUE; _Lock.UnLock(); if (engine->app->window != NULL) { g_WindowType = engine->app->window; } break; case APP_CMD_TERM_WINDOW: //窗口销毁 _Lock.Lock(); g_bWindowMax = TCG_FALSE; _Lock.UnLock(); break; case APP_CMD_GAINED_FOCUS: // When our app gains focus, we start monitoring the accelerometer. if (engine->accelerometerSensor != NULL) { ASensorEventQueue_enableSensor(engine->sensorEventQueue, engine->accelerometerSensor); // We'd like to get 60 events per second (in us). ASensorEventQueue_setEventRate(engine->sensorEventQueue, engine->accelerometerSensor, (1000L/60)*1000); } break; case APP_CMD_LOST_FOCUS: // When our app loses focus, we stop monitoring the accelerometer. // This is to avoid consuming battery while not being used. if (engine->accelerometerSensor != NULL) { ASensorEventQueue_disableSensor(engine->sensorEventQueue, engine->accelerometerSensor); } // Also stop animating. engine->animating = 0; break; default: break; } }
void disableAccelerometer(void) { LOGI("disableAccelerometer()"); if (engine.accelerometerSensor != NULL) { ASensorEventQueue_disableSensor(engine.sensorEventQueue, engine.accelerometerSensor); } }
static void disableSensorManager() { if(sstJoystick.bAccelerometerEnabled) { ASensorEventQueue_disableSensor(sstJoystick.sensorEventQueue, sstJoystick.accelerometerSensor); sstJoystick.bAccelerometerEnabled = orxFALSE; } }
// センサーからの値取得を不許可にする void disable_sensors(struct engine* engine) { int i; for (i = 0; i < SENSOR_MAX; i++) { if (engine->sensors[i].sensor != NULL) { ASensorEventQueue_disableSensor(engine->sensorEventQueue, /////-----(1) engine->sensors[i].sensor); } } }
void Engine::suspendSensors() { // When our app loses focus, we stop monitoring the accelerometer. // This is to avoid consuming battery while not being used. if( mAccelerometerSensor != NULL ) { ASensorEventQueue_disableSensor( mSensorEventQueue, mAccelerometerSensor ); } }
static void SDL_ANDROID_SensorClose(SDL_Sensor *sensor) { if (sensor->hwdata) { ASensorEventQueue_disableSensor(sensor->hwdata->eventqueue, sensor->hwdata->asensor); ASensorManager_destroyEventQueue(SDL_sensor_manager, sensor->hwdata->eventqueue); SDL_free(sensor->hwdata); sensor->hwdata = NULL; } }
/** * Process the next main command. */ static void engine_handle_cmd(struct android_app* app, int32_t cmd) { struct engine* engine = (struct engine*)app->userData; switch (cmd) { case APP_CMD_SAVE_STATE: // The system has asked us to save our current state. Do so. engine->app->savedState = malloc(sizeof(struct saved_state)); *((struct saved_state*)engine->app->savedState) = engine->state; engine->app->savedStateSize = sizeof(struct saved_state); break; case APP_CMD_INIT_WINDOW: // The window is being shown, get it ready. if (engine->app->window != NULL) { engine_init_display(engine); nuiAndroidBridge::androidResize(ANativeWindow_getWidth(app->window), ANativeWindow_getHeight(app->window)); nuiButton* pButton = new nuiButton("Prout!"); // pButton->SetPosition(nuiCenter); gpBridge->AddChild(pButton); engine_draw_frame(engine); engine->animating = 1; } 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: // When our app gains focus, we start monitoring the accelerometer. if (engine->accelerometerSensor != NULL) { ASensorEventQueue_enableSensor(engine->sensorEventQueue, engine->accelerometerSensor); // We'd like to get 60 events per second (in us). ASensorEventQueue_setEventRate(engine->sensorEventQueue, engine->accelerometerSensor, (1000L/60)*1000); } break; case APP_CMD_LOST_FOCUS: // When our app loses focus, we stop monitoring the accelerometer. // This is to avoid consuming battery while not being used. if (engine->accelerometerSensor != NULL) { ASensorEventQueue_disableSensor(engine->sensorEventQueue, engine->accelerometerSensor); } // Also stop animating. engine->animating = 1; engine_draw_frame(engine); break; } }
/*********************************************************************************** * Process the next main command. **********************************************************************************/ static void engine_handle_cmd(struct android_app* app, int32_t cmd) { struct engine* engine = (struct engine*)app->userData; switch (cmd) { case APP_CMD_SAVE_STATE: // The system has asked us to save our current state. Do so. engine->app->savedState = malloc(sizeof(struct saved_state)); *((struct saved_state*)engine->app->savedState) = engine->state; engine->app->savedStateSize = sizeof(struct saved_state); break; case APP_CMD_INIT_WINDOW: // The window is being shown, get it ready. LOGI("APP_CMD_INIT_WINDOW 11"); if (engine->app->window != NULL) { engine_init_display(engine); //engine_draw_frame(engine); } break; case APP_CMD_TERM_WINDOW: LOGI("APP_CMD_TERM_WINDOW 11"); // The window is being hidden or closed, clean it up. engine_term_display(engine); break; case APP_CMD_GAINED_FOCUS: // When our app gains focus, we start monitoring the accelerometer. if (engine->accelerometerSensor != NULL) { ASensorEventQueue_enableSensor(engine->sensorEventQueue, engine->accelerometerSensor); // We'd like to get 60 events per second (in us). ASensorEventQueue_setEventRate(engine->sensorEventQueue, engine->accelerometerSensor, (1000L/60)*1000); } break; case APP_CMD_LOST_FOCUS: // When our app loses focus, we stop monitoring the accelerometer. // This is to avoid consuming battery while not being used. if (engine->accelerometerSensor != NULL) { ASensorEventQueue_disableSensor(engine->sensorEventQueue, engine->accelerometerSensor); } //engine_draw_frame(engine); break; } }
bool CIrrDeviceAndroid::deactivateAccelerometer() { if (Accelerometer) { ASensorEventQueue_disableSensor(SensorEventQueue, Accelerometer); Accelerometer = 0; os::Printer::log("Deactivated accelerometer", ELL_DEBUG); return true; } return false; }
bool CIrrDeviceAndroid::deactivateGyroscope() { if (Gyroscope) { ASensorEventQueue_disableSensor(SensorEventQueue, Gyroscope); Gyroscope = 0; os::Printer::log("Deactivated gyroscope", ELL_DEBUG); return true; } return false; }
void stopSensor() { // if (engine.accelerometerSensor != NULL) { // ASensorEventQueue_disableSensor(engine.accelerometerEventQueue, // engine.accelerometerSensor); // } if (engine.gyroscopeSensor != NULL) { ASensorEventQueue_disableSensor(engine.gyroscopeEventQueue, engine.gyroscopeSensor); } // if (engine.magneticSensor != NULL) { // ASensorEventQueue_disableSensor(engine.magneticEventQueue, // engine.magneticSensor); // } }
/** * Process the next main command. */ static void engine_handle_cmd(struct android_app* app, int32_t cmd) { struct engine* engine = (struct engine*)app->userData; switch (cmd) { case APP_CMD_SAVE_STATE: LOGI("from APP_CMD_SAVE_STATE\n"); saveState(app); break; case APP_CMD_INIT_WINDOW: LOGI("from APP_CMD_INIT_WINDOW\n"); // The window is being shown, get it ready. if (engine->app->window != NULL) { engine_init_display(engine); engine_init_shaders(engine); engine_draw_frame(engine); } break; case APP_CMD_TERM_WINDOW: LOGI("from APP_CMD_TERM_WINDOW\n"); // The window is being hidden or closed, clean it up. cleanup(engine); break; case APP_CMD_GAINED_FOCUS: saveState(app); #if 0 // When our app gains focus, we start monitoring the accelerometer. if (engine->accelerometerSensor != NULL) { ASensorEventQueue_enableSensor(engine->sensorEventQueue, engine->accelerometerSensor); // We'd like to get 60 events per second (in us). ASensorEventQueue_setEventRate(engine->sensorEventQueue, engine->accelerometerSensor, (1000L/60)*1000); } #endif LOGI("from APP_CMD_GAINED_FOCUS\n"); break; case APP_CMD_LOST_FOCUS: LOGI("from APP_CMD_LOST_FOCUS\n"); // When our app loses focus, we stop monitoring the accelerometer. // This is to avoid consuming battery while not being used. if (engine->accelerometerSensor != NULL) { ASensorEventQueue_disableSensor(engine->sensorEventQueue, engine->accelerometerSensor); } // Also stop animating. engine->animating = 0; engine_draw_frame(engine); break; } }
/** * Process the next main command. */ static void window_handle_cmd(struct android_app* app, int32_t cmd) { la_window_t* window = (la_window_t*)app->userData; switch (cmd) { case APP_CMD_SAVE_STATE: la_print("---------------------------- app save state"); // The system has asked us to save our current state. Do so. // window->app->savedState = malloc(sizeof(struct saved_state)); // *((struct saved_state*)window->app->savedState) = NULL;//window->state; // window->app->savedStateSize = sizeof(struct saved_state); break; case APP_CMD_INIT_WINDOW: // The window is being shown, get it ready. if (window->app->window != NULL) { window_init_display(window); la_port_swap_buffers(window); } main(0, NULL); break; case APP_CMD_TERM_WINDOW: // The cross-platform window kill. la_window_kill__(window); // The window is being hidden or closed, clean it up. window_term_display(window); break; case APP_CMD_GAINED_FOCUS: // When our app gains focus, we start monitoring the accelerometer. if (window->accelerometerSensor != NULL) { ASensorEventQueue_enableSensor(window->sensorEventQueue, window->accelerometerSensor); // We'd like to get 60 events per second (in us). ASensorEventQueue_setEventRate(window->sensorEventQueue, window->accelerometerSensor, (1000L/60)*1000); } break; case APP_CMD_LOST_FOCUS: // When our app loses focus, we stop monitoring the accelerometer. // This is to avoid consuming battery while not being used. if (window->accelerometerSensor != NULL) { ASensorEventQueue_disableSensor(window->sensorEventQueue, window->accelerometerSensor); } la_port_swap_buffers(window); break; } }
void gdk_android_handle_glue_cmd(struct android_app* app, int32_t cmd) { GError *err = NULL; //GTKAndroidInitPhase *engine = (GTKAndroidInitPhase *) app->userData; switch (cmd) { case APP_CMD_SAVE_STATE: // The system has asked us to save our current state. Do so. app->savedState = NULL; app->savedStateSize = 0; break; case APP_CMD_INIT_WINDOW: // The window is being shown, get it ready. if (app->window != NULL && !gdk_android_init_display(app, &err)) { g_error("%s", err->message); g_error_free(err); } break; case APP_CMD_TERM_WINDOW: if (gdk_android_stop) gdk_android_stop(); break; case APP_CMD_PAUSE: case APP_CMD_STOP: if (gdk_android_stop) gdk_android_stop(); break; case APP_CMD_GAINED_FOCUS: // When our app gains focus, we start monitoring the accelerometer. if (accelerometerSensor != NULL) { ASensorEventQueue_enableSensor(sensorEventQueue, accelerometerSensor); ASensorEventQueue_setEventRate(sensorEventQueue, accelerometerSensor, 0.5); } break; case APP_CMD_LOST_FOCUS: // When our app loses focus, we stop monitoring the accelerometer. // This is to avoid consuming battery while not being used. if (accelerometerSensor != NULL) ASensorEventQueue_disableSensor(sensorEventQueue, accelerometerSensor); break; } }
status Sensor::disable() { if ((mEventLoop.mEnabled) && (mSensor != NULL)) { if (ASensorEventQueue_disableSensor(mEventLoop.mSensorEventQueue, mSensor) < 0) { goto ERROR; } mSensor = NULL; } return STATUS_OK; ERROR: Pegas_log_error("Error while deactivating sensor."); return STATUS_KO; }
/** *处理下一主命令。 */ static void engine_handle_cmd(struct android_app* app, int32_t cmd) { struct engine* engine = (struct engine*)app->userData; switch (cmd) { case APP_CMD_SAVE_STATE: //系统已经要求我们保存当前状态。就这样做。 engine->app->savedState = malloc(sizeof(struct saved_state)); *((struct saved_state*)engine->app->savedState) = engine->state; engine->app->savedStateSize = sizeof(struct saved_state); break; case APP_CMD_INIT_WINDOW: //正在显示窗口,让其准备就绪。 if (engine->app->window != NULL) { engine_init_display(engine); engine_draw_frame(engine); } break; case APP_CMD_TERM_WINDOW: //正在隐藏或关闭窗口,请其进行清理。 engine_term_display(engine); break; case APP_CMD_GAINED_FOCUS: //当我们的应用获得焦点时,我们开始监控加速计。 if (engine->accelerometerSensor != NULL) { ASensorEventQueue_enableSensor(engine->sensorEventQueue, engine->accelerometerSensor); //我们想要每秒获得 60 个事件(在美国)。 ASensorEventQueue_setEventRate(engine->sensorEventQueue, engine->accelerometerSensor, (1000L / 60) * 1000); } break; case APP_CMD_LOST_FOCUS: //当我们的应用程序失去焦点时,我们会停止监控加速计。 //这可在不使用时避免使用电池。 if (engine->accelerometerSensor != NULL) { ASensorEventQueue_disableSensor(engine->sensorEventQueue, engine->accelerometerSensor); } //另外,停止动画。 engine->animating = 0; engine_draw_frame(engine); break; } }
static void engine_handle_command(struct android_app* app, int32_t cmd) { struct engine* engine = (struct engine*)app->userData; switch (cmd) { case APP_CMD_SAVE_STATE: app_save_state_callback(); break; case APP_CMD_INIT_WINDOW: if (engine->app->window != nullptr) { engine_init_display(engine); engine_draw_frame(engine); } break; case APP_CMD_TERM_WINDOW: engine_term_display(engine); break; case APP_CMD_GAINED_FOCUS: if (engine->accelerometerSensor != nullptr) { ASensorEventQueue_enableSensor(engine->sensorEventQueue, engine->accelerometerSensor); ASensorEventQueue_setEventRate(engine->sensorEventQueue, engine->accelerometerSensor, (1000L/60)*1000); accelerometer_enable_callback(); } break; case APP_CMD_LOST_FOCUS: if (engine->accelerometerSensor != nullptr) { ASensorEventQueue_disableSensor(engine->sensorEventQueue, engine->accelerometerSensor); accelerometer_disable_callback(); } engine_draw_frame(engine); break; } }
void SensorImpl::setEnabled(const bool enabled) { if (enabled == isEnabled() || !isAvailable()) return; if (enabled) { if (ASensorEventQueue_enableSensor(ns_sensorEventQueue, getDefault(m_type)) >= 0) { m_sensor = getDefault(m_type); if (auto rate = ASensor_getMinDelay(m_sensor)) ASensorEventQueue_setEventRate(ns_sensorEventQueue, m_sensor, rate); } } else { ASensorEventQueue_disableSensor(ns_sensorEventQueue, m_sensor); m_sensor = NULL; } }
void Window::handle_cmd( int32_t cmd ) { switch( cmd ) { case APP_CMD_SAVE_STATE: m_app->savedStateSize = 0; break; case APP_CMD_INIT_WINDOW: if( m_app->window != 0 ) { initialize(); } break; case APP_CMD_TERM_WINDOW: m_finished = true; break; case APP_CMD_GAINED_FOCUS: if( m_accelerometerSensor != 0 ) { ASensorEventQueue_enableSensor( m_sensorEventQueue, m_accelerometerSensor ); ASensorEventQueue_setEventRate( m_sensorEventQueue, m_accelerometerSensor, 1000000/60 ); } // notifyevent( "focusgained" ); break; case APP_CMD_LOST_FOCUS: if( m_accelerometerSensor != 0 ) { ASensorEventQueue_disableSensor( m_sensorEventQueue, m_accelerometerSensor ); } // notifyevent( "focuslost" ); break; } }
// メインコマンドの処理 static void engine_handle_cmd(struct android_app* app, int32_t cmd) { struct engine* engine = (struct engine*) app->userData; switch (cmd) { case APP_CMD_SAVE_STATE: // 状態保存を行うとき // 状態保存エリア取得 engine->app->savedState = malloc(sizeof(struct saved_state)); *((struct saved_state*) engine->app->savedState) = engine->state; engine->app->savedStateSize = sizeof(struct saved_state); break; case APP_CMD_INIT_WINDOW: // ウィンドウを初期化したとき if (engine->app->window != NULL) { // 画面を初期化する engine_init_display(engine); // アニメーションを有効化する engine->animating = 1; // 画面を描画する engine_draw_frame(engine); } break; case APP_CMD_TERM_WINDOW: // ウィンドウを破棄するとき // EGL情報を破棄する engine_term_display(engine); break; case APP_CMD_GAINED_FOCUS: // アプリがフォーカスを取得したとき if (engine->accelerometerSensor != NULL) { // 加速度センサーを有効化する ASensorEventQueue_enableSensor(engine->sensorEventQueue, engine->accelerometerSensor); // センサー情報取得間隔を設定する ASensorEventQueue_setEventRate(engine->sensorEventQueue, engine->accelerometerSensor, (1000L / 60) * 1000); } if (engine->gyroscopeSensor != NULL) { // ジャイロスコープを有効化する ASensorEventQueue_enableSensor(engine->sensorEventQueue, engine->gyroscopeSensor); // センサー情報取得間隔を設定する ASensorEventQueue_setEventRate(engine->sensorEventQueue, engine->gyroscopeSensor, (1000L / 60) * 1000); } break; case APP_CMD_LOST_FOCUS: // フォーカスが消失したとき if (engine->accelerometerSensor != NULL) { // 加速度センサーを無効化する ASensorEventQueue_disableSensor(engine->sensorEventQueue, engine->accelerometerSensor); } if (engine->gyroscopeSensor != NULL) { // ジャイロスコープを無効化する ASensorEventQueue_disableSensor(engine->sensorEventQueue, engine->gyroscopeSensor); } // アニメーション停止 engine->animating = 0; // 画面を表示 engine_draw_frame(engine); break; } }
static void engine_handle_cmd(struct android_app* app, int32_t cmd) { struct engine* engine = (struct engine*)app->userData; // LOGI("**** CMD %i\n",cmd); switch (cmd) { case APP_CMD_SAVE_STATE: // The system has asked us to save our current state. Do so. //engine->app->savedState = malloc(sizeof(struct saved_state)); //*((struct saved_state*)engine->app->savedState) = engine->state; //engine->app->savedStateSize = sizeof(struct saved_state); break; case APP_CMD_CONFIG_CHANGED: case APP_CMD_WINDOW_RESIZED: { #if 0 // android blows if (engine->display_active) { EGLint w,h; eglQuerySurface(engine->display, engine->surface, EGL_WIDTH, &w); eglQuerySurface(engine->display, engine->surface, EGL_HEIGHT, &h); engine->os->init_video_mode(w,h); //print_line("RESIZED VIDEO MODE: "+itos(w)+","+itos(h)); engine_draw_frame(engine); } #else if (engine->display_active) { EGLint w,h; eglQuerySurface(engine->display, engine->surface, EGL_WIDTH, &w); eglQuerySurface(engine->display, engine->surface, EGL_HEIGHT, &h); // if (w==engine->os->get_video_mode().width && h==engine->os->get_video_mode().height) // break; engine_term_display(engine); } engine->os->reload_gfx(); engine_draw_frame(engine); engine->animating=1; /* EGLint w,h; eglQuerySurface(engine->display, engine->surface, EGL_WIDTH, &w); eglQuerySurface(engine->display, engine->surface, EGL_HEIGHT, &h); engine->os->init_video_mode(w,h); //print_line("RESIZED VIDEO MODE: "+itos(w)+","+itos(h)); }*/ #endif } break; case APP_CMD_INIT_WINDOW: //The window is being shown, get it ready. // LOGI("INIT WINDOW"); if (engine->app->window != NULL) { if (engine->os==NULL) { //do initialization here, when there's OpenGL! hackish but the only way engine->os = new OS_Android(_gfx_init,engine); // char *args[]={"-test","gui",NULL}; __android_log_print(ANDROID_LOG_INFO,"godot","pre asdasd setup..."); #if 0 Error err = Main::setup("apk",2,args); #else Error err = Main::setup("apk",0,NULL); String modules = Globals::get_singleton()->get("android/modules"); Vector<String> mods = modules.split(",",false); mods.push_back("GodotOS"); __android_log_print(ANDROID_LOG_INFO,"godot","mod count: %i",mods.size()); if (mods.size()) { jclass activityClass = engine->jni->FindClass("android/app/NativeActivity"); jmethodID getClassLoader = engine->jni->GetMethodID(activityClass,"getClassLoader", "()Ljava/lang/ClassLoader;"); jobject cls = engine->jni->CallObjectMethod(app->activity->clazz, getClassLoader); jclass classLoader = engine->jni->FindClass("java/lang/ClassLoader"); jmethodID findClass = engine->jni->GetMethodID(classLoader, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;"); static JNINativeMethod methods[] = { {"registerSingleton", "(Ljava/lang/String;Ljava/lang/Object;)V",(void *)&Java_com_android_godot_Godot_registerSingleton}, {"registerMethod", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)V",(void *)&Java_com_android_godot_Godot_registerMethod}, {"getGlobal", "(Ljava/lang/String;)Ljava/lang/String;", (void *)&Java_com_android_godot_Godot_getGlobal}, }; jstring gstrClassName = engine->jni->NewStringUTF("com/android/godot/Godot"); jclass GodotClass = (jclass)engine->jni->CallObjectMethod(cls, findClass, gstrClassName); __android_log_print(ANDROID_LOG_INFO,"godot","godot ****^*^*?^*^*class data %x",GodotClass); engine->jni->RegisterNatives(GodotClass,methods,sizeof(methods)/sizeof(methods[0])); for (int i=0;i<mods.size();i++) { String m = mods[i]; //jclass singletonClass = engine->jni->FindClass(m.utf8().get_data()); jstring strClassName = engine->jni->NewStringUTF(m.utf8().get_data()); jclass singletonClass = (jclass)engine->jni->CallObjectMethod(cls, findClass, strClassName); __android_log_print(ANDROID_LOG_INFO,"godot","****^*^*?^*^*class data %x",singletonClass); jmethodID initialize = engine->jni->GetStaticMethodID(singletonClass, "initialize", "(Landroid/app/Activity;)Lcom/android/godot/Godot$SingletonBase;"); jobject obj = engine->jni->CallStaticObjectMethod(singletonClass,initialize,app->activity->clazz); __android_log_print(ANDROID_LOG_INFO,"godot","****^*^*?^*^*class instance %x",obj); jobject gob = engine->jni->NewGlobalRef(obj); } } #endif if (!Main::start()) return; //should exit instead and print the error engine->os->main_loop_begin(); } else { //i guess recreate resources? engine->os->reload_gfx(); } engine->animating=1; engine_draw_frame(engine); } break; case APP_CMD_TERM_WINDOW: // The window is being hidden or closed, clean it up. // LOGI("TERM WINDOW"); engine_term_display(engine); break; case APP_CMD_GAINED_FOCUS: // When our app gains focus, we start monitoring the accelerometer. if (engine->accelerometerSensor != NULL) { ASensorEventQueue_enableSensor(engine->sensorEventQueue, engine->accelerometerSensor); // We'd like to get 60 events per second (in us). ASensorEventQueue_setEventRate(engine->sensorEventQueue, engine->accelerometerSensor, (1000L/60)*1000); } engine->animating = 1; break; case APP_CMD_LOST_FOCUS: // When our app loses focus, we stop monitoring the accelerometer. // This is to avoid consuming battery while not being used. if (engine->accelerometerSensor != NULL) { ASensorEventQueue_disableSensor(engine->sensorEventQueue, engine->accelerometerSensor); } // Also stop animating. engine->animating = 0; engine_draw_frame(engine); break; } }
void android_handle_event(struct android_app* app, int32_t cmd) { AInstance* a = static_cast<AInstance*>(app->userData); switch (cmd) { case APP_CMD_INIT_WINDOW: android_init_display(a); break; case APP_CMD_TERM_WINDOW: eglMakeCurrent( a->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglDestroySurface(a->display, a->surface); a->surface = EGL_NO_SURFACE; break; case APP_CMD_WINDOW_RESIZED: android_handle_display(a); break; case APP_CMD_GAINED_FOCUS: // When our app gains focus, we start monitoring the accelerometer. if (a->accelerometerSensor) { ASensorEventQueue_enableSensor( a->sensorEventQueue, a->accelerometerSensor); // We'd like to get 60 events per second (in us). ASensorEventQueue_setEventRate( a->sensorEventQueue, a->accelerometerSensor, (1000L / 60) * 1000); } a->director->mixer().suspend(false); a->active = true; break; case APP_CMD_LOST_FOCUS: a->active = false; break; case APP_CMD_LOW_MEMORY: a->director->on_memory_warning(); break; case APP_CMD_RESUME: if (a->surface) { eglMakeCurrent(a->display, a->surface, a->surface, a->context); // From NVIDIA: // Note that in some cases, only the onPause is received on suspend, in which case, the // focus lost callback actually comes when the device is resumed to the lock screen. In // other words, resuming sends an indication that you have been resumed (onResume) // and then an indication that you are hidden (focus lost). And the unlock case remains // unchanged (focus regained). if (a->active) android_handle_event(app, APP_CMD_GAINED_FOCUS); } break; case APP_CMD_SAVE_STATE: break; case APP_CMD_PAUSE: eglMakeCurrent( a->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); if (a->accelerometerSensor) { ASensorEventQueue_disableSensor( a->sensorEventQueue, a->accelerometerSensor); } a->director->mixer().suspend(true); break; case APP_CMD_DESTROY: a->active = false; a->done = true; break; default: break; } }
void pause() { ASensorEventQueue_disableSensor(accelerometerEventQueue, accelerometer); }