зеркало из https://github.com/mozilla/gecko-dev.git
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
This commit is contained in:
Родитель
f68e87377c
Коммит
1da86e673f
|
@ -0,0 +1,14 @@
|
|||
<?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/. -->
|
||||
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:gecko="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item android:color="@color/menu_item_tint_private"
|
||||
gecko:state_private="true"/>
|
||||
|
||||
<item android:color="@color/menu_item_tint"/>
|
||||
|
||||
</selector>
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
});
|
||||
}
|
||||
},
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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] = {};
|
||||
|
|
Загрузка…
Ссылка в новой задаче