Deal with situations where the system UI is shown when the keyboard pops up (thanks Rachel!)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
index 6fcb5c0..2a16300 100644
--- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
+++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
@@ -33,7 +33,7 @@ import android.content.pm.ApplicationInfo;
/**
SDL Activity
*/
-public class SDLActivity extends Activity {
+public class SDLActivity extends Activity implements View.OnSystemUiVisibilityChangeListener {
private static final String TAG = "SDL";
public static boolean mIsResumedCalled, mIsSurfaceReady, mHasFocus;
@@ -251,6 +251,8 @@ public class SDLActivity extends Activity {
setWindowStyle(false);
+ getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(this);
+
// Get filename from "Open with" of another application
Intent intent = getIntent();
if (intent != null && intent.getData() != null) {
@@ -489,12 +491,14 @@ public class SDLActivity extends Activity {
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
- View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
+ View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.INVISIBLE;
window.getDecorView().setSystemUiVisibility(flags);
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
+ window.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
} else {
- int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
- window.getDecorView().setSystemUiVisibility(flags);
+ int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_VISIBLE;
+ window.getDecorView().setSystemUiVisibility(flags);
+ window.addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}
@@ -1110,6 +1114,32 @@ public class SDLActivity extends Activity {
return dialog;
}
+ private final Runnable rehideSystemUi = new Runnable() {
+ @Override
+ public void run() {
+ int flags = View.SYSTEM_UI_FLAG_FULLSCREEN |
+ View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
+ View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
+ View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
+ View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
+ View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.INVISIBLE;
+
+ SDLActivity.this.getWindow().getDecorView().setSystemUiVisibility(flags);
+ }
+ };
+
+ public void onSystemUiVisibilityChange(int visibility) {
+ if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0 || (visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0) {
+
+ Handler handler = getWindow().getDecorView().getHandler();
+ if (handler != null) {
+ handler.removeCallbacks(rehideSystemUi); // Prevent a hide loop.
+ handler.postDelayed(rehideSystemUi, 2000);
+ }
+
+ }
+ }
+
/**
* This method is called by SDL using JNI.
*/