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
--- 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