From 1da86e673f2109f6fa68291f81eea806c9df0c7d Mon Sep 17 00:00:00 2001 From: Jing-wei Wu Date: Fri, 25 Aug 2017 16:24:18 +0800 Subject: [PATCH] Bug 1390735 - Support tint color for page action button. r=nechen,sebastian,walkingice Use tint to provide two colors for page action icon in normal/private mode. We would not tint icons that already have their own colors(for example: ic_readermode_on.png or casting_active.png) or are came from 3-party addons. MozReview-Commit-ID: 8uuMucKGLw5 --HG-- extra : rebase_source : 7d213e2b96fab8389b2b2c69e1fdb8ecfe569f20 extra : intermediate-source : ee7c5cecab194ae54317d77de05b2e2f84e1122e extra : source : a97a2b9700a27e944691536adec6112451ff1f24 --- .../src/photon/res/color/page_action_fg.xml | 14 ++++++++++++++ .../gecko/toolbar/PageActionLayout.java | 18 +++++++++++++++--- mobile/android/chrome/content/CastingApps.js | 6 ++++-- mobile/android/chrome/content/Reader.js | 9 +++++---- mobile/android/chrome/content/browser.js | 1 + mobile/android/modules/PageActions.jsm | 3 ++- 6 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 mobile/android/app/src/photon/res/color/page_action_fg.xml diff --git a/mobile/android/app/src/photon/res/color/page_action_fg.xml b/mobile/android/app/src/photon/res/color/page_action_fg.xml new file mode 100644 index 000000000000..928460cd7727 --- /dev/null +++ b/mobile/android/app/src/photon/res/color/page_action_fg.xml @@ -0,0 +1,14 @@ + + + + + + + + + + diff --git a/mobile/android/base/java/org/mozilla/gecko/toolbar/PageActionLayout.java b/mobile/android/base/java/org/mozilla/gecko/toolbar/PageActionLayout.java index 2d3b667199a0..59eca0de637d 100644 --- a/mobile/android/base/java/org/mozilla/gecko/toolbar/PageActionLayout.java +++ b/mobile/android/base/java/org/mozilla/gecko/toolbar/PageActionLayout.java @@ -7,6 +7,7 @@ package org.mozilla.gecko.toolbar; import org.mozilla.gecko.EventDispatcher; import org.mozilla.gecko.R; +import org.mozilla.gecko.util.DrawableUtil; import org.mozilla.gecko.util.ResourceDrawableUtils; import org.mozilla.gecko.util.BundleEventListener; import org.mozilla.gecko.util.EventCallback; @@ -17,8 +18,10 @@ import org.mozilla.gecko.widget.themed.ThemedImageButton; import org.mozilla.gecko.widget.themed.ThemedLinearLayout; import android.content.Context; +import android.content.res.ColorStateList; import android.content.res.Resources; import android.graphics.drawable.Drawable; +import android.support.v4.content.ContextCompat; import android.util.AttributeSet; import android.view.Menu; import android.view.MenuItem; @@ -108,8 +111,9 @@ public class PageActionLayout extends ThemedLinearLayout implements BundleEventL final String title = message.getString("title"); final String imageURL = message.getString("icon"); final boolean important = message.getBoolean("important"); + final boolean useTint = message.getBoolean("useTint"); - addPageAction(id, title, imageURL, new OnPageActionClickListeners() { + addPageAction(id, title, imageURL, useTint, new OnPageActionClickListeners() { @Override public void onClick(final String id) { final GeckoBundle data = new GeckoBundle(1); @@ -131,7 +135,7 @@ public class PageActionLayout extends ThemedLinearLayout implements BundleEventL } } - private void addPageAction(final String id, final String title, final String imageData, + private void addPageAction(final String id, final String title, final String imageData, final boolean useTint, final OnPageActionClickListeners onPageActionClickListeners, boolean important) { ThreadUtils.assertOnUiThread(); @@ -147,7 +151,15 @@ public class PageActionLayout extends ThemedLinearLayout implements BundleEventL @Override public void onBitmapFound(final Drawable d) { if (mPageActionList.contains(pageAction)) { - pageAction.setDrawable(d); + final Drawable icon; + if (useTint) { + final ColorStateList colorStateList = ContextCompat.getColorStateList( + getContext(), R.color.page_action_fg); + icon = DrawableUtil.tintDrawableWithStateList(d, colorStateList); + } else { + icon = d; + } + pageAction.setDrawable(icon); refreshPageActionIcons(); } } diff --git a/mobile/android/chrome/content/CastingApps.js b/mobile/android/chrome/content/CastingApps.js index 734b4e2c22ea..2f8675bc44ca 100644 --- a/mobile/android/chrome/content/CastingApps.js +++ b/mobile/android/chrome/content/CastingApps.js @@ -558,14 +558,16 @@ var CastingApps = { title: Strings.browser.GetStringFromName("contextmenu.sendToDevice"), icon: "drawable://casting_active", clickCallback: this.pageAction.click, - important: true + important: true, + useTint: false }); } else if (aVideo.mozAllowCasting) { this.pageAction.id = PageActions.add({ title: Strings.browser.GetStringFromName("contextmenu.sendToDevice"), icon: "drawable://casting", clickCallback: this.pageAction.click, - important: true + important: true, + useTint: true }); } }, diff --git a/mobile/android/chrome/content/Reader.js b/mobile/android/chrome/content/Reader.js index 02fec47f38f0..e3ecd56b1411 100644 --- a/mobile/android/chrome/content/Reader.js +++ b/mobile/android/chrome/content/Reader.js @@ -168,18 +168,19 @@ var Reader = { delete this.pageAction.id; } - let showPageAction = (icon, title) => { + let showPageAction = (icon, title, useTint) => { this.pageAction.id = PageActions.add({ icon: icon, title: title, clickCallback: () => this.pageAction.readerModeCallback(browser), - important: true + important: true, + useTint: useTint }); }; let browser = tab.browser; if (browser.currentURI.spec.startsWith("about:reader")) { - showPageAction("drawable://ic_readermode_on", Strings.reader.GetStringFromName("readerView.close")); + showPageAction("drawable://ic_readermode_on", Strings.reader.GetStringFromName("readerView.close"), false); // Only start a reader session if the viewer is in the foreground. We do // not track background reader viewers. UITelemetry.startSession("reader.1", null); @@ -193,7 +194,7 @@ var Reader = { UITelemetry.stopSession("reader.1", "", null); if (browser.isArticle) { - showPageAction("drawable://ic_readermode", Strings.reader.GetStringFromName("readerView.enter")); + showPageAction("drawable://ic_readermode", Strings.reader.GetStringFromName("readerView.enter"), true); UITelemetry.addEvent("show.1", "button", null, "reader_available"); this._sendMmaEvent("reader_available"); } else { diff --git a/mobile/android/chrome/content/browser.js b/mobile/android/chrome/content/browser.js index c2838a5aa21f..55db083f0ea1 100644 --- a/mobile/android/chrome/content/browser.js +++ b/mobile/android/chrome/content/browser.js @@ -6630,6 +6630,7 @@ var ExternalApps = { this._pageActionId = PageActions.add({ title: Strings.browser.GetStringFromName("openInApp.pageAction"), icon: "drawable://icon_openinapp", + useTint: true, clickCallback: () => { UITelemetry.addEvent("launch.1", "pageaction", null, "helper"); diff --git a/mobile/android/modules/PageActions.jsm b/mobile/android/modules/PageActions.jsm index d381aa6028c3..c2d293964430 100644 --- a/mobile/android/modules/PageActions.jsm +++ b/mobile/android/modules/PageActions.jsm @@ -88,7 +88,8 @@ var PageActions = { id: id, title: aOptions.title, icon: resolveGeckoURI(aOptions.icon), - important: "important" in aOptions ? aOptions.important : false + important: "important" in aOptions ? aOptions.important : false, + useTint: "useTint" in aOptions ? aOptions.useTint : false }); this._items[id] = {};