Deal with situations where the system UI is shown when the keyboard pops up (thanks Rachel!)
authorSam Lantinga <slouken@libsdl.org>
Mon, 18 Jun 2018 13:13:58 -0700
changeset 12022b1de5ecf0c99
parent 12021 3239c8ad2986
child 12023 842dd960769e
Deal with situations where the system UI is shown when the keyboard pops up (thanks Rachel!)
android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
     1.1 --- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java	Mon Jun 18 13:13:56 2018 -0700
     1.2 +++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java	Mon Jun 18 13:13:58 2018 -0700
     1.3 @@ -33,7 +33,7 @@
     1.4  /**
     1.5      SDL Activity
     1.6  */
     1.7 -public class SDLActivity extends Activity {
     1.8 +public class SDLActivity extends Activity implements View.OnSystemUiVisibilityChangeListener {
     1.9      private static final String TAG = "SDL";
    1.10  
    1.11      public static boolean mIsResumedCalled, mIsSurfaceReady, mHasFocus;
    1.12 @@ -251,6 +251,8 @@
    1.13  
    1.14          setWindowStyle(false);
    1.15  
    1.16 +        getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(this);
    1.17 +
    1.18          // Get filename from "Open with" of another application
    1.19          Intent intent = getIntent();
    1.20          if (intent != null && intent.getData() != null) {
    1.21 @@ -489,12 +491,14 @@
    1.22                                          View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
    1.23                                          View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
    1.24                                          View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
    1.25 -					View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
    1.26 +                    					View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.INVISIBLE;
    1.27                              window.getDecorView().setSystemUiVisibility(flags);        
    1.28                              window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    1.29 +                            window.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    1.30                          } else {
    1.31 -                            int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
    1.32 -                            window.getDecorView().setSystemUiVisibility(flags);        
    1.33 +                            int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_VISIBLE;
    1.34 +                            window.getDecorView().setSystemUiVisibility(flags);
    1.35 +                            window.addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    1.36                              window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    1.37                          }
    1.38                      }
    1.39 @@ -1110,6 +1114,32 @@
    1.40          return dialog;
    1.41      }
    1.42  
    1.43 +    private final Runnable rehideSystemUi = new Runnable() {
    1.44 +        @Override
    1.45 +        public void run() {
    1.46 +            int flags = View.SYSTEM_UI_FLAG_FULLSCREEN |
    1.47 +                        View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
    1.48 +                        View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
    1.49 +                        View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
    1.50 +                        View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
    1.51 +                        View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.INVISIBLE;
    1.52 +
    1.53 +            SDLActivity.this.getWindow().getDecorView().setSystemUiVisibility(flags);
    1.54 +        }
    1.55 +    };
    1.56 +
    1.57 +    public void onSystemUiVisibilityChange(int visibility) {
    1.58 +        if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0 || (visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0) {
    1.59 +
    1.60 +            Handler handler = getWindow().getDecorView().getHandler();
    1.61 +            if (handler != null) {
    1.62 +                handler.removeCallbacks(rehideSystemUi); // Prevent a hide loop.
    1.63 +                handler.postDelayed(rehideSystemUi, 2000);
    1.64 +            }
    1.65 +
    1.66 +        }
    1.67 +    }    
    1.68 +
    1.69      /**
    1.70       * This method is called by SDL using JNI.
    1.71       */