Bug 1357780 - CustomTabs get rid of dark theme
Now we only use Light theme, and its look and feel more close to
Full-Browser. Hopefully when we re-use gecko widgets will have less
visual issue.
In ActionBar, the tint color follows text color. And the text color is
decided by Top toolbar background.
MozReview-Commit-ID: JrFAdLmk3Fk
--- a/mobile/android/base/java/org/mozilla/gecko/customtabs/ActionBarPresenter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/customtabs/ActionBarPresenter.java
@@ -2,16 +2,17 @@
* 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.content.res.Resources;
import android.content.res.TypedArray;
+import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Handler;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
@@ -53,28 +54,30 @@ public class ActionBarPresenter {
private final TextView mUrlView;
private final Handler mHandler = new Handler();
private Runnable mUpdateAction;
@ColorInt
private int mTextPrimaryColor = DEFAULT_TEXT_PRIMARY_COLOR;
- ActionBarPresenter(@NonNull final ActionBar actionBar) {
+ ActionBarPresenter(@NonNull final ActionBar actionBar, @ColorInt final int textColor) {
+ mTextPrimaryColor = textColor;
mActionBar = actionBar;
mActionBar.setDisplayShowCustomEnabled(true);
mActionBar.setDisplayShowTitleEnabled(false);
mActionBar.setCustomView(R.layout.customtabs_action_bar_custom_view);
final View customView = mActionBar.getCustomView();
mIconView = (ImageButton) customView.findViewById(R.id.custom_tabs_action_bar_icon);
mTitleView = (TextView) customView.findViewById(R.id.custom_tabs_action_bar_title);
mUrlView = (TextView) customView.findViewById(R.id.custom_tabs_action_bar_url);
- onThemeChanged(mActionBar.getThemedContext().getTheme());
+ mTitleView.setTextColor(mTextPrimaryColor);
+ mUrlView.setTextColor(mTextPrimaryColor);
mIdentityPopup = new SiteIdentityPopup(mActionBar.getThemedContext());
mIdentityPopup.setAnchor(customView);
mIconView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mIdentityPopup.show();
}
@@ -224,18 +227,9 @@ public class ActionBarPresenter {
mUrlView.setText(null);
mUrlView.setVisibility(View.GONE);
} else {
mTitleView.setText(title);
mUrlView.setText(url);
mUrlView.setVisibility(View.VISIBLE);
}
}
-
- private void onThemeChanged(@NonNull final Resources.Theme currentTheme) {
- // Theme might be light or dark. To get text color for custom-view.
- final TypedArray themeArray = currentTheme.obtainStyledAttributes(
- new int[]{android.R.attr.textColorPrimary});
-
- mTextPrimaryColor = themeArray.getColor(0, DEFAULT_TEXT_PRIMARY_COLOR);
- themeArray.recycle();
- }
}
--- a/mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
+++ b/mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
@@ -5,24 +5,23 @@
package org.mozilla.gecko.customtabs;
import android.app.PendingIntent;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.Bitmap;
-import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Browser;
+import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
-import android.support.annotation.StyleRes;
import android.support.design.widget.Snackbar;
import android.support.v4.util.SparseArrayCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.view.ActionMode;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
@@ -34,17 +33,16 @@ import android.widget.ProgressBar;
import org.mozilla.gecko.EventDispatcher;
import org.mozilla.gecko.R;
import org.mozilla.gecko.SingleTabActivity;
import org.mozilla.gecko.SnackbarBuilder;
import org.mozilla.gecko.Tab;
import org.mozilla.gecko.Tabs;
import org.mozilla.gecko.Telemetry;
import org.mozilla.gecko.TelemetryContract;
-import org.mozilla.gecko.gfx.DynamicToolbarAnimator;
import org.mozilla.gecko.gfx.DynamicToolbarAnimator.PinReason;
import org.mozilla.gecko.menu.GeckoMenu;
import org.mozilla.gecko.menu.GeckoMenuInflater;
import org.mozilla.gecko.mozglue.SafeIntent;
import org.mozilla.gecko.util.Clipboard;
import org.mozilla.gecko.util.ColorUtil;
import org.mozilla.gecko.util.GeckoBundle;
import org.mozilla.gecko.util.IntentUtils;
@@ -70,27 +68,25 @@ public class CustomTabsActivity extends
private MenuItem menuItemControl;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final SafeIntent intent = new SafeIntent(getIntent());
- setThemeFromToolbarColor();
-
doorhangerOverlay = findViewById(R.id.custom_tabs_doorhanger_overlay);
mProgressView = (ProgressBar) findViewById(R.id.page_progress);
final Toolbar toolbar = (Toolbar) findViewById(R.id.actionbar);
setSupportActionBar(toolbar);
final ActionBar actionBar = getSupportActionBar();
bindNavigationCallback(toolbar);
- actionBarPresenter = new ActionBarPresenter(actionBar);
+ actionBarPresenter = new ActionBarPresenter(actionBar, getActionBarTextColor());
actionBarPresenter.displayUrlOnly(intent.getDataString());
actionBarPresenter.setBackgroundColor(IntentUtil.getToolbarColor(intent), getWindow());
actionBarPresenter.setTextLongClickListener(new UrlCopyListener());
Tabs.registerOnTabsChangedListener(this);
}
@Override
@@ -137,23 +133,19 @@ public class CustomTabsActivity extends
data.putString("client", host);
} else {
data.putString("client", "unknown");
}
// Pass a message to Gecko to send Telemetry data
EventDispatcher.getInstance().dispatch("Telemetry:CustomTabsPing", data);
}
- private void setThemeFromToolbarColor() {
- final int color = ColorUtil.getReadableTextColor(IntentUtil.getToolbarColor(new SafeIntent(getIntent())));
- @StyleRes final int styleRes = (color == Color.BLACK)
- ? R.style.GeckoCustomTabs_Light
- : R.style.GeckoCustomTabs;
-
- setTheme(styleRes);
+ @ColorInt
+ private int getActionBarTextColor() {
+ return ColorUtil.getReadableTextColor(IntentUtil.getToolbarColor(new SafeIntent(getIntent())));
}
// 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
@@ -120,23 +120,17 @@
</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">
- <item name="menuItemActionBarStyle">@style/Widget.MenuItemActionBar</item>
- <item name="menuItemDefaultStyle">@style/Widget.MenuItemCustomTabs</item>
- <item name="windowActionModeOverlay">true</item>
- </style>
-
- <style name="GeckoCustomTabs.Light" parent="Theme.AppCompat.Light.NoActionBar">
+ <style name="GeckoCustomTabs" parent="Theme.AppCompat.Light.NoActionBar">
<item name="menuItemActionBarStyle">@style/Widget.MenuItemActionBar</item>
<item name="menuItemDefaultStyle">@style/Widget.MenuItemCustomTabs</item>
<item name="windowActionModeOverlay">true</item>
</style>
<!-- Bookmark full-page dialog theme -->
<style name="Bookmark" parent="Theme.AppCompat.Light.DialogWhenLarge"/>
<style name="Bookmark.Gecko" parent="Gecko">