[Android] Hide status and navigation bar only if the fullscreen flag is on

This commit is contained in:
Jonathan De Wachter 2014-06-26 07:32:44 +02:00
parent 73008293ba
commit 57ca180d8d
4 changed files with 58 additions and 46 deletions

View File

@ -113,6 +113,42 @@ void* main(ActivityStates* states)
} // namespace sf
////////////////////////////////////////////////////////////
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);
}
////////////////////////////////////////////////////////////
void getScreenSizeInPixels(ANativeActivity* activity, int* width, int* height)
@ -164,6 +200,9 @@ static void onResume(ANativeActivity* activity)
sf::priv::ActivityStates* states = sf::priv::retrieveStates(activity);
sf::Lock lock(states->mutex);
if (states->fullscreen)
goToFullscreenMode(activity);
// Send an event to warn people the activity has been resumed
sf::Event event;
event.type = sf::Event::MouseEntered;
@ -441,35 +480,6 @@ void ANativeActivity_onCreate(ANativeActivity* activity, void* savedState, size_
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);

View File

@ -73,6 +73,8 @@ struct ActivityStates
bool initialized;
bool terminated;
bool fullscreen;
bool updated;
};

View File

@ -190,7 +190,7 @@ int WindowImplAndroid::processEvent(int fd, int events, void* data)
{
if (AInputQueue_preDispatchEvent(states->inputQueue, _event))
return 1;
int32_t handled = 0;
int32_t type = AInputEvent_getType(_event);
@ -207,7 +207,7 @@ int WindowImplAndroid::processEvent(int fd, int events, void* data)
else if (type == AINPUT_EVENT_TYPE_MOTION)
{
int32_t action = AMotionEvent_getAction(_event);
switch (action & AMOTION_EVENT_ACTION_MASK)
{
case AMOTION_EVENT_ACTION_SCROLL:
@ -215,7 +215,7 @@ int WindowImplAndroid::processEvent(int fd, int events, void* data)
processScrollEvent(_event, states);
break;
}
case AMOTION_EVENT_ACTION_HOVER_MOVE:
case AMOTION_EVENT_ACTION_MOVE:
{
@ -283,7 +283,7 @@ void WindowImplAndroid::processScrollEvent(AInputEvent* _event, ActivityStates*
jfloat yPrecision = AMotionEvent_getYPrecision(_event);
jint deviceId = AInputEvent_getDeviceId(_event);
jint edgeFlags = AMotionEvent_getEdgeFlags(_event);
// Create the MotionEvent object in java trough its static constructor obtain()
jclass ClassMotionEvent = lJNIEnv->FindClass("android/view/MotionEvent");
jmethodID StaticMethodObtain = lJNIEnv->GetStaticMethodID(ClassMotionEvent, "obtain", "(JJIFFFFIFFII)Landroid/view/MotionEvent;");
@ -312,7 +312,7 @@ void WindowImplAndroid::processKeyEvent(AInputEvent* _event, ActivityStates* sta
{
int32_t device = AInputEvent_getSource(_event);
int32_t action = AKeyEvent_getAction(_event);
int32_t key = AKeyEvent_getKeyCode(_event);
int32_t metakey = AKeyEvent_getMetaState(_event);
@ -342,26 +342,26 @@ void WindowImplAndroid::processMotionEvent(AInputEvent* _event, ActivityStates*
int32_t action = AMotionEvent_getAction(_event);
Event event;
if (device == AINPUT_SOURCE_MOUSE)
event.type = Event::MouseMoved;
else if (device == AINPUT_SOURCE_TOUCHSCREEN)
event.type = Event::TouchMoved;
int pointerCount = AMotionEvent_getPointerCount(_event);
for (int p = 0; p < pointerCount; p++)
{
int id = AMotionEvent_getPointerId(_event, p);
float x = AMotionEvent_getX(_event, p);
float y = AMotionEvent_getY(_event, p);
if (device == AINPUT_SOURCE_MOUSE)
{
event.mouseMove.x = x;
event.mouseMove.y = y;
states->mousePosition = Vector2i(event.mouseMove.x, event.mouseMove.y);
}
else if (device == AINPUT_SOURCE_TOUCHSCREEN)
@ -372,7 +372,7 @@ void WindowImplAndroid::processMotionEvent(AInputEvent* _event, ActivityStates*
event.touch.finger = id;
event.touch.x = x;
event.touch.y = y;
states->touchEvents[id] = Vector2i(event.touch.x, event.touch.y);
}
@ -386,13 +386,13 @@ void WindowImplAndroid::processPointerEvent(bool isDown, AInputEvent* _event, Ac
{
int32_t device = AInputEvent_getSource(_event);
int32_t action = AMotionEvent_getAction(_event);
int index = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
int id = AMotionEvent_getPointerId(_event, index);
float x = AMotionEvent_getX(_event, index);
float y = AMotionEvent_getY(_event, index);
Event event;
if (isDown)
@ -403,7 +403,7 @@ void WindowImplAndroid::processPointerEvent(bool isDown, AInputEvent* _event, Ac
event.mouseButton.button = static_cast<Mouse::Button>(id);
event.mouseButton.x = x;
event.mouseButton.y = y;
if (id >= 0 && id < Mouse::ButtonCount)
states->isButtonPressed[id] = true;
}
@ -413,7 +413,7 @@ void WindowImplAndroid::processPointerEvent(bool isDown, AInputEvent* _event, Ac
event.touch.finger = id;
event.touch.x = x;
event.touch.y = y;
states->touchEvents[id] = Vector2i(event.touch.x, event.touch.y);
}
}
@ -425,7 +425,7 @@ void WindowImplAndroid::processPointerEvent(bool isDown, AInputEvent* _event, Ac
event.mouseButton.button = static_cast<Mouse::Button>(id);
event.mouseButton.x = x;
event.mouseButton.y = y;
if (id >= 0 && id < Mouse::ButtonCount)
states->isButtonPressed[id] = false;
}
@ -435,7 +435,7 @@ void WindowImplAndroid::processPointerEvent(bool isDown, AInputEvent* _event, Ac
event.touch.finger = id;
event.touch.x = x;
event.touch.y = y;
states->touchEvents.erase(id);
}
}

View File

@ -190,7 +190,7 @@ private:
///
////////////////////////////////////////////////////////////
static Keyboard::Key androidKeyToSF(int32_t key);
////////////////////////////////////////////////////////////
/// \brief Get unicode decoded from the input event
///