Beispiel #1
0
		void run(android_app* _app)
		{
			m_app = _app;
			m_app->userData = (void*)this;
			m_app->onAppCmd = onAppCmdCB;
			m_app->onInputEvent = onInputEventCB;
			ANativeActivity_setWindowFlags(m_app->activity, 0
				| AWINDOW_FLAG_FULLSCREEN
				| AWINDOW_FLAG_KEEP_SCREEN_ON
				, 0
				);

			const char* argv[1] = { "android.so" };
			m_mte.m_argc = 1;
			m_mte.m_argv = const_cast<char**>(argv);
			
			while (0 == m_app->destroyRequested)
			{
				int32_t num;
				android_poll_source* source;
				/*int32_t id =*/ ALooper_pollAll(-1, NULL, &num, (void**)&source);

				if (NULL != source)
				{
					source->process(m_app, source);
				}
			}

			m_thread.shutdown();
		}
Beispiel #2
0
void goToFullscreenMode(ANativeActivity* activity)
{
    // Hide the status bar
    ANativeActivity_setWindowFlags(activity, AWINDOW_FLAG_FULLSCREEN,
        AWINDOW_FLAG_FULLSCREEN);

    // Hide the navigation bar
    JavaVM* lJavaVM = activity->vm;
    JNIEnv* lJNIEnv = activity->env;

    jobject objectActivity = activity->clazz;
    jclass classActivity = lJNIEnv->GetObjectClass(objectActivity);

    jmethodID methodGetWindow = lJNIEnv->GetMethodID(classActivity, "getWindow", "()Landroid/view/Window;");
    jobject objectWindow = lJNIEnv->CallObjectMethod(objectActivity, methodGetWindow);

    jclass classWindow = lJNIEnv->FindClass("android/view/Window");
    jmethodID methodGetDecorView = lJNIEnv->GetMethodID(classWindow, "getDecorView", "()Landroid/view/View;");
    jobject objectDecorView = lJNIEnv->CallObjectMethod(objectWindow, methodGetDecorView);

    jclass classView = lJNIEnv->FindClass("android/view/View");

    jfieldID FieldSYSTEM_UI_FLAG_LOW_PROFILE = lJNIEnv->GetStaticFieldID(classView, "SYSTEM_UI_FLAG_LOW_PROFILE", "I");
    jint SYSTEM_UI_FLAG_LOW_PROFILE = lJNIEnv->GetStaticIntField(classView, FieldSYSTEM_UI_FLAG_LOW_PROFILE);

    jfieldID FieldSYSTEM_UI_FLAG_FULLSCREEN = lJNIEnv->GetStaticFieldID(classView, "SYSTEM_UI_FLAG_FULLSCREEN", "I");
    jint SYSTEM_UI_FLAG_FULLSCREEN = lJNIEnv->GetStaticIntField(classView, FieldSYSTEM_UI_FLAG_FULLSCREEN);

    //jfieldID FieldSYSTEM_UI_FLAG_IMMERSIVE_STICKY  = lJNIEnv->GetStaticFieldID(classView, "SYSTEM_UI_FLAG_IMMERSIVE_STICKY", "I");
    //jint SYSTEM_UI_FLAG_IMMERSIVE_STICKY = lJNIEnv->GetStaticIntField(classView, FieldSYSTEM_UI_FLAG_IMMERSIVE_STICKY);

    jmethodID methodsetSystemUiVisibility = lJNIEnv->GetMethodID(classView, "setSystemUiVisibility", "(I)V");
    lJNIEnv->CallVoidMethod(objectDecorView, methodsetSystemUiVisibility, SYSTEM_UI_FLAG_LOW_PROFILE | SYSTEM_UI_FLAG_FULLSCREEN | 0x00001000);
}
Beispiel #3
0
void android_main(struct android_app* state) {
    struct engine engine;

    // 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;
	PlatfromInit();

	//_InitSensor();
	//InitSensor();
	
	ANativeActivity_setWindowFlags(state->activity, AWINDOW_FLAG_KEEP_SCREEN_ON, 0);

    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);
            }

			//_ProcessSensorData(ident);

            // Check if we are exiting.
            if (state->destroyRequested != 0) {
                engine_term_display(&engine);
				PlatfromShutDown();
                return;
            }
        }

        if (engine.animating) {

            // Drawing is throttled to the screen update rate, so there
            // is no need to do timing here.
            engine_draw_frame(&engine);
        }
    }
}
Beispiel #4
0
    ActivityState* ActivityState::create(ANativeActivity* activity)
    {
        JOP_ASSERT(ns_instance == nullptr, "There must only be one ActivityState!");

        ns_instance.reset(new ActivityState);
        ns_instance->nativeActivity = activity;

        ANativeActivity_setWindowFlags(activity, AWINDOW_FLAG_KEEP_SCREEN_ON, AWINDOW_FLAG_KEEP_SCREEN_ON);

        Thread::attachJavaThread(activity->vm, activity->env);

        // Get the screen size
        {
            auto env = Thread::getCurrentJavaEnv();

            if (!env)
            {
                JOP_DEBUG_ERROR("No current java environment, function \"" << __func__ << "\"");
                return get();
            }

            jclass activityClass = env->GetObjectClass(activity->clazz);

            jclass displayMetricsClass = env->FindClass("android/util/DisplayMetrics");
            jmethodID displayMetricsInit = env->GetMethodID(displayMetricsClass, "<init>", "()V");
            jobject displayMetricsObject = env->NewObject(displayMetricsClass, displayMetricsInit);

            jmethodID getWindowManagerMethod = env->GetMethodID(activityClass, "getWindowManager", "()Landroid/view/WindowManager;");
            jobject windowManagerObject = env->CallObjectMethod(activity->clazz, getWindowManagerMethod);

            jclass windowManagerClass = env->FindClass("android/view/WindowManager");
            jmethodID getDefaultDisplayMethod = env->GetMethodID(windowManagerClass, "getDefaultDisplay", "()Landroid/view/Display;");
            jobject displayObject = env->CallObjectMethod(windowManagerObject, getDefaultDisplayMethod);

            jclass displayClass = env->FindClass("android/view/Display");
            jmethodID getMetricsMethod = env->GetMethodID(displayClass, "getMetrics", "(Landroid/util/DisplayMetrics;)V");
            env->CallVoidMethod(displayObject, getMetricsMethod, displayMetricsObject);

            jfieldID pixelsWidth = env->GetFieldID(displayMetricsClass, "widthPixels", "I");
            jfieldID pixelsHeight = env->GetFieldID(displayMetricsClass, "heightPixels", "I");

            ns_instance->screenSize.x = env->GetIntField(displayMetricsObject, pixelsWidth);
            ns_instance->screenSize.y = env->GetIntField(displayMetricsObject, pixelsHeight);

            //jmethodID getRefreshRateMethod = env->GetMethodID(displayClass, "getRefreshRate", "(Landroid/view/Display;)F");
            ns_instance->screenRefreshRate = 60;//env->CallFloatMethod(displayObject, getRefreshRateMethod);

            env->DeleteLocalRef(activityClass);
            env->DeleteLocalRef(displayMetricsObject);
            env->DeleteLocalRef(windowManagerObject);
            env->DeleteLocalRef(windowManagerClass);
            env->DeleteLocalRef(displayObject);
            env->DeleteLocalRef(displayClass);
        }

        return get();
    }
