Bug 1391342 - Keep toolbar hidding while showing keyboard in full screen. r?jchen,sebastian draft
authorNevin Chen(:nechen) <cnevinchen@gmail.com>
Fri, 06 Oct 2017 11:33:14 +0800
changeset 678941 4aad02756c07c8eb63877f4037a703567dc97ff2
parent 678457 a72bd6160609be2fa471be5f87955bdd47fafe22
child 735470 3e75094f99135214a41470b739c98aee08671d92
push id84075
push userbmo:cnevinchen@gmail.com
push dateThu, 12 Oct 2017 02:49:07 +0000
reviewersjchen, sebastian
bugs1391342
milestone58.0a1
Bug 1391342 - Keep toolbar hidding while showing keyboard in full screen. r?jchen,sebastian MozReview-Commit-ID: 7GLvOB3TyuK
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoInputConnection.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/ActivityUtils.java
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoInputConnection.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoInputConnection.java
@@ -3,26 +3,26 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko;
 
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
-import java.util.concurrent.SynchronousQueue;
 
 import org.mozilla.gecko.gfx.DynamicToolbarAnimator;
+import org.mozilla.gecko.util.ActivityUtils;
 import org.mozilla.gecko.util.Clipboard;
 import org.mozilla.gecko.util.GamepadUtils;
 import org.mozilla.gecko.util.ThreadUtils;
-import org.mozilla.gecko.util.ThreadUtils.AssertBehavior;
 
 import android.annotation.SuppressLint;
 import android.annotation.TargetApi;
+import android.app.Activity;
 import android.content.Context;
 import android.content.res.Configuration;
 import android.graphics.Matrix;
 import android.graphics.RectF;
 import android.media.AudioManager;
 import android.os.Build;
 import android.os.Handler;
 import android.os.Looper;
@@ -212,17 +212,17 @@ class GeckoInputConnection
         View view = getView();
         if (view == null) {
             return null;
         }
         Context context = view.getContext();
         return InputMethods.getInputMethodManager(context);
     }
 
-    private void showSoftInput() {
+    private void showSoftInputWithToolbar(final boolean showToolbar) {
         if (mSoftInputReentrancyGuard) {
             return;
         }
         final View v = getView();
         final InputMethodManager imm = getInputMethodManager();
         if (v == null || imm == null) {
             return;
         }
@@ -232,17 +232,17 @@ class GeckoInputConnection
             public void run() {
                 if (v.hasFocus() && !imm.isActive(v)) {
                     // Marshmallow workaround: The view has focus but it is not the active
                     // view for the input method. (Bug 1211848)
                     v.clearFocus();
                     v.requestFocus();
                 }
                 final GeckoView view = getView();
-                if (view != null) {
+                if (view != null && showToolbar) {
                     view.getDynamicToolbarAnimator().showToolbar(/*immediately*/ true);
                 }
                 mSoftInputReentrancyGuard = true;
                 imm.showSoftInput(v, 0);
                 mSoftInputReentrancyGuard = false;
             }
         });
     }
@@ -647,19 +647,22 @@ class GeckoInputConnection
             outAttrs.initialSelEnd = 0;
             return mKeyInputConnection;
         }
         Editable editable = getEditable();
         outAttrs.initialSelStart = Selection.getSelectionStart(editable);
         outAttrs.initialSelEnd = Selection.getSelectionEnd(editable);
 
         if (mIsUserAction) {
-            showSoftInput();
+            if ((context instanceof Activity) && ActivityUtils.isFullScreen((Activity) context)) {
+                showSoftInputWithToolbar(false);
+            } else {
+                showSoftInputWithToolbar(true);
+            }
         }
-
         return this;
     }
 
     private boolean replaceComposingSpanWithSelection() {
         final Editable content = getEditable();
         if (content == null) {
             return false;
         }
@@ -935,17 +938,17 @@ class GeckoInputConnection
                 break;
 
             case NOTIFY_IME_OF_BLUR:
                 // Showing/hiding vkb is done in notifyIMEContext
                 mFocused = false;
                 break;
 
             case NOTIFY_IME_OPEN_VKB:
-                showSoftInput();
+                showSoftInputWithToolbar(false);
                 break;
 
             case GeckoEditableListener.NOTIFY_IME_TO_COMMIT_COMPOSITION: {
                 // Gecko already committed its composition. However, Android keyboards
                 // have trouble dealing with us removing the composition manually on the
                 // Java side. Therefore, we keep the composition intact on the Java side.
                 // The text content should still be in-sync on both sides.
                 //
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/ActivityUtils.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/ActivityUtils.java
@@ -32,16 +32,18 @@ public class ActivityUtils {
                         View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
                         View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
                         View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
                         View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
             } else {
                 newVis |= View.SYSTEM_UI_FLAG_LOW_PROFILE;
             }
         } else {
+            // no need to prevent status bar to appear when exiting full screen
+            preventDisplayStatusbar(activity, false);
             newVis = View.SYSTEM_UI_FLAG_VISIBLE;
         }
 
         if (AppConstants.Versions.feature23Plus) {
             // We also have to set SYSTEM_UI_FLAG_LIGHT_STATUS_BAR with to current system ui status
             // to support both light and dark status bar.
             final int oldVis = window.getDecorView().getSystemUiVisibility();
             newVis |= (oldVis & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
@@ -72,9 +74,26 @@ public class ActivityUtils {
         while (context instanceof ContextWrapper) {
             if (context instanceof Activity) {
                 return (Activity) context;
             }
             context = ((ContextWrapper) context).getBaseContext();
         }
         return null;
     }
+
+    public static void preventDisplayStatusbar(final Activity activity, boolean registering) {
+        final View decorView = activity.getWindow().getDecorView();
+        if (registering) {
+            decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
+                @Override
+                public void onSystemUiVisibilityChange(int visibility) {
+                    if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
+                        setFullScreen(activity, true);
+                    }
+                }
+            });
+        } else {
+            decorView.setOnSystemUiVisibilityChangeListener(null);
+        }
+
+    }
 }