static void* android_app_entry(void* param) { struct android_app* android_app = (struct android_app*)param; android_app->config = AConfiguration_new(); AConfiguration_fromAssetManager(android_app->config, android_app->activity->assetManager); print_cur_config(android_app); android_app->cmdPollSource.id = LOOPER_ID_MAIN; android_app->cmdPollSource.app = android_app; android_app->cmdPollSource.process = process_cmd; android_app->inputPollSource.id = LOOPER_ID_INPUT; android_app->inputPollSource.app = android_app; android_app->inputPollSource.process = process_input; ALooper* looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS); ALooper_addFd(looper, android_app->msgread, LOOPER_ID_MAIN, ALOOPER_EVENT_INPUT, NULL, &android_app->cmdPollSource); android_app->looper = looper; pthread_mutex_lock(&android_app->mutex); android_app->running = 1; pthread_cond_broadcast(&android_app->cond); pthread_mutex_unlock(&android_app->mutex); android_main(android_app); android_app_destroy(android_app); return NULL; }
void ApplicationContext::initAppForAndroid(AAssetManager* assetMgr, ANativeWindow* window) { mAConfig = AConfiguration_new(); AConfiguration_fromAssetManager(mAConfig, assetMgr); mAAssetMgr = assetMgr; mAWindow = window; initApp(); }
int TBSystem::GetDPI() { AConfiguration *config = AConfiguration_new(); AConfiguration_fromAssetManager(config, g_pManager); int32_t density = AConfiguration_getDensity(config); AConfiguration_delete(config); if (density == 0 || density == ACONFIGURATION_DENSITY_NONE) return 120; return density; }
void ApplicationContextAndroid::initAppForAndroid(AAssetManager* assetMgr, ANativeWindow* window) { mAConfig = AConfiguration_new(); AConfiguration_fromAssetManager(mAConfig, assetMgr); mAAssetMgr = assetMgr; mWindows.resize(1); mWindows[0].native = window; initApp(); }
int PlatformUtils::getDPI() { AConfiguration *config = AConfiguration_new(); AConfiguration_fromAssetManager(config, AndroidServices::getAAssetManager()); int32_t density = AConfiguration_getDensity(config); AConfiguration_delete(config); if (density == 0 || density == ACONFIGURATION_DENSITY_NONE) return 120; return density; }
static void initializeMain(ActivityStates* states) { // Protect from concurrent access Lock lock(states->mutex); // Prepare and share the looper to be read later ALooper* looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS); states->looper = looper; // Get the default configuration states->config = AConfiguration_new(); AConfiguration_fromAssetManager(states->config, states->activity->assetManager); }
static void handleCmd(struct android_app* app, int32_t cmd) { switch (cmd) { case APP_CMD_SAVE_STATE: // http://developer.android.com/reference/android/app/NativeActivity.html break; case APP_CMD_INIT_WINDOW: if(app->window && gRoot) { AConfiguration* config = AConfiguration_new(); AConfiguration_fromAssetManager(config, app->activity->assetManager); gAssetMgr = app->activity->assetManager; if(!gRenderWnd) { Ogre::ArchiveManager::getSingleton().addArchiveFactory( new Ogre::APKFileSystemArchiveFactory(app->activity->assetManager) ); Ogre::ArchiveManager::getSingleton().addArchiveFactory( new Ogre::APKZipArchiveFactory(app->activity->assetManager) ); Ogre::NameValuePairList opt; opt["externalWindowHandle"] = Ogre::StringConverter::toString((int)app->window); opt["androidConfig"] = Ogre::StringConverter::toString((int)config); gRenderWnd = gRoot->createRenderWindow("OgreWindow", 0, 0, false, &opt); InitStartScene(); } else { static_cast<Ogre::AndroidEGLWindow*>(gRenderWnd)->_createInternalResources(app->window, config); } AConfiguration_delete(config); } break; case APP_CMD_TERM_WINDOW: if(gRoot && gRenderWnd) static_cast<Ogre::AndroidEGLWindow*>(gRenderWnd)->_destroyInternalResources(); break; case APP_CMD_GAINED_FOCUS: // When our app gains focus, we start monitoring the accelerometer. break; case APP_CMD_LOST_FOCUS: // Also stop animating. break; } }
// ==== コンストラクタ ANAS::Activity::Activity( ANAS::ActivityConfigration &_conf ): pActivity( _conf.pActivity ), pSavedState( _conf.pSavedState ), SavedStateSize( _conf.SavedStateSize ), pCallBacks( _conf.pUserCallbacks ), pInputInterface( _conf.pInput ), pGraphicInterface( _conf.pGraphic ) { Log::i("Activity Constructor","Start Construction" ); // Destroy Sync. DestroyFuture = DestroyPromise.get_future(); // Config pConfig = AConfiguration_new(); if(pConfig){ AConfiguration_fromAssetManager(pConfig, pActivity->assetManager); } // Test Code. /* const char* asset_name = "android_logo.png"; AAsset *asset = AAssetManager_open(pActivity->assetManager, asset_name, AASSET_MODE_STREAMING); if(asset){ int Asset_size = AAsset_getLength(asset); const void *Asset_ptr = AAsset_getBuffer(asset); boost::format asset_format("FILE: %1%, SIZE: %2%"); Log::e("Asset Test", (asset_format % asset_name % Asset_size).str().c_str() ); Image _test_img; _test_img.Load<IFT_PNG>( Asset_ptr ); AAsset_close( asset ); } */ // CallBacks SetCallBacks(pActivity->callbacks); Log::i("Activity Constructor", "End Construction"); }
//----------------------------------------------------------------------------// void AndroidAppHelper::handleCmd (struct android_app* app, int32_t cmd) { switch (cmd) { case APP_CMD_SAVE_STATE: break; case APP_CMD_INIT_WINDOW: if (app->window && Ogre::Root::getSingletonPtr()) { AConfiguration* config = AConfiguration_new(); AConfiguration_fromAssetManager (config, app->activity->assetManager); if (!mRenderWnd) { Ogre::NameValuePairList opt; opt["externalWindowHandle"] = Ogre::StringConverter::toString ((int)app->window); opt["androidConfig"] = Ogre::StringConverter::toString ((int)config); mRenderWnd = Ogre::Root::getSingleton().createRenderWindow ( "OgreWindow", 0, 0, false, &opt); setWindowCreated (true); } else { static_cast<Ogre::AndroidEGLWindow*> (mRenderWnd)->_createInternalResources ( app->window, config); } AConfiguration_delete (config); } break; case APP_CMD_TERM_WINDOW: if (Ogre::Root::getSingletonPtr() && mRenderWnd) static_cast<Ogre::AndroidEGLWindow*> (mRenderWnd)->_destroyInternalResources(); break; case APP_CMD_GAINED_FOCUS: break; case APP_CMD_LOST_FOCUS: break; case APP_CMD_CONFIG_CHANGED: break; } }
static void initWindow() { LOGI("------->initWindow() >>>>>>>>"); LOGI("Calling AConfiguration_new()"); AConfiguration* config = AConfiguration_new(); LOGI("AConfiguration_new() %p", config); AConfiguration_fromAssetManager(config, gAssetManager); LOGI("AConfiguration_fromAssetManager(config, gAssetManager) %p", config); if (!gRenderWnd) { Ogre::ArchiveManager::getSingleton().addArchiveFactory( new Ogre::APKFileSystemArchiveFactory(gAssetManager) ); Ogre::ArchiveManager::getSingleton().addArchiveFactory( new Ogre::APKZipArchiveFactory(gAssetManager) ); Ogre::NameValuePairList opt; LOGI("Ogre::StringConverter::toString((int)mRendereWindow) %s", Ogre::StringConverter::toString((int )mRendereWindow).c_str()); LOGI("Ogre::StringConverter::toString((int)config) %s", Ogre::StringConverter::toString((int )config).c_str()); opt["externalWindowHandle"] = Ogre::StringConverter::toString((int) mRendereWindow); opt["androidConfig"] = Ogre::StringConverter::toString((int) config); gRenderWnd = gRoot->createRenderWindow("OgreWindow", 0, 0, false, &opt); setupScene(); } else { static_cast<Ogre::AndroidEGLWindow*>(gRenderWnd)->_createInternalResources(mRendereWindow, config); } AConfiguration_delete(config); LOGI("<-------initWindow()"); }
int main(void) { std::string out_text; out_text = "Hello Android World 2"; std::cout << std::endl; std::cout << "start" << std::endl; int index = 100; while(index) { std::cout << index << " - " << out_text.c_str() << std::endl; index--; } std::cout << "end" << std::endl; __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "do you see me %d", 55); AConfiguration* config = AConfiguration_new(); int32_t screen_size = AConfiguration_getScreenSize(config); AConfiguration_delete(config); switch(screen_size) { case ACONFIGURATION_SCREENSIZE_ANY: std::cout << "screen_size ANY" << std::endl; break; case ACONFIGURATION_SCREENSIZE_SMALL: std::cout << "screen_size SMALL" << std::endl; break; case ACONFIGURATION_SCREENSIZE_NORMAL: std::cout << "screen_size NORMAL" << std::endl; break; case ACONFIGURATION_SCREENSIZE_LARGE: std::cout << "screen_size LARGE" << std::endl; break; case ACONFIGURATION_SCREENSIZE_XLARGE: std::cout << "screen_size XLARGE" << std::endl; break; }; return 0; }
cxAndroid::cxAndroid() { config = AConfiguration_new(); state = nullptr; size = 0; memset(Language, 0, 3); memset(Country, 0, 3); pthread_mutex_init(&mutex, NULL); pthread_cond_init(&cond, NULL); int msgpipe[2]; pipe(msgpipe); msgread = msgpipe[0]; msgwrite = msgpipe[1]; running = false; animating = false; destroyReq = false; destroyed = false; activityState = -1; window = nullptr; pendingWindow = nullptr; inputQueue = nullptr; pendingInputQueue = nullptr; vm = nullptr; env = nullptr; surface = EGL_NO_SURFACE; context = EGL_NO_CONTEXT; display = EGL_NO_DISPLAY; width = 0; height = 0; }
static void* android_app_entry(void* param) { LOGV("+android_app_entry"); struct android_app* android_app = (struct android_app*)param; android_app->config = AConfiguration_new(); AConfiguration_fromAssetManager(android_app->config, android_app->activity->assetManager); print_cur_config(android_app); android_app->cmdPollSource.id = LOOPER_ID_MAIN; android_app->cmdPollSource.app = android_app; android_app->cmdPollSource.process = process_cmd; android_app->inputPollSource.id = LOOPER_ID_INPUT; android_app->inputPollSource.app = android_app; android_app->inputPollSource.process = process_input; ALooper* looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS); ALooper_addFd(looper, android_app->msgread, LOOPER_ID_MAIN, ALOOPER_EVENT_INPUT, NULL, &android_app->cmdPollSource); android_app->looper = looper; pthread_mutex_lock(&android_app->mutex); android_app->running = 1; pthread_cond_broadcast(&android_app->cond); pthread_mutex_unlock(&android_app->mutex); std::string sargv; // Load command line from ARGV parameter JNIEnv *env = GetEnvAttachThread(android_app->activity->vm); if(env) { jobject me = android_app->activity->clazz; jclass acl = env->GetObjectClass(me); //class pointer of NativeActivity jmethodID giid = env->GetMethodID(acl, "getIntent", "()Landroid/content/Intent;"); jobject intent = env->CallObjectMethod(me, giid); //Got our intent jclass icl = env->GetObjectClass(intent); //class pointer of Intent jmethodID gseid = env->GetMethodID(icl, "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;"); jstring jsARGV = (jstring)env->CallObjectMethod(intent, gseid, env->NewStringUTF("ARGV")); if(jsARGV) { const char *chARGV = env->GetStringUTFChars(jsARGV, 0); if(chARGV) { sargv = std::string(chARGV); LOGI("ARGV: pango %s", chARGV); } env->ReleaseStringUTFChars(jsARGV, chARGV); } android_app->activity->vm->DetachCurrentThread(); } // Set up argv/argc to pass to users main std::vector<std::string> vargv; vargv.push_back("pango"); // Parse parameters from ARGV android intent parameter std::istringstream iss(sargv); std::copy(std::istream_iterator<std::string>(iss), std::istream_iterator<std::string>(), std::back_inserter<std::vector<std::string> >(vargv)); char* argv[vargv.size()+1]; for(size_t ac = 0; ac < vargv.size(); ++ac) { argv[ac] = new char[vargv[ac].size()]; strcpy( argv[ac], vargv[ac].c_str() ); } argv[vargv.size()] = NULL; // Call users standard main entry point. main(vargv.size(), argv); // Clean up parameters for(size_t ac = 0; ac < vargv.size(); ++ac) { delete[] argv[ac]; } android_app_destroy(android_app); LOGV("-android_app_entry"); return NULL; }
/** * 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) { // 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); engine.sensorEventQueue = ASensorManager_createEventQueue(engine.sensorManager, state->looper, LOOPER_ID_USER, NULL, NULL); if (state->savedState != NULL) { // We are starting with a previous saved state; restore from it. engine.state = *(struct saved_state*)state->savedState; } // loop waiting for stuff to do. while (1) { // Read all pending events. int ident; int events; struct android_poll_source* source; // If not animating, we will block forever waiting for events. // If animating, we loop until all events are read, then continue // to draw the next frame of animation. while ((ident=ALooper_pollAll(engine.animating ? 0 : -1, NULL, &events, (void**)&source)) >= 0) { // Process this event. if (source != NULL) { source->process(state, source); } // If a sensor has data, process it now. if (ident == LOOPER_ID_USER) { if (engine.accelerometerSensor != NULL) { ASensorEvent event; while (ASensorEventQueue_getEvents(engine.sensorEventQueue, &event, 1) > 0) { LOG_EVENTS_DEBUG("accelerometer: x=%f y=%f z=%f", event.acceleration.x, event.acceleration.y, event.acceleration.z); AConfiguration* _currentconf = AConfiguration_new(); AConfiguration_fromAssetManager(_currentconf, state->activity->assetManager); static int32_t _orientation = AConfiguration_getOrientation(_currentconf); if (ACONFIGURATION_ORIENTATION_LAND != _orientation) { // ACONFIGURATION_ORIENTATION_ANY // ACONFIGURATION_ORIENTATION_PORT // ACONFIGURATION_ORIENTATION_SQUARE cocos2d::Acceleration acc; acc.x = -event.acceleration.x/10; acc.y = -event.acceleration.y/10; acc.z = event.acceleration.z/10; acc.timestamp = 0; cocos2d::EventAcceleration accEvent(acc); cocos2d::EventDispatcher::getInstance()->dispatchEvent(&accEvent); } else { // ACONFIGURATION_ORIENTATION_LAND // swap x and y parameters cocos2d::Acceleration acc; acc.x = event.acceleration.y/10; acc.y = -event.acceleration.x/10; acc.z = event.acceleration.z/10; acc.timestamp = 0; cocos2d::EventAcceleration accEvent(acc); cocos2d::EventDispatcher::getInstance()->dispatchEvent(&accEvent); } } } } // Check if we are exiting. if (state->destroyRequested != 0) { engine_term_display(&engine); memset(&engine, 0, sizeof(engine)); s_methodInitialized = false; return; } } if (engine.animating) { // Done with events; draw next animation frame. engine.state.angle += .01f; if (engine.state.angle > 1) { engine.state.angle = 0; } // Drawing is throttled to the screen update rate, so there // is no need to do timing here. LOG_RENDER_DEBUG("android_main : engine.animating"); engine_draw_frame(&engine); } else { LOG_RENDER_DEBUG("android_main : !engine.animating"); } } }
static void *android_app_entry(void *data) { struct android_app* android_app = (struct android_app*)data; android_app->config = AConfiguration_new(); AConfiguration_fromAssetManager(android_app->config, android_app->activity->assetManager); print_cur_config(android_app); ALooper* looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS); ALooper_addFd(looper, android_app->msgread, LOOPER_ID_MAIN, ALOOPER_EVENT_INPUT, NULL, NULL); android_app->looper = looper; pthread_mutex_lock(&android_app->mutex); android_app->running = 1; pthread_cond_broadcast(&android_app->cond); pthread_mutex_unlock(&android_app->mutex); memset(&g_android, 0, sizeof(g_android)); g_android = android_app; RARCH_LOG("Native Activity started.\n"); rarch_main_clear_state(); while (!android_app->window) { if (!android_run_events(android_app)) goto exit; } rarch_init_msg_queue(); if (!android_app_start_main(android_app)) { g_settings.input.overlay[0] = 0; // threaded video doesn't work right for just displaying one frame g_settings.video.threaded = false; init_drivers(); driver.video_poke->set_aspect_ratio(driver.video_data, ASPECT_RATIO_SQUARE); rarch_render_cached_frame(); sleep(2); goto exit; } if (!g_extern.libretro_dummy) menu_rom_history_push_current(); for (;;) { if (g_extern.system.shutdown) break; else if (g_extern.lifecycle_mode_state & (1ULL << MODE_LOAD_GAME)) { load_menu_game_prepare(); // If ROM load fails, we exit RetroArch. On console it might make more sense to go back to menu though ... if (load_menu_game()) g_extern.lifecycle_mode_state |= (1ULL << MODE_GAME); else { #ifdef RARCH_CONSOLE g_extern.lifecycle_mode_state |= (1ULL << MODE_MENU); #else return NULL; #endif } g_extern.lifecycle_mode_state &= ~(1ULL << MODE_LOAD_GAME); } else if (g_extern.lifecycle_mode_state & (1ULL << MODE_GAME)) { driver.input->poll(NULL); if (driver.video_poke->set_aspect_ratio) driver.video_poke->set_aspect_ratio(driver.video_data, g_settings.video.aspect_ratio_idx); if (g_extern.lifecycle_mode_state & (1ULL << MODE_VIDEO_THROTTLE_ENABLE)) audio_start_func(); // Main loop while (rarch_main_iterate()); if (g_extern.lifecycle_mode_state & (1ULL << MODE_VIDEO_THROTTLE_ENABLE)) audio_stop_func(); g_extern.lifecycle_mode_state &= ~(1ULL << MODE_GAME); } else if(g_extern.lifecycle_mode_state & (1ULL << MODE_MENU)) { g_extern.lifecycle_mode_state |= (1ULL << MODE_MENU_PREINIT); while((input_key_pressed_func(RARCH_PAUSE_TOGGLE)) ? android_run_events(android_app) : menu_iterate()); g_extern.lifecycle_mode_state &= ~(1ULL << MODE_MENU); } else break; } exit: android_app->activityState = APP_CMD_DEAD; RARCH_LOG("Deinitializing RetroArch...\n"); menu_free(); if (g_extern.config_save_on_exit && *g_extern.config_path) config_save_file(g_extern.config_path); if (g_extern.main_is_init) rarch_main_deinit(); rarch_deinit_msg_queue(); #ifdef PERF_TEST rarch_perf_log(); #endif rarch_main_clear_state(); RARCH_LOG("android_app_destroy!"); if (android_app->inputQueue != NULL) AInputQueue_detachLooper(android_app->inputQueue); AConfiguration_delete(android_app->config); // exit() here is nasty. // pthread_exit(NULL) or return NULL; causes hanging ... // Should probably called ANativeActivity_finsih(), but it's bugged, it will hang our app. exit(0); }
void StAndroidGlue::threadEntry() { if(myJavaVM->AttachCurrentThread(&myThJniEnv, NULL) < 0) { ST_ERROR_LOG("Failed to attach working thread to Java VM"); return; } THE_ANDROID_GLUE = this; StMessageBox::setCallback(msgBoxCallback); myConfig = AConfiguration_new(); AConfiguration_fromAssetManager(myConfig, myActivity->assetManager); updateMonitors(); printConfig(); ALooper* aLooper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS); ALooper_addFd(aLooper, myMsgRead, LooperId_MAIN, ALOOPER_EVENT_INPUT, NULL, &myCmdPollSource); myLooper = aLooper; pthread_mutex_lock(&myMutex); myIsRunning = true; pthread_cond_broadcast(&myCond); pthread_mutex_unlock(&myMutex); // try to load stereo APIs /**jclass aJClass_Real3D = myThJniEnv->FindClass("com/lge/real3d/Real3D"); if(aJClass_Real3D != NULL) { jmethodID aJMet_isStereoDisplayAvailable = myThJniEnv->GetStaticMethodID(aJClass_Real3D, "isStereoDisplayAvailable", "(Landroid/content/Contex;)Z"); postMessage("com.lge.real3d.Real3D !!!"); } jclass aJClass_HTC = myThJniEnv->FindClass("com/htc/view/DisplaySetting"); if(aJClass_HTC != NULL) { jmethodID aJMet_isStereoDisplayAvailable = myThJniEnv->GetStaticMethodID(aJClass_HTC, "setStereoscopic3DFormat", "(Landroid/view/Surface;I)Z"); postMessage("com.htc.view.DisplaySetting !!!"); } jclass aJClass_Sharp = myThJniEnv->FindClass("jp/co/sharp/android/stereo3dlcd/SurfaceController"); if(aJClass_Sharp != NULL) { jmethodID aJMet_setStereoView = myThJniEnv->GetMethodID(aJClass_Sharp, "setStereoView", "(Z)V"); postMessage("jp.co.sharp.android.stereo3dlcd !!!"); }*/ createApplication(); if(!myApp.isNull()) { if(!myApp->open()) { stError("Error: application can not be executed!"); } myApp->exec(); } else { stError("Error: no application to execute!"); } myApp.nullify(); // application is done but we are waiting for destroying event... bool isFirstWait = true; for(; !myToDestroy; ) { if(isFirstWait) { postExit(); isFirstWait = false; } StAndroidPollSource* aSource = NULL; int aNbEvents = 0; ALooper_pollAll(-1, NULL, &aNbEvents, (void** )&aSource); if(aSource != NULL) { aSource->process(this, aSource); } } freeSavedState(); pthread_mutex_lock(&myMutex); if(myInputQueue != NULL) { AInputQueue_detachLooper(myInputQueue); } AConfiguration_delete(myConfig); pthread_cond_broadcast(&myCond); pthread_mutex_unlock(&myMutex); myThJniEnv = NULL; StMessageBox::setCallback(NULL); THE_ANDROID_GLUE = NULL; myJavaVM->DetachCurrentThread(); }
AndroidConfiguration::AndroidConfiguration(AAssetManager* manager) : mManager(manager) , mConfiguration(AConfiguration_new(), &AConfiguration_delete) , mCacheForToString() { mCacheForToString.reserve(AproximateToStringLength); }
void gkAndroidApp::handleCmd(int32_t cmd) { switch (cmd) { case APP_CMD_SAVE_STATE: LOG_FOOT break; case APP_CMD_INIT_WINDOW: LOG_FOOT // The window is being shown, get it ready. if (m_state->window) { AConfiguration* config = AConfiguration_new(); if(!m_window) { AConfiguration_fromAssetManager(config, m_state->activity->assetManager); init(config, "momo_ogre_i.blend"); m_window = gkWindowSystem::getSingleton().getMainWindow(); } else { static_cast<Ogre::AndroidEGLWindow*>(m_window->getRenderWindow())-> _createInternalResources(m_state->window, config); } AConfiguration_delete(config); } break; case APP_CMD_TERM_WINDOW: { LOG_FOOT if(m_window) { static_cast<Ogre::AndroidEGLWindow*>(m_window->getRenderWindow())-> _destroyInternalResources(); } break; } case APP_CMD_GAINED_FOCUS: LOG_FOOT // When our app gains focus, we start monitoring the accelerometer. if (m_accelerometerSensor) { ASensorEventQueue_enableSensor(m_sensorEventQueue, m_accelerometerSensor); // We'd like to get 60 events per second (in us). ASensorEventQueue_setEventRate(m_sensorEventQueue, m_accelerometerSensor, (1000L/60)*1000); } break; case APP_CMD_LOST_FOCUS: LOG_FOOT // When our app loses focus, we stop monitoring the accelerometer. // This is to avoid consuming battery while not being used. if (m_accelerometerSensor) { ASensorEventQueue_disableSensor(m_sensorEventQueue, m_accelerometerSensor); } break; case APP_CMD_CONFIG_CHANGED: LOG_FOOT break; } }
static void handleCmd(struct android_app* app, int32_t cmd) { switch (cmd) { case APP_CMD_SAVE_STATE: break; case APP_CMD_INIT_WINDOW: if (app->window) // && mRoot) { AConfiguration* config = AConfiguration_new(); AConfiguration_fromAssetManager(config, app->activity->assetManager); if (!okit.isInited()) { LOG_FOOT; //okit.getPrefs().winsize.x = drawWidth; //okit.getPrefs().winsize.y = drawHeight; okit.assetMgr = app->activity->assetManager; okit.getPrefs().extWinhandle = Ogre::StringConverter::toString((int)app->window); okit.getPrefs().androidConfig = Ogre::StringConverter::toString((int)config); okit.getPrefs().verbose = true; //gkLogger::enable("OgreKitDemo.log", true); //Ogre::LogManager::getSingleton().getDefaultLog()->addListener(&gLogListener); if (okit.init("")) { LOG_FOOT; m_window = gkWindowSystem::getSingleton().getMainWindow(); LOG_FOOT; okit.m_input = static_cast<OIS::AndroidInputManager*>(m_window->getInputManager()); okit.sensorManager = ASensorManager_getInstance(); okit.accelerometerSensor = ASensorManager_getDefaultSensor(okit.sensorManager, ASENSOR_TYPE_ACCELEROMETER); okit.sensorEventQueue = ASensorManager_createEventQueue(okit.sensorManager, okit.state->looper, LOOPER_ID_USER, NULL, NULL); gkEngine::getSingleton().initializeStepLoop(); LOGI("inited"); //okit.setWindowSize(drawWidth, drawHeight); } } else { LOG_FOOT; Ogre::RenderWindow* rwnd = gkWindowSystem::getSingleton().getMainRenderWindow(); if (rwnd) static_cast<Ogre::AndroidEGLWindow*>(rwnd)->_createInternalResources(app->window, config); } LOG_FOOT; AConfiguration_delete(config); } break; case APP_CMD_TERM_WINDOW: if (okit.isInited()) { Ogre::RenderWindow* rwnd = gkWindowSystem::getSingleton().getMainRenderWindow(); if (rwnd) static_cast<Ogre::AndroidEGLWindow*>(rwnd)->_destroyInternalResources(); } LOGI("terminiate."); break; case APP_CMD_GAINED_FOCUS: // When our app gains focus, we start monitoring the accelerometer. if (okit.accelerometerSensor != NULL) { ASensorEventQueue_enableSensor(okit.sensorEventQueue, okit.accelerometerSensor); // We'd like to get 60 events per second (in us). ASensorEventQueue_setEventRate(okit.sensorEventQueue, okit.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 (okit.accelerometerSensor != NULL) { ASensorEventQueue_disableSensor(okit.sensorEventQueue, okit.accelerometerSensor); } break; case APP_CMD_CONFIG_CHANGED: break; } }