Bug 1081153 - Consolidate BaseGeckoInterface/GeckoApp.setFullScreen() (r=mfinkle)
authorLucas Rocha <lucasr@lucasr.org>
Fri, 10 Oct 2014 17:01:52 +0100
changeset 209790 03fd3fb2d48c9b5bde4a141f054e8c109ad6c823
parent 209789 433cb9e553e117c9d3c46c43774a2b819866788a
child 209791 9b598425c7cb675c1673ff33c8e1e1a9f15a8b4b
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersmfinkle
bugs1081153
milestone35.0a1
Bug 1081153 - Consolidate BaseGeckoInterface/GeckoApp.setFullScreen() (r=mfinkle)
mobile/android/base/BaseGeckoInterface.java
mobile/android/base/GeckoApp.java
mobile/android/base/moz.build
mobile/android/base/util/ActivityUtils.java
--- a/mobile/android/base/BaseGeckoInterface.java
+++ b/mobile/android/base/BaseGeckoInterface.java
@@ -2,16 +2,17 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * 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 org.mozilla.gecko.AppConstants.Versions;
 import org.mozilla.gecko.prompts.PromptService;
+import org.mozilla.gecko.util.ActivityUtils;
 import org.mozilla.gecko.util.HardwareUtils;
 import org.mozilla.gecko.util.ThreadUtils;
 
 import android.app.Activity;
 import android.content.Context;
 import android.graphics.RectF;
 import android.hardware.SensorEventListener;
 import android.location.LocationListener;
