Bug 1315937 - add theme to CustomTabsActivity draft
authorJulian_Chu <walkingice0204@gmail.com>
Wed, 01 Mar 2017 11:43:35 +0800
changeset 494469 316c27bc21488c727ac3e429b6bcc2cb390442cd
parent 491797 f27d1e685d54f9c882fba3891985b251a975ab3e
child 494470 f67c582e86c58ff0c5b423f9b7a7059bd1c13b3b
child 494473 be41b19afed3812b2b9c33503d4a7f60b8b2604b
child 497289 5071e2e45489726fd51b8efb3b850df1776635e5
push id48033
push userbmo:walkingice0204@gmail.com
push dateTue, 07 Mar 2017 04:08:35 +0000
bugs1315937
milestone54.0a1
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
mobile/android/base/AndroidManifest.xml.in
mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
mobile/android/base/resources/values/themes.xml
--- 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>