Bug 1207421 - Find a way to access the gaia task switcher r=reuben
authorFabrice Desré <fabrice@mozilla.com>
Fri, 23 Oct 2015 08:57:55 -0700
changeset 304420 db77be9081cb74dd91903d29bbe0ee8bd7bca14c
parent 304419 01d6ea8fe74391ff5b9240ec02f655972f006149
child 304421 656b3bacca783c85c1eb5564cdbbadd27abc5e1f
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersreuben
bugs1207421
milestone44.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1207421 - Find a way to access the gaia task switcher r=reuben
mobile/android/b2gdroid/app/src/main/java/org/mozilla/b2gdroid/Launcher.java
mobile/android/b2gdroid/components/MessagesBridge.jsm
--- 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
@@ -1,14 +1,16 @@
 /* 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.b2gdroid;
 
+import java.util.Date;
+
 import android.app.Activity;
 import android.app.ActivityManager;
 import android.app.KeyguardManager;
 import android.app.KeyguardManager.KeyguardLock;
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.SharedPreferences;
@@ -40,16 +42,22 @@ public class Launcher extends FragmentAc
                       implements GeckoEventListener, ContextGetter {
     private static final String LOGTAG = "B2G";
 
     private ContactService      mContactService;
     private ScreenStateObserver mScreenStateObserver;
     private Apps                mApps;
     private SettingsMapper      mSettings;
 
+    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;
+
     /** ContextGetter */
     public Context getContext() {
         return this;
     }
 
     public SharedPreferences getSharedPreferences() {
         return null;
     }
@@ -92,16 +100,20 @@ public class Launcher extends FragmentAc
         GeckoAppShell.setGeckoInterface(new BaseGeckoInterface(this));
 
         UpdateServiceHelper.registerForUpdates(this);
 
         EventDispatcher.getInstance().registerGeckoThreadListener(this,
             "Launcher:Ready");
 
         setContentView(R.layout.launcher);
+
+        mHomeCount = 0;
+        mFirstHome = 0;
+        mLastHome = 0;
     }
 
     @Override
     public void onResume() {
         super.onResume();
         if (GeckoThread.isRunning()) {
             hideSplashScreen();
         }
@@ -134,20 +146,39 @@ public class Launcher extends FragmentAc
                 obj.put("action", "view");
                 obj.put("url", intent.getDataString());
             } catch(Exception ex) {
                 Log.wtf(LOGTAG, "Error building Android:Launcher view message", ex);
             }
             GeckoEvent e = GeckoEvent.createBroadcastEvent("Android:Launcher", obj.toString());
             GeckoAppShell.sendEventToGecko(e);
         } else if (Intent.ACTION_MAIN.equals(action)) {
-            Log.d(LOGTAG, "Let's dispatch a 'home' key event");
+            String message = "home-key";
+
+            // Check if we did a multiple home tap to trigger the task switcher.
+            long now = (new Date()).getTime();
+            if (now - mLastHome > kHomeDelay) {
+                mHomeCount = 0;
+            }
+            if (mHomeCount == 0) {
+                mFirstHome = now;
+            }
+            mHomeCount++;
+            if (mHomeCount == kHomeRepeat) {
+                mHomeCount = 0;
+                if (now - mFirstHome < kHomeDelay) {
+                    message = "task-switcher";
+                }
+            }
+            mLastHome = now;
+
+            Log.d(LOGTAG, "Let's dispatch a '" + message + "' key event");
             JSONObject obj = new JSONObject();
             try {
-                obj.put("action", "home-key");
+                obj.put("action", message);
             } catch(JSONException ex) {
                 Log.wtf(LOGTAG, "Error building Android:Launcher message", ex);
             }
             GeckoEvent e = GeckoEvent.createBroadcastEvent("Android:Launcher", obj.toString());
             GeckoAppShell.sendEventToGecko(e);
         }
     }
 
--- a/mobile/android/b2gdroid/components/MessagesBridge.jsm
+++ b/mobile/android/b2gdroid/components/MessagesBridge.jsm
@@ -64,16 +64,19 @@ this.MessagesBridge = {
         let a = new window.MozActivity({ name: "view",
                                          data: { type: "url",
                                                  url: data.url } });
         break;
       case "home-key":
         window.dispatchEvent(new window.KeyboardEvent("keydown", { key: "Home" }));
         window.dispatchEvent(new window.KeyboardEvent("keyup", { key: "Home" }));
         break;
+      case "task-switcher":
+        window.dispatchEvent(new window.CustomEvent("taskmanagershow", {}));
+        break;
     }
   },
 
   onAndroidSetting: function(aSubject, aTopic, aData) {
     let data = JSON.parse(aData);
     let lock = settings.createLock();
     let key = Object.keys(data)[0];
     debug(`Got Android:Setting message ${key} -> ${data[key]}`);