| Index: chrome/android/java/src/org/chromium/chrome/browser/preferences/website/WebsitePreference.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/website/WebsitePreference.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/website/WebsitePreference.java
|
| index e9a4364be758bc2b76dc54369975c38b6da119ec..4adf8896c9eaad8234aa48d236b0c026df910f39 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/preferences/website/WebsitePreference.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/website/WebsitePreference.java
|
| @@ -5,13 +5,21 @@
|
| package org.chromium.chrome.browser.preferences.website;
|
|
|
| import android.content.Context;
|
| +import android.graphics.Bitmap;
|
| +import android.graphics.drawable.BitmapDrawable;
|
| +import android.net.Uri;
|
| import android.preference.Preference;
|
| import android.view.View;
|
| import android.widget.ImageView;
|
| +import android.widget.LinearLayout;
|
| import android.widget.TextView;
|
|
|
| import org.chromium.base.annotations.SuppressFBWarnings;
|
| import org.chromium.chrome.R;
|
| +import org.chromium.chrome.browser.favicon.FaviconHelper;
|
| +import org.chromium.chrome.browser.favicon.FaviconHelper.FaviconImageCallback;
|
| +import org.chromium.chrome.browser.profiles.Profile;
|
| +import org.chromium.chrome.browser.widget.RoundedIconGenerator;
|
|
|
| import java.text.DecimalFormat;
|
| import java.text.NumberFormat;
|
| @@ -22,13 +30,27 @@ import java.text.NumberFormat;
|
| * access the site has.)
|
| */
|
| @SuppressFBWarnings("EQ_COMPARETO_USE_OBJECT_EQUALS")
|
| -class WebsitePreference extends Preference {
|
| +class WebsitePreference extends Preference implements FaviconImageCallback {
|
| private final Website mSite;
|
| private final String mCategoryFilter;
|
| private final WebsiteSettingsCategoryFilter mFilter;
|
|
|
| private static final int TEXT_SIZE_SP = 13;
|
|
|
| + // Loads the favicons asynchronously.
|
| + private FaviconHelper mFaviconHelper;
|
| +
|
| + // Whether the favicon has been fetched already.
|
| + private boolean mFaviconFetched = false;
|
| +
|
| + // Metrics for favicon processing.
|
| + private static final int FAVICON_CORNER_RADIUS_DP = 2;
|
| + private static final int FAVICON_SIZE_DP = 16;
|
| + private static final int FAVICON_TEXT_SIZE_SP = 10;
|
| + private static final int FAVICON_BACKGROUND_COLOR = 0xff969696;
|
| + private static final int FAVICON_PARENT_MINWIDTH_DP = 55;
|
| + private static final int FAVICON_PARENT_PADDING_DP = 12;
|
| +
|
| WebsitePreference(Context context, Website site, String categoryFilter) {
|
| super(context);
|
| mSite = site;
|
| @@ -49,6 +71,39 @@ class WebsitePreference extends Preference {
|
| return mSite;
|
| }
|
|
|
| + @Override
|
| + public void onFaviconAvailable(Bitmap image, String iconUrl) {
|
| + mFaviconHelper.destroy();
|
| + mFaviconHelper = null;
|
| + if (image == null) {
|
| + // Invalid favicon, produce a generic one.
|
| + RoundedIconGenerator faviconGenerator = new RoundedIconGenerator(
|
| + getContext(), FAVICON_SIZE_DP, FAVICON_SIZE_DP,
|
| + FAVICON_CORNER_RADIUS_DP, FAVICON_BACKGROUND_COLOR,
|
| + FAVICON_TEXT_SIZE_SP);
|
| + image = faviconGenerator.generateIconForUrl(faviconUrl());
|
| + }
|
| +
|
| + setIcon(new BitmapDrawable(getContext().getResources(), image));
|
| + }
|
| +
|
| + /**
|
| + * Returns the url of the site to fetch a favicon for.
|
| + */
|
| + private String faviconUrl() {
|
| + String origin = mSite.getAddress().getOrigin();
|
| + if (origin == null) {
|
| + return "http://" + mSite.getAddress().getHost();
|
| + }
|
| +
|
| + Uri uri = Uri.parse(origin);
|
| + if (uri.getPort() != -1) {
|
| + // Remove the port.
|
| + uri = uri.buildUpon().authority(uri.getHost()).build();
|
| + }
|
| + return uri.toString();
|
| + }
|
| +
|
| private void refresh() {
|
| setTitle(mSite.getTitle());
|
| String subtitleText = mSite.getSummary();
|
| @@ -96,6 +151,31 @@ class WebsitePreference extends Preference {
|
| mediaCaptureIcon.setVisibility(View.VISIBLE);
|
| }
|
| }
|
| +
|
| + float density = getContext().getResources().getDisplayMetrics().density;
|
| + if (!mFaviconFetched) {
|
| + // Start the favicon fetching. Will respond in onFaviconAvailable.
|
| + mFaviconHelper = new FaviconHelper();
|
| + if (!mFaviconHelper.getLocalFaviconImageForURL(
|
| + Profile.getLastUsedProfile(), faviconUrl(),
|
| + FaviconHelper.FAVICON | FaviconHelper.TOUCH_ICON
|
| + | FaviconHelper.TOUCH_PRECOMPOSED_ICON,
|
| + Math.round(FAVICON_SIZE_DP * density),
|
| + this)) {
|
| + onFaviconAvailable(null, null);
|
| + }
|
| + mFaviconFetched = true;
|
| + }
|
| +
|
| + ImageView icon = (ImageView) view.findViewById(android.R.id.icon);
|
| + View parent = (View) icon.getParent();
|
| + if (parent instanceof LinearLayout) {
|
| + LinearLayout parentLayout = (LinearLayout) parent;
|
| + int minWidth = Math.round(FAVICON_PARENT_MINWIDTH_DP * density);
|
| + int padding = Math.round(FAVICON_PARENT_PADDING_DP * density);
|
| + parentLayout.setMinimumWidth(minWidth);
|
| + parentLayout.setPadding(padding, 0, padding, 0);
|
| + }
|
| }
|
|
|
| /**
|
|
|