Browse Source

properly detect whether we are in "fullscreen" (i.e. immersive) on Android

fysx 10 years ago
parent
commit
c30e788393

+ 18 - 0
jni/love/src/common/android.cpp

@@ -49,6 +49,24 @@ void setImmersive (bool immersive_active) {
 	env->DeleteLocalRef (clazz);
 	env->DeleteLocalRef (clazz);
 }
 }
 
 
+bool getImmersive () {
+	JNIEnv *env = (JNIEnv*) SDL_AndroidGetJNIEnv();
+
+	jobject activity = (jobject) SDL_AndroidGetActivity();
+
+	jclass clazz (env->GetObjectClass(activity));
+	jmethodID method_id = env->GetMethodID (clazz, "getImmersiveMode", "()Z");
+
+	jboolean immersive_active = env->CallBooleanMethod (activity, method_id);
+
+	env->DeleteLocalRef (activity);
+	env->DeleteLocalRef (clazz);
+
+	if (immersive_active)
+		return true;
+	return false;
+}
+
 double getScreenScale()
 double getScreenScale()
 {
 {
   static double result = -1.;
   static double result = -1.;

+ 4 - 0
jni/love/src/common/android.h

@@ -32,7 +32,11 @@ namespace love
 namespace android
 namespace android
 {
 {
 
 
+/**
+ * Enables or disables immersive mode where the navigation bar is hidden.
+ **/
 void setImmersive (bool immersive_active);
 void setImmersive (bool immersive_active);
+bool getImmersive ();
 
 
 /**
 /**
  * Gets the scale factor of the window's screen, e.g. on Retina displays this
  * Gets the scale factor of the window's screen, e.g. on Retina displays this

+ 8 - 4
jni/love/src/modules/window/sdl/Window.cpp

@@ -442,6 +442,10 @@ void Window::updateSettings(const WindowSettings &newsettings)
 		curMode.settings.fstype = newsettings.fstype;
 		curMode.settings.fstype = newsettings.fstype;
 	}
 	}
 
 
+#ifdef LOVE_ANDROID
+	curMode.settings.fullscreen = love::android::getImmersive();
+#endif
+
 	// The min width/height is set to 0 internally in SDL when in fullscreen.
 	// The min width/height is set to 0 internally in SDL when in fullscreen.
 	if (curMode.settings.fullscreen)
 	if (curMode.settings.fullscreen)
 	{
 	{
@@ -518,6 +522,10 @@ bool Window::setFullscreen(bool fullscreen, Window::FullscreenType fstype)
 		}
 		}
 	}
 	}
 
 
+#ifdef LOVE_ANDROID
+	love::android::setImmersive(fullscreen);
+#endif
+
 	if (SDL_SetWindowFullscreen(window, sdlflags) == 0)
 	if (SDL_SetWindowFullscreen(window, sdlflags) == 0)
 	{
 	{
 		SDL_GL_MakeCurrent(window, context);
 		SDL_GL_MakeCurrent(window, context);
@@ -535,10 +543,6 @@ bool Window::setFullscreen(bool fullscreen, Window::FullscreenType fstype)
 			SDL_GL_GetDrawableSize(window, &width, &height);
 			SDL_GL_GetDrawableSize(window, &width, &height);
 #endif
 #endif
 
 
-#ifdef LOVE_ANDROID
-			love::android::setImmersive(fullscreen);
-#endif
-
 			gfx->setViewportSize(width, height);
 			gfx->setViewportSize(width, height);
 		}
 		}
 
 

+ 4 - 0
src/org/love2d/android/GameActivity.java

@@ -143,6 +143,10 @@ public class GameActivity extends SDLActivity {
       };
       };
     }
     }
 
 
+    public boolean getImmersiveMode () {
+      return immersiveActive;
+    }
+
     public static String getGamePath() {
     public static String getGamePath() {
       Log.d ("GameActivity", "called getGamePath(), game path = " + gamePath);
       Log.d ("GameActivity", "called getGamePath(), game path = " + gamePath);
       return gamePath;
       return gamePath;