mirror of
https://github.com/SFML/SFML.git
synced 2025-01-19 15:55:13 +08:00
[Android] Hide status and navigation bar only if the fullscreen flag is on
This commit is contained in:
parent
73008293ba
commit
57ca180d8d
@ -113,6 +113,42 @@ void* main(ActivityStates* states)
|
|||||||
} // namespace sf
|
} // 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)
|
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::priv::ActivityStates* states = sf::priv::retrieveStates(activity);
|
||||||
sf::Lock lock(states->mutex);
|
sf::Lock lock(states->mutex);
|
||||||
|
|
||||||
|
if (states->fullscreen)
|
||||||
|
goToFullscreenMode(activity);
|
||||||
|
|
||||||
// Send an event to warn people the activity has been resumed
|
// Send an event to warn people the activity has been resumed
|
||||||
sf::Event event;
|
sf::Event event;
|
||||||
event.type = sf::Event::MouseEntered;
|
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,
|
ANativeActivity_setWindowFlags(activity, AWINDOW_FLAG_KEEP_SCREEN_ON,
|
||||||
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
|
// Initialize the display
|
||||||
eglInitialize(states->display, NULL, NULL);
|
eglInitialize(states->display, NULL, NULL);
|
||||||
|
|
||||||
|
@ -73,6 +73,8 @@ struct ActivityStates
|
|||||||
bool initialized;
|
bool initialized;
|
||||||
bool terminated;
|
bool terminated;
|
||||||
|
|
||||||
|
bool fullscreen;
|
||||||
|
|
||||||
bool updated;
|
bool updated;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user