Bug 1276696 - Add CustomTabsActivity based on GeckoApp. r?mcomella draft
authorSebastian Kaspari <s.kaspari@gmail.com>
Wed, 25 May 2016 19:58:17 +0200
changeset 378041 2524bee928744af46f374854219f61d4d389f52d
parent 378040 dc34035e535bc3c357f1a9c709ea4085ca9aed1a
child 378042 0ef81b106911778d5736b15151c004a04527f499
push id20919
push users.kaspari@gmail.com
push dateTue, 14 Jun 2016 12:28:54 +0000
reviewersmcomella
bugs1276696
milestone50.0a1
Bug 1276696 - Add CustomTabsActivity based on GeckoApp. r?mcomella This activity doesn't do much yet and just has a layout including a GeckoView. Some basic behavior from GeckoApp is working though: Context menus, floating text selection, snackbars. MozReview-Commit-ID: C6SJeYz609h
mobile/android/base/AndroidManifest.xml.in
mobile/android/base/java/org/mozilla/gecko/LauncherActivity.java
mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
mobile/android/base/moz.build
mobile/android/base/resources/layout/customtabs_activity.xml
--- a/mobile/android/base/AndroidManifest.xml.in
+++ b/mobile/android/base/AndroidManifest.xml.in
@@ -289,16 +289,19 @@
             <intent-filter>
                 <action android:name="android.intent.action.SEND" />
                 <category android:name="android.intent.category.DEFAULT" />
                 <data android:mimeType="text/plain" />
             </intent-filter>
 
         </activity>
 
+        <activity android:name="org.mozilla.gecko.customtabs.CustomTabsActivity"
+            android:theme="@style/Theme.AppCompat.NoActionBar" />
+
         <!-- Service to handle requests from overlays. -->
         <service android:name="org.mozilla.gecko.overlays.service.OverlayActionService" />
 
         <!--
           Ensure that passwords provider runs in its own process. (Bug 718760.)
           Process name is per-application to avoid loading CPs from multiple
           Fennec versions into the same process. (Bug 749727.)
           Process name is a mangled version to avoid a Talos bug. (Bug 750548.)
--- a/mobile/android/base/java/org/mozilla/gecko/LauncherActivity.java
+++ b/mobile/android/base/java/org/mozilla/gecko/LauncherActivity.java
@@ -3,33 +3,36 @@
  * 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 android.app.Activity;
 import android.content.Intent;
 import android.os.Bundle;
-import android.text.TextUtils;
+import android.support.customtabs.CustomTabsIntent;
 
+import org.mozilla.gecko.customtabs.CustomTabsActivity;
 import org.mozilla.gecko.db.BrowserContract;
 import org.mozilla.gecko.tabqueue.TabQueueHelper;
 import org.mozilla.gecko.tabqueue.TabQueueService;
 
 /**
  * Activity that receives incoming Intents and dispatches them to the appropriate activities (e.g. browser, custom tabs, web app).
  */
 public class LauncherActivity extends Activity {
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
         GeckoAppShell.ensureCrashHandling();
 
-        if (isViewIntent()) {
+        if (isCustomTabsIntent()) {
+            dispatchCustomTabsIntent();
+        } else if (isViewIntentWithURL()) {
             dispatchViewIntent();
         } else {
             dispatchNormalIntent();
         }
 
         finish();
     }
 
@@ -59,13 +62,26 @@ public class LauncherActivity extends Ac
      * Launch the browser activity.
      */
     private void dispatchNormalIntent() {
         Intent intent = new Intent(getIntent());
         intent.setClassName(getApplicationContext(), AppConstants.MOZ_ANDROID_BROWSER_INTENT_CLASS);
         startActivity(intent);
     }
 
-    private boolean isViewIntent() {
-        final String action = getIntent().getAction();
-        return Intent.ACTION_VIEW.equals(action);
+    private void dispatchCustomTabsIntent() {
+        Intent intent = new Intent(getIntent());
+        intent.setClassName(getApplicationContext(), CustomTabsActivity.class.getName());
+        startActivity(intent);
+    }
+
+    private boolean isViewIntentWithURL() {
+        final Intent intent = getIntent();
+
+        return Intent.ACTION_VIEW.equals(intent.getAction())
+                && intent.getDataString() != null;
+    }
+
+    private boolean isCustomTabsIntent() {
+        return isViewIntentWithURL()
+                && getIntent().hasExtra(CustomTabsIntent.EXTRA_SESSION);
     }
 }
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
@@ -0,0 +1,23 @@
+/* -*- 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.customtabs;
+
+import android.os.Bundle;
+
+import org.mozilla.gecko.GeckoApp;
+import org.mozilla.gecko.R;
+
+public class CustomTabsActivity extends GeckoApp {
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+    }
+
+    @Override
+    public int getLayout() {
+        return R.layout.customtabs_activity;
+    }
+}
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -219,16 +219,17 @@ gbjar.sources += ['java/org/mozilla/geck
     'BrowserApp.java',
     'BrowserLocaleManager.java',
     'cleanup/FileCleanupController.java',
     'cleanup/FileCleanupService.java',
     'ContactService.java',
     'ContextGetter.java',
     'CrashHandler.java',
     'CustomEditText.java',
+    'customtabs/CustomTabsActivity.java',
     'DataReportingNotification.java',
     'db/AbstractPerProfileDatabaseProvider.java',
     'db/AbstractTransactionalProvider.java',
     'db/BaseTable.java',
     'db/BrowserDatabaseHelper.java',
     'db/BrowserDB.java',
     'db/BrowserProvider.java',
     'db/DBUtils.java',
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/resources/layout/customtabs_activity.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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/. -->
+
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/root_layout"
+    android:orientation="vertical"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent">
+
+    <!--
+        This layout is quite complex because GeckoApp accesses all view groups
+        in this tree. In a perfect world this should just include a GeckoView.
+    -->
+
+    <view class="org.mozilla.gecko.GeckoApp$MainLayout"
+        android:id="@+id/main_layout"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:background="@android:color/transparent">
+
+        <RelativeLayout android:id="@+id/gecko_layout"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:layout_below="@+id/tablet_tab_strip"
+            android:layout_above="@+id/find_in_page">
+
+            <org.mozilla.gecko.GeckoView android:id="@+id/layer_view"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:scrollbars="none"/>
+
+        </RelativeLayout>
+
+    </view>
+
+</RelativeLayout>
\ No newline at end of file