Bug 1315937 - add theme to CustomTabsActivity
CustomTabsActivity is usually be used by 3rd-party apps. Its look and
feel is usually different from GeckoApp. To give separated themes to
ensure any change to CustomTabs won't effect GeckoApp.
MozReview-Commit-ID: 7aBnnPXv3nQ
--- a/mobile/android/base/AndroidManifest.xml.in
+++ b/mobile/android/base/AndroidManifest.xml.in
@@ -307,17 +307,17 @@
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
#ifdef MOZ_ANDROID_CUSTOM_TABS
<activity android:name="org.mozilla.gecko.customtabs.CustomTabsActivity"
- android:theme="@style/Theme.AppCompat.NoActionBar" />
+ android:theme="@style/GeckoCustomTabs" />
#endif
<!-- 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
--- a/mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
+++ b/mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
@@ -9,16 +9,17 @@ import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
+import android.support.annotation.StyleRes;
import android.support.annotation.VisibleForTesting;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@@ -96,26 +97,26 @@ public class CustomTabsActivity extends
finish();
}
});
Tabs.registerOnTabsChangedListener(this);
}
private void setThemeFromToolbarColor() {
- if (toolbarColor == NO_COLOR) {
- return;
+ // default theme, regardless AndroidManifest.
+ @StyleRes int styleRes = R.style.GeckoCustomTabs;
+
+ if (toolbarColor != NO_COLOR) {
+ styleRes = (ColorUtil.getReadableTextColor(toolbarColor) == Color.BLACK)
+ ? R.style.GeckoCustomTabs_Light
+ : R.style.GeckoCustomTabs;
}
- if (ColorUtil.getReadableTextColor(toolbarColor) == Color.BLACK) {
- setTheme(R.style.Theme_AppCompat_Light_NoActionBar);
- } else {
- setTheme(R.style.Theme_AppCompat_NoActionBar);
- }
-
+ setTheme(styleRes);
}
// Bug 1329145: 3rd party app could specify customized exit-animation to this activity.
// Activity.overridePendingTransition will invoke getPackageName to retrieve that animation resource.
// In that case, to return different package name to get customized animation resource.
@Override
public String getPackageName() {
if (usingCustomAnimation) {
--- a/mobile/android/base/resources/values/themes.xml
+++ b/mobile/android/base/resources/values/themes.xml
@@ -114,9 +114,20 @@
<!-- Set the app's title bar color in the recent app switcher.
Note: We'd prefer not to show up in the recent app switcher (bug 1137928). -->
<item name="android:colorPrimary">@color/text_and_tabs_tray_grey</item>
<!-- We display the overlay on top of other Activities so show their status bar. -->
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
+ <!--
+ Themes for CustomTabsActivity. Since CustomTabsActivity usually be used by 3-rd party apps,
+ to create separated themes to keep look and feel be consistent with ordinary Android app.
+ And ensure changes to CustomTabsActivity won't effect GeckoApp.
+ -->
+ <style name="GeckoCustomTabs" parent="Theme.AppCompat.NoActionBar">
+ </style>
+
+ <style name="GeckoCustomTabs.Light" parent="Theme.AppCompat.Light.NoActionBar">
+ </style>
+
</resources>