Bug 1202752 - Prevent the android utility tray from opening r=fabrice
authorsgiles <sgiles@mozilla.com>
Fri, 30 Oct 2015 16:25:16 +0000
changeset 306555 3e4883a63febdc44ab7a1fe6c49d97b3e1e85f9b
parent 306554 515f1bf1eb54340c5f8f4b42568c1813244e09da
child 306556 af48e0ddc57af62103789a84271ac68ae5268b96
push id7160
push usergarndt@mozilla.com
push dateWed, 04 Nov 2015 22:20:12 +0000
reviewersfabrice
bugs1202752
milestone45.0a1
Bug 1202752 - Prevent the android utility tray from opening r=fabrice
mobile/android/b2gdroid/app/src/main/java/org/mozilla/b2gdroid/Launcher.java
--- a/mobile/android/b2gdroid/app/src/main/java/org/mozilla/b2gdroid/Launcher.java
+++ b/mobile/android/b2gdroid/app/src/main/java/org/mozilla/b2gdroid/Launcher.java
@@ -4,22 +4,27 @@
 
 package org.mozilla.b2gdroid;
 
 import java.util.Date;
 
 import android.content.Context;
 import android.content.Intent;
 import android.content.SharedPreferences;
+import android.graphics.PixelFormat;
 import android.location.Location;
 import android.location.LocationListener;
 import android.os.Bundle;
 import android.support.v4.app.FragmentActivity;
 import android.util.Log;
+
+import android.view.Gravity;
+import android.view.MotionEvent;
 import android.view.View;
+import android.view.WindowManager;
 
 import org.json.JSONObject;
 import org.json.JSONException;
 
 import org.mozilla.gecko.BaseGeckoInterface;
 import org.mozilla.gecko.ContactService;
 import org.mozilla.gecko.ContextGetter;
 import org.mozilla.gecko.EventDispatcher;
@@ -42,16 +47,18 @@ public class Launcher extends FragmentAc
 
     private ContactService        mContactService;
     private ScreenStateObserver   mScreenStateObserver;
     private Apps                  mApps;
     private SettingsMapper        mSettings;
     private GeckoEventReceiver    mGeckoEventReceiver;
     private RemoteGeckoEventProxy mGeckoEventProxy;
 
+    private View mDisableStatusBarView = null;
+
     private static final long   kHomeRepeat = 2;
     private static final long   kHomeDelay  = 500; // delay in ms to tap kHomeRepeat times.
     private long                mFirstHome;
     private long                mLastHome;
     private long                mHomeCount;
 
     final class GeckoInterface extends BaseGeckoInterface
                                implements LocationListener {
@@ -105,16 +112,56 @@ public class Launcher extends FragmentAc
         final View splash = findViewById(R.id.splashscreen);
         runOnUiThread(new Runnable() {
             @Override public void run() {
                 splash.setVisibility(View.GONE);
             }
         });
     }
 
+    private View getStatusBarOverlay() {
+        if (mDisableStatusBarView != null) {
+            return mDisableStatusBarView;
+        }
+
+        mDisableStatusBarView = new View(this);
+
+        mDisableStatusBarView.setOnTouchListener(new View.OnTouchListener() {
+            public boolean onTouch(View view, MotionEvent ev) {
+                // Pass the touch event down to the GeckoView
+                Launcher.this.findViewById(R.id.gecko_view).dispatchTouchEvent(ev);
+                return true;
+            }
+        });
+
+        WindowManager.LayoutParams handleParams = new WindowManager.LayoutParams(
+                // Fill the width of the screen
+                WindowManager.LayoutParams.FILL_PARENT,
+                // Arbitrary value to cover the edge of the top of the screen to interrupt the gesture.
+                // This value was found through trial and error on a large screen L and a Z3C on KK
+                25,
+                // display over everything
+                WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
+                // Prevent events from capturing in other views beneath this
+                // one
+                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
+                // Allows the View to receive touch events so we can pass them
+                // to Gecko
+                WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
+                // Draw over status bar area
+                WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
+                // Draw transparent
+                PixelFormat.TRANSPARENT);
+
+        handleParams.gravity = Gravity.TOP;
+        WindowManager manager = ((WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE));
+        manager.addView(mDisableStatusBarView, handleParams);
+        return mDisableStatusBarView;
+    }
+
     /** Called when the activity is first created. */
     @Override
     public void onCreate(Bundle savedInstanceState) {
         Log.w(LOGTAG, "onCreate");
         super.onCreate(savedInstanceState);
 
         IntentHelper.init(this);
         mScreenStateObserver = new ScreenStateObserver(this);
@@ -134,16 +181,19 @@ public class Launcher extends FragmentAc
             "Launcher:Ready");
 
         // Register the RemoteGeckoEventProxy with the Notification Opened
         // event, Notifications are handled in a different process as a
         // service, so we need to forward them to the remote service
         EventDispatcher.getInstance().registerGeckoThreadListener(mGeckoEventProxy,
             "Android:NotificationOpened");
 
+        // Initialize status bar overlay
+        getStatusBarOverlay();
+
         setContentView(R.layout.launcher);
 
         mHomeCount = 0;
         mFirstHome = 0;
         mLastHome = 0;
     }
 
     @Override
@@ -223,21 +273,24 @@ public class Launcher extends FragmentAc
     }
 
     @Override
     public void onWindowFocusChanged(boolean hasFocus) {
         Log.d(LOGTAG, "onWindowFocusChanged hasFocus=" + hasFocus);
 
         super.onWindowFocusChanged(hasFocus);
         if (hasFocus) {
+            getStatusBarOverlay().setVisibility(View.VISIBLE);
             findViewById(R.id.main_layout).setSystemUiVisibility(
                      View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                     | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                     | View.SYSTEM_UI_FLAG_FULLSCREEN
                     );
+        } else {
+            getStatusBarOverlay().setVisibility(View.INVISIBLE);
         }
     }
 
     public void handleMessage(String event, JSONObject message) {
         Log.w(LOGTAG, "Launcher received " + event);
 
         if ("Launcher:Ready".equals(event)) {
             hideSplashScreen();