@@ -68,34 +69,17 @@ public class BaseGeckoInterface implemen
 
     // Bug 908775: Implement this
     public void doRestart() {}
 
     public void setFullScreen(final boolean fullscreen) {
         ThreadUtils.postToUiThread(new Runnable() {
             @Override
             public void run() {
-                // Hide/show the system notification bar
-                Window window = getActivity().getWindow();
-
-                if (Versions.feature11Plus) {
-                    final int newVis;
-                    if (fullscreen) {
-                        newVis = View.SYSTEM_UI_FLAG_FULLSCREEN |
-                                 View.SYSTEM_UI_FLAG_LOW_PROFILE;
-                    } else {
-                        newVis = View.SYSTEM_UI_FLAG_VISIBLE;
-                    }
-
-                    window.getDecorView().setSystemUiVisibility(newVis);
-                } else {
-                    window.setFlags(fullscreen ?
-                                    WindowManager.LayoutParams.FLAG_FULLSCREEN : 0,
-                                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
-                }
+                ActivityUtils.setFullScreen(getActivity(), fullscreen);
             }
         });
     }
 
     // Bug 908779: Implement this
     public void addPluginView(final View view, final RectF rect, final boolean isFullScreen) {}
 
     // Bug 908781: Implement this
--- a/mobile/android/base/GeckoApp.java
+++ b/mobile/android/base/GeckoApp.java
@@ -42,16 +42,17 @@ import org.mozilla.gecko.menu.GeckoMenuI
 import org.mozilla.gecko.menu.MenuPanel;
 import org.mozilla.gecko.mozglue.GeckoLoader;
 import org.mozilla.gecko.preferences.ClearOnShutdownPref;
 import org.mozilla.gecko.preferences.GeckoPreferences;
 import org.mozilla.gecko.prompts.PromptService;
 import org.mozilla.gecko.updater.UpdateService;
 import org.mozilla.gecko.updater.UpdateServiceHelper;
 import org.mozilla.gecko.util.ActivityResultHandler;
+import org.mozilla.gecko.util.ActivityUtils;
 import org.mozilla.gecko.util.EventCallback;
 import org.mozilla.gecko.util.FileUtils;
 import org.mozilla.gecko.util.GeckoEventListener;
 import org.mozilla.gecko.util.HardwareUtils;
 import org.mozilla.gecko.util.NativeEventListener;
 import org.mozilla.gecko.util.NativeJSObject;
 import org.mozilla.gecko.util.PrefUtils;
 import org.mozilla.gecko.util.StringUtils;
@@ -98,17 +99,16 @@ import android.view.MenuItem;
 import android.view.MotionEvent;
 import android.view.OrientationEventListener;
 import android.view.SurfaceHolder;
 import android.view.SurfaceView;
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.ViewStub;
 import android.view.Window;
-import android.view.WindowManager;
 import android.widget.AbsoluteLayout;
 import android.widget.FrameLayout;
 import android.widget.ListView;
 import android.widget.RelativeLayout;
 import android.widget.SimpleAdapter;
 import android.widget.TextView;
 import android.widget.Toast;
 
@@ -1070,34 +1070,17 @@ public abstract class GeckoApp
 
         requestRender();
     }
 
     public void setFullScreen(final boolean fullscreen) {
         ThreadUtils.postToUiThread(new Runnable() {
             @Override
             public void run() {
-                // Hide/show the system notification bar
-                Window window = getWindow();
-
-                if (Versions.feature11Plus) {
-                    final int newVis;
-                    if (fullscreen) {
-                        newVis = View.SYSTEM_UI_FLAG_FULLSCREEN |
-                                 View.SYSTEM_UI_FLAG_LOW_PROFILE;
-                    } else {
-                        newVis = View.SYSTEM_UI_FLAG_VISIBLE;
-                    }
-
-                    window.getDecorView().setSystemUiVisibility(newVis);
-                } else {
-                    window.setFlags(fullscreen ?
-                                    WindowManager.LayoutParams.FLAG_FULLSCREEN : 0,
-                                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
-                }
+                ActivityUtils.setFullScreen(GeckoApp.this, fullscreen);
             }
         });
     }
 
     /**
      * Check and start the Java profiler if MOZ_PROFILER_STARTUP env var is specified.
      **/
     protected static void earlyStartJavaSampler(Intent intent) {
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -42,16 +42,17 @@ mgjar.generated_sources += [
     'org/mozilla/gecko/mozglue/GeckoLoader.java',
 ]
 mgjar.javac_flags += ['-Xlint:all']
 
 gujar = add_java_jar('gecko-util')
 gujar.sources += [
     'util/ActivityResultHandler.java',
     'util/ActivityResultHandlerMap.java',
+    'util/ActivityUtils.java',
     'util/Clipboard.java',
     'util/EventCallback.java',
     'util/FileUtils.java',
     'util/FloatUtils.java',
     'util/GamepadUtils.java',
     'util/GeckoBackgroundThread.java',
     'util/GeckoEventListener.java',
     'util/GeckoJarReader.java',
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/util/ActivityUtils.java
@@ -0,0 +1,39 @@
+/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * 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.util;
+
+import android.app.Activity;
+import android.view.View;
+import android.view.Window;
+import android.view.WindowManager;
+
+import org.mozilla.gecko.AppConstants.Versions;
+
+public class ActivityUtils {
+    private ActivityUtils() {
+    }
+
+    public static void setFullScreen(Activity activity, boolean fullscreen) {
+        // Hide/show the system notification bar
+        Window window = activity.getWindow();
+
+        if (Versions.feature11Plus) {
+            final int newVis;
+            if (fullscreen) {
+                newVis = View.SYSTEM_UI_FLAG_FULLSCREEN |
+                         View.SYSTEM_UI_FLAG_LOW_PROFILE;
+            } else {
+                newVis = View.SYSTEM_UI_FLAG_VISIBLE;
+            }
+
+            window.getDecorView().setSystemUiVisibility(newVis);
+        } else {
+            window.setFlags(fullscreen ?
+                            WindowManager.LayoutParams.FLAG_FULLSCREEN : 0,
+                            WindowManager.LayoutParams.FLAG_FULLSCREEN);
+        }
+    }
+}