void ANativeActivity_onCreate(ANativeActivity* activity,
      void* savedState, size_t savedStateSize)
{
   (void)savedState;
   (void)savedStateSize;

   RARCH_LOG("Creating Native Activity: %p\n", activity);
   activity->callbacks->onDestroy = onDestroy;
   activity->callbacks->onStart = onStart;
   activity->callbacks->onResume = onResume;
   activity->callbacks->onSaveInstanceState = NULL;
   activity->callbacks->onPause = onPause;
   activity->callbacks->onStop = onStop;
   activity->callbacks->onConfigurationChanged = onConfigurationChanged;
   activity->callbacks->onLowMemory = NULL;
   activity->callbacks->onWindowFocusChanged = onWindowFocusChanged;
   activity->callbacks->onNativeWindowCreated = onNativeWindowCreated;
   activity->callbacks->onNativeWindowDestroyed = onNativeWindowDestroyed;
   activity->callbacks->onInputQueueCreated = onInputQueueCreated;
   activity->callbacks->onInputQueueDestroyed = onInputQueueDestroyed;

   // these are set only for the native activity, and are reset when it ends
   ANativeActivity_setWindowFlags(activity, AWINDOW_FLAG_KEEP_SCREEN_ON | AWINDOW_FLAG_FULLSCREEN, 0);

   struct android_app* android_app = (struct android_app*)malloc(sizeof(struct android_app));
   memset(android_app, 0, sizeof(struct android_app));
   android_app->activity = activity;

   pthread_mutex_init(&android_app->mutex, NULL);
   pthread_cond_init(&android_app->cond, NULL);

   int msgpipe[2];
   if (pipe(msgpipe))
   {
      RARCH_ERR("could not create pipe: %s.\n", strerror(errno));
      activity->instance = NULL;
   }
   else
   {
      android_app->msgread = msgpipe[0];
      android_app->msgwrite = msgpipe[1];

      pthread_create(&android_app->thread, NULL, android_app_entry, android_app);

      // Wait for thread to start.
      pthread_mutex_lock(&android_app->mutex);
      while (!android_app->running)
         pthread_cond_wait(&android_app->cond, &android_app->mutex);
      pthread_mutex_unlock(&android_app->mutex);

      activity->instance = android_app;
   }
}
Beispiel #6
0
void android_main( struct android_app *app )
{
	int ident, events;
	struct android_poll_source *source;
	unsigned int oldtime, newtime, time;

	app_dummy();

	sys_android_app = app;
	app->inputPollSource.process = Sys_Android_ProcessInput;
	ANativeActivity_setWindowFlags( app->activity, AWINDOW_FLAG_KEEP_SCREEN_ON, 0 ); // flags must be set before window creation

	app->onAppCmd = Sys_Android_WaitOnAppCmd;
	while( !sys_android_initialized )
	{
		Sys_Sleep( 0 );
		while( ( ident = ALooper_pollAll( 0, NULL, &events, ( void ** )( &source ) ) ) >= 0 )
		{
			if ( source )
				source->process( app, source );
		}
	}

	Sys_Android_Init();
	Qcommon_Init( 0, NULL );

	oldtime = Sys_Milliseconds();
	for( ;; )
	{
		if( dedicated && dedicated->integer )
			Sys_Sleep( 1 );

		while( ( ident = ALooper_pollAll( 0, NULL, &events, ( void ** )( &source ) ) ) >= 0 )
		{
			if( source )
				source->process( app, source );
		}

		for( ;; )
		{
			newtime = Sys_Milliseconds();
			time = newtime - oldtime;
			if( time > 0 )
				break;
			Sys_Sleep( 0 );
		}
		oldtime = newtime;

		Sys_Android_ExecuteIntent();
		Qcommon_Frame( time );
	}
}
Beispiel #7
0
void StAndroidGlue::setWindowFlags(const int theFlags) {
    if(myWindowFlags == theFlags) {
        return;
    }

    int aFlagsToAdd    = 0;
    int aFlagsToRemove = 0;
    addOrRemoveFlag(aFlagsToAdd, aFlagsToRemove,
                    myWindowFlags, theFlags,
                    AWINDOW_FLAG_KEEP_SCREEN_ON);
    myWindowFlags = theFlags;

    ANativeActivity_setWindowFlags(myActivity, aFlagsToAdd, aFlagsToRemove);
}
TestActivity::TestActivity (ANativeActivity* activity)
	: RenderActivity	(activity)
	, m_cmdLine			(getIntentStringExtra(activity, "cmdLine"))
	, m_testThread		(*this, m_cmdLine)
	, m_started			(false)
{
	// Set initial orientation.
	setRequestedOrientation(getNativeActivity(), mapScreenRotation(m_cmdLine.getScreenRotation()));

	// Set up window flags.
	ANativeActivity_setWindowFlags(activity, AWINDOW_FLAG_KEEP_SCREEN_ON	|
											 AWINDOW_FLAG_TURN_SCREEN_ON	|
											 AWINDOW_FLAG_FULLSCREEN		|
											 AWINDOW_FLAG_SHOW_WHEN_LOCKED, 0);
}
Beispiel #9
0
gkAndroidApp::gkAndroidApp(android_app* state)
    : m_state(state),
      m_window(NULL) {
    state->userData = this;
    state->onAppCmd = handleCmd;
    state->onInputEvent = handleInput;

    // prepare to monitor accelerometer
    ASensorManager *sensorManager = ASensorManager_getInstance();
    m_accelerometerSensor = ASensorManager_getDefaultSensor(sensorManager,
            ASENSOR_TYPE_ACCELEROMETER);
    m_sensorEventQueue = ASensorManager_createEventQueue(sensorManager,
            state->looper, LOOPER_ID_USER, NULL, NULL);

    ANativeActivity_setWindowFlags(state->activity,
            AWINDOW_FLAG_FULLSCREEN | AWINDOW_FLAG_KEEP_SCREEN_ON, 0);
}
Beispiel #10
0
static GK_BOOL initAndroid(onInitCallback onInit)
{
	int events;
	struct android_poll_source* source;
	
	gkActive = GK_TRUE;
	
	ANativeActivity_setWindowFlags(engine.app->activity, AWINDOW_FLAG_FULLSCREEN, AWINDOW_FLAG_SHOW_WALLPAPER);
		
	while (gkActive && !engine.initialized) {
		if(ALooper_pollAll(-1, 0, &events, (void**)&source) >= 0) {
            if (source != NULL) {
                source->process(engine.app, source);
            }
		}
	}
	
	if(gkActive)
		onInit();

	return GK_TRUE;
}
Beispiel #11
0
void android_main(struct android_app* state) {
    struct engine engine;
    // 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;
     engine.requested_quit=false;
     engine.os=NULL;
     engine.display_active=false;

     FileAccessAndroid::asset_manager=state->activity->assetManager;

     // 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);


	ANativeActivity_setWindowFlags(state->activity,AWINDOW_FLAG_FULLSCREEN|AWINDOW_FLAG_KEEP_SCREEN_ON,0);

	state->activity->vm->AttachCurrentThread(&engine.jni, NULL);



     // 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.

	 int nullmax=50;
	 while ((ident=ALooper_pollAll(engine.animating ? 0 : -1, NULL, &events,
		 (void**)&source)) >= 0) {

	     // Process this event.

	     if (source != NULL) {
	//	 LOGI("process\n");
		 source->process(state, source);
	     } else {
		     nullmax--;
		     if (nullmax<0)
			break;
	     }

	     // If a sensor has data, process it now.
	    // LOGI("events\n");
	     if (ident == LOOPER_ID_USER) {
		 if (engine.accelerometerSensor != NULL) {
		     ASensorEvent event;
		     while (ASensorEventQueue_getEvents(engine.sensorEventQueue,
			     &event, 1) > 0) {


			     if (engine.os) {
				     engine.os->process_accelerometer(Vector3(event.acceleration.x, event.acceleration.y,
									      event.acceleration.z));

			     }

		     }
		 }
	     }

	     // Check if we are exiting.
	     if (state->destroyRequested != 0) {
		     if (engine.os) {
			     engine.os->main_loop_request_quit();
		     }
		    state->destroyRequested=0;
	     }

	     if (engine.requested_quit) {
		engine_term_display(&engine);
		exit(0);
		return;
	     }

//	     LOGI("end\n");


	 }

//	 LOGI("engine animating? %i\n",engine.animating);

	 if (engine.animating) {
	     //do os render

	     engine_draw_frame(&engine);
	     //LOGI("TERM WINDOW");

	 }
     }

}
Beispiel #12
0
void ANativeActivity_onCreate(ANativeActivity* activity, void* savedState, size_t savedStateSize)
{
    // Create an activity states (will keep us in the know, about events we care)
    sf::priv::ActivityStates* states = NULL;
    states = new sf::priv::ActivityStates;

    // Initialize the states value
    states->activity   = NULL;
    states->window     = NULL;
    states->looper     = NULL;
    states->inputQueue = NULL;
    states->config     = NULL;

    for (unsigned int i = 0; i < sf::Mouse::ButtonCount; i++)
        states->isButtonPressed[i] = false;

    states->display = eglGetDisplay(EGL_DEFAULT_DISPLAY);

    if (savedState != NULL)
    {
        states->savedState = malloc(savedStateSize);
        states->savedStateSize = savedStateSize;
        memcpy(states->savedState, savedState, savedStateSize);
    }

    states->mainOver = false;

    states->initialized = false;
    states->terminated = false;

    // Share it across the SFML modules
    sf::priv::getActivity(states, true);

    // These functions will update the activity states and therefore, will allow
    // SFML to be kept in the know
    activity->callbacks->onStart   = onStart;
    activity->callbacks->onResume  = onResume;
    activity->callbacks->onPause   = onPause;
    activity->callbacks->onStop    = onStop;
    activity->callbacks->onDestroy = onDestroy;

    activity->callbacks->onNativeWindowCreated = onNativeWindowCreated;
    activity->callbacks->onNativeWindowDestroyed = onNativeWindowDestroyed;
    activity->callbacks->onNativeWindowRedrawNeeded = onNativeWindowRedrawNeeded;
    activity->callbacks->onNativeWindowResized = onNativeWindowResized;

    activity->callbacks->onInputQueueCreated = onInputQueueCreated;
    activity->callbacks->onInputQueueDestroyed = onInputQueueDestroyed;

    activity->callbacks->onWindowFocusChanged = onWindowFocusChanged;
    activity->callbacks->onContentRectChanged = onContentRectChanged;
    activity->callbacks->onConfigurationChanged = onConfigurationChanged;

    activity->callbacks->onSaveInstanceState = onSaveInstanceState;
    activity->callbacks->onLowMemory = onLowMemory;

    // Share this activity with the callback functions
    states->activity = activity;

    // Keep the screen turned on and bright
    ANativeActivity_setWindowFlags(activity, AWINDOW_FLAG_KEEP_SCREEN_ON,
        AWINDOW_FLAG_KEEP_SCREEN_ON);

    // Initialize the display
    eglInitialize(states->display, NULL, NULL);

    getScreenSizeInPixels(activity, &states->screenSize.x, &states->screenSize.y);

    // Redirect error messages to logcat
    sf::err().rdbuf(&states->logcat);

    // Launch the main thread
    sf::Thread* thread = new sf::Thread(sf::priv::main, states);
    thread->launch();

    // Wait for the main thread to be initialized
    states->mutex.lock();

    while (!states->initialized)
    {
        states->mutex.unlock();
        sf::sleep(sf::milliseconds(20));
        states->mutex.lock();
    }

    states->mutex.unlock();

    // Share this state with the callback functions
    activity->instance = states;
}
Beispiel #13
0
static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
    engine* e = (engine*)app->userData;

    switch (cmd) {

        case APP_CMD_SAVE_STATE:
        	LOGDw("engine_handle_cmd", "APP_CMD_SAVE_STATE");
        	e->app->savedState = malloc(sizeof(struct saved_state));
            *((struct saved_state*)e->app->savedState) = e->state;
            e->app->savedStateSize = sizeof(struct saved_state);
            break;

        case APP_CMD_INIT_WINDOW:
        	LOGDw("engine_handle_cmd", "APP_CMD_INIT_WINDOW");
        	if (e->app->window != NULL) {
				LOGD("call_order", "APP_CMD_INIT_WINDOW");
				first_init(e);
			}
            break;

        case APP_CMD_START:
        	LOGDw("engine_handle_cmd", "APP_CMD_START");
			ANativeActivity_setWindowFlags(app->activity, AWINDOW_FLAG_KEEP_SCREEN_ON, 0);
        	break;

        case APP_CMD_TERM_WINDOW:
        	LOGDw("engine_handle_cmd", "APP_CMD_TERM_WINDOW");
			gles_term_display(&g_sc);
            break;

        case APP_CMD_GAINED_FOCUS:
        	LOGDw("engine_handle_cmd", "APP_CMD_GAINED_FOCUS");
        	kill_all_touch_circles();
        	draw_frame();
        	e->animating = 1;
            break;

        case APP_CMD_LOST_FOCUS:
        	LOGDw("engine_handle_cmd", "APP_CMD_LOST_FOCUS");
        	kill_all_touch_circles();
        	draw_frame();
        	e->animating = 0;
        	if (sles_init_called)wake_from_paused = TRUE;

        	// タッチの円形全部無効スべき
            pause_all_voices();
    		usleep(5000000);
    		shutdown_audio();
//    		join_control_loop();
//    		e->app->destroyRequested = 1; // RvA
            break;

        case APP_CMD_STOP:
        	LOGDw("engine_handle_cmd", "APP_CMD_STOP");
        	break;

        case APP_CMD_DESTROY:
        	LOGDw("engine_handle_cmd", "APP_CMD_DESTROY");
        	break;
    }
}
Beispiel #14
0
void ANativeActivity_onCreate(ANativeActivity* activity, void* savedState, size_t savedStateSize)
{
    // Create an activity states (will keep us in the know, about events we care)
    sf::priv::ActivityStates* states = NULL;
    states = new sf::priv::ActivityStates;

    // Initialize the states value
    states->activity   = NULL;
    states->window     = NULL;
    states->looper     = NULL;
    states->inputQueue = NULL;
    states->config     = NULL;

    for (unsigned int i = 0; i < sf::Mouse::ButtonCount; i++)
        states->isButtonPressed[i] = false;

    states->display = eglGetDisplay(EGL_DEFAULT_DISPLAY);

    // As the input queue will be created before the SFML window, we need to use
    // this dummy function that will be replaced later by the first created
    // SFML window
    states->processEvent = dummyProcessEvent;

    if (savedState != NULL) {
        states->savedState = malloc(savedStateSize);
        states->savedStateSize = savedStateSize;
        memcpy(states->savedState, savedState, savedStateSize);
    }

    states->mainOver = false;

    states->initialized = false;
    states->terminated = false;

    // Share it across the SFML modules
    sf::priv::getActivity(states, true);

    // These functions will update the activity states and therefore, will allow
    // SFML to be kept in the know
    activity->callbacks->onStart   = onStart;
    activity->callbacks->onResume  = onResume;
    activity->callbacks->onPause   = onPause;
    activity->callbacks->onStop    = onStop;
    activity->callbacks->onDestroy = onDestroy;

    activity->callbacks->onNativeWindowCreated = onNativeWindowCreated;
    activity->callbacks->onNativeWindowDestroyed = onNativeWindowDestroyed;
    activity->callbacks->onNativeWindowRedrawNeeded = onNativeWindowRedrawNeeded;
    activity->callbacks->onNativeWindowResized = onNativeWindowResized;

    activity->callbacks->onInputQueueCreated = onInputQueueCreated;
    activity->callbacks->onInputQueueDestroyed = onInputQueueDestroyed;

    activity->callbacks->onWindowFocusChanged = onWindowFocusChanged;
    activity->callbacks->onContentRectChanged = onContentRectChanged;
    activity->callbacks->onConfigurationChanged = onConfigurationChanged;

    activity->callbacks->onSaveInstanceState = onSaveInstanceState;
    activity->callbacks->onLowMemory = onLowMemory;

    // Share this activity with the callback functions
    states->activity = activity;

    // Keep the screen turned on and bright
    ANativeActivity_setWindowFlags(activity, AWINDOW_FLAG_KEEP_SCREEN_ON,
        AWINDOW_FLAG_KEEP_SCREEN_ON);

    // Hide the status bar
    ANativeActivity_setWindowFlags(activity, AWINDOW_FLAG_FULLSCREEN,
        AWINDOW_FLAG_FULLSCREEN);

    // Hide the navigation bar
    JavaVM* lJavaVM = activity->vm;
    JNIEnv* lJNIEnv = activity->env;

    jobject objectActivity = activity->clazz;
    jclass classActivity = lJNIEnv->GetObjectClass(objectActivity);

    jmethodID methodGetWindow = lJNIEnv->GetMethodID(classActivity, "getWindow", "()Landroid/view/Window;");
    jobject objectWindow = lJNIEnv->CallObjectMethod(objectActivity, methodGetWindow);

    jclass classWindow = lJNIEnv->FindClass("android/view/Window");
    jmethodID methodGetDecorView = lJNIEnv->GetMethodID(classWindow, "getDecorView", "()Landroid/view/View;");
    jobject objectDecorView = lJNIEnv->CallObjectMethod(objectWindow, methodGetDecorView);

    jclass classView = lJNIEnv->FindClass("android/view/View");

    jfieldID FieldSYSTEM_UI_FLAG_HIDE_NAVIGATION = lJNIEnv->GetStaticFieldID(classView, "SYSTEM_UI_FLAG_HIDE_NAVIGATION", "I");
    jint SYSTEM_UI_FLAG_HIDE_NAVIGATION = lJNIEnv->GetStaticIntField(classView, FieldSYSTEM_UI_FLAG_HIDE_NAVIGATION);

    jfieldID FieldSYSTEM_UI_FLAG_FULLSCREEN = lJNIEnv->GetStaticFieldID(classView, "SYSTEM_UI_FLAG_FULLSCREEN", "I");
    jint SYSTEM_UI_FLAG_FULLSCREEN = lJNIEnv->GetStaticIntField(classView, FieldSYSTEM_UI_FLAG_FULLSCREEN);

    jmethodID methodsetSystemUiVisibility = lJNIEnv->GetMethodID(classView, "setSystemUiVisibility", "(I)V");
    lJNIEnv->CallVoidMethod(objectDecorView, methodsetSystemUiVisibility, SYSTEM_UI_FLAG_HIDE_NAVIGATION | SYSTEM_UI_FLAG_FULLSCREEN);

    // Initialize the display
    eglInitialize(states->display, NULL, NULL);

    // Launch the main thread
    sf::Thread* thread = new sf::Thread(sf::priv::main, states);
    thread->launch();

    // Wait for the main thread to be initialized
    states->mutex.lock();

    while (!states->initialized)
    {
        states->mutex.unlock();
        sf::sleep(sf::milliseconds(20));
        states->mutex.lock();
    }

    states->mutex.unlock();

    // Share this state with the callback functions
    activity->instance = states;
}
void ANativeActivity_onCreate(ANativeActivity* activity,
      void* savedState, size_t savedStateSize)
{
   int msgpipe[2];
   struct android_app* android_app;

   (void)savedState;
   (void)savedStateSize;

   RARCH_LOG("Creating Native Activity: %p\n", activity);
   activity->callbacks->onDestroy = onDestroy;
   activity->callbacks->onStart = onStart;
   activity->callbacks->onResume = onResume;
   activity->callbacks->onSaveInstanceState = NULL;
   activity->callbacks->onPause = onPause;
   activity->callbacks->onStop = onStop;
   activity->callbacks->onConfigurationChanged = onConfigurationChanged;
   activity->callbacks->onLowMemory = NULL;
   activity->callbacks->onWindowFocusChanged = onWindowFocusChanged;
   activity->callbacks->onNativeWindowCreated = onNativeWindowCreated;
   activity->callbacks->onNativeWindowDestroyed = onNativeWindowDestroyed;
   activity->callbacks->onInputQueueCreated = onInputQueueCreated;
   activity->callbacks->onInputQueueDestroyed = onInputQueueDestroyed;

   // these are set only for the native activity, and are reset when it ends
   ANativeActivity_setWindowFlags(activity, AWINDOW_FLAG_KEEP_SCREEN_ON | AWINDOW_FLAG_FULLSCREEN, 0);

   if (pthread_key_create(&thread_key, jni_thread_destruct))
      RARCH_ERR("Error initializing pthread_key\n");

   android_app = (struct android_app*)calloc(1, sizeof(*android_app));
   if (!android_app)
   {
      RARCH_ERR("Failed to initialize android_app\n");
      return;
   }

   memset(android_app, 0, sizeof(struct android_app));
   android_app->activity = activity;

   android_app->mutex = (slock_t*)slock_new();
   android_app->cond  = (scond_t*)scond_new();

   if (pipe(msgpipe))
   {
      RARCH_ERR("could not create pipe: %s.\n", strerror(errno));
      activity->instance = NULL;
   }
   android_app->msgread = msgpipe[0];
   android_app->msgwrite = msgpipe[1];

   android_app->thread = (sthread_t*)sthread_create(android_app_entry, android_app);

   // Wait for thread to start.
   slock_lock(android_app->mutex);
   while (!android_app->running)
      scond_wait(android_app->cond, android_app->mutex);
   slock_unlock(android_app->mutex);

   activity->instance = android_app;
}