Commit 4ed28c4a authored by Henrique Nakashima's avatar Henrique Nakashima Committed by Commit Bot

Pass Resources to createRoundedBitmapDrawable().

Resources should not be retrieved using getApplicationContext().
Different activities may have different resources.

Change-Id: Idcebd0060b2d19cda81416217be90b4b4a7ccee1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1846095
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704296}
parent ff7e27a2
......@@ -58,7 +58,7 @@ public class TabListFaviconProvider {
}
if (sRoundedChromeDrawable == null) {
Bitmap chromeBitmap =
BitmapFactory.decodeResource(context.getResources(), R.drawable.chromelogo16);
BitmapFactory.decodeResource(mContext.getResources(), R.drawable.chromelogo16);
sRoundedChromeDrawable = processBitmap(chromeBitmap);
}
mDefaultIconColor = mContext.getResources().getColor(R.color.default_icon_color);
......@@ -66,7 +66,7 @@ public class TabListFaviconProvider {
}
private Drawable processBitmap(Bitmap bitmap) {
return FaviconUtils.createRoundedBitmapDrawable(
return FaviconUtils.createRoundedBitmapDrawable(mContext.getResources(),
Bitmap.createScaledBitmap(bitmap, mFaviconSize, mFaviconSize, true));
}
......
......@@ -81,8 +81,9 @@ public class BookmarkItemRow extends BookmarkRow implements LargeIconCallback {
icon = mIconGenerator.generateIconForUrl(mUrl);
setIconDrawable(new BitmapDrawable(getResources(), icon));
} else {
setIconDrawable(FaviconUtils.createRoundedBitmapDrawable(Bitmap.createScaledBitmap(
icon, mDisplayedIconSize, mDisplayedIconSize, false)));
setIconDrawable(FaviconUtils.createRoundedBitmapDrawable(getResources(),
Bitmap.createScaledBitmap(
icon, mDisplayedIconSize, mDisplayedIconSize, false)));
}
}
}
......@@ -238,7 +238,7 @@ public class EphemeralTabCoordinator {
Bitmap.createScaledBitmap(image, mFaviconSize, mFaviconSize, true));
}
return FaviconUtils.createRoundedBitmapDrawable(
return FaviconUtils.createRoundedBitmapDrawable(mContext.getResources(),
Bitmap.createScaledBitmap(image, mFaviconSize, mFaviconSize, true));
}
}
......
......@@ -71,7 +71,7 @@ public class ExperimentalExploreSitesCategoryTileView extends LinearLayout {
drawable = new BitmapDrawable(mResources,
mIconGenerator.generateIconForText(mCategoryData.getCategoryName()));
} else {
drawable = ViewUtils.createRoundedBitmapDrawable(
drawable = ViewUtils.createRoundedBitmapDrawable(mResources,
Bitmap.createScaledBitmap(bitmap, mIconWidthPx, mIconHeightPx, false),
mResources.getDimensionPixelSize(R.dimen.experimental_explore_sites_radius));
}
......
......@@ -175,7 +175,7 @@ public class ExploreSitesSection {
mProfile, category.getId(), iconSizePx, (Bitmap image) -> {
if (image != null) {
category.setDrawable(ViewUtils.createRoundedBitmapDrawable(
image, iconSizePx / 2));
v.getContext().getResources(), image, iconSizePx / 2));
v.renderIcon(category);
}
});
......
......@@ -9,7 +9,6 @@ import android.graphics.Bitmap;
import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ContextUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ui.widget.RoundedIconGenerator;
import org.chromium.chrome.browser.util.ViewUtils;
......@@ -50,13 +49,14 @@ public class FaviconUtils {
/**
* Creates a {@link RoundedBitmapDrawable} using the provided {@link Bitmap} and a default
* favicon corner radius.
* @param resources The {@link Resources}.
* @param icon The {@link Bitmap} to round.
* @return A {@link RoundedBitmapDrawable} for the provided {@link Bitmap}.
*/
public static RoundedBitmapDrawable createRoundedBitmapDrawable(Bitmap icon) {
Resources resources = ContextUtils.getApplicationContext().getResources();
return ViewUtils.createRoundedBitmapDrawable(
icon, resources.getDimensionPixelSize(R.dimen.default_favicon_corner_radius));
public static RoundedBitmapDrawable createRoundedBitmapDrawable(
Resources resources, Bitmap icon) {
return ViewUtils.createRoundedBitmapDrawable(resources, icon,
resources.getDimensionPixelSize(R.dimen.default_favicon_corner_radius));
}
private static int getIconColor(Resources resources) {
......
......@@ -169,8 +169,9 @@ public class HistoryItemView extends SelectableItemView<HistoryItem> implements
icon = mIconGenerator.generateIconForUrl(getItem().getUrl());
setIconDrawable(new BitmapDrawable(getResources(), icon));
} else {
setIconDrawable(FaviconUtils.createRoundedBitmapDrawable(Bitmap.createScaledBitmap(
icon, mDisplayedIconSize, mDisplayedIconSize, false)));
setIconDrawable(FaviconUtils.createRoundedBitmapDrawable(getResources(),
Bitmap.createScaledBitmap(
icon, mDisplayedIconSize, mDisplayedIconSize, false)));
}
}
......
......@@ -715,7 +715,7 @@ public class RecentTabsRowAdapter extends BaseExpandableListAdapter {
// TODO(injae): Move shared code between Bookmarks/History/Downloads/here to ViewUtils.java.
// Also applies to RoundedIconGenerator. crbug.com/829550
return FaviconUtils.createRoundedBitmapDrawable(
Bitmap.createScaledBitmap(image, size, size, true));
mActivity.getResources(), Bitmap.createScaledBitmap(image, size, size, true));
}
private void loadForeignFavicon(final ViewHolder viewHolder, final String url) {
......
......@@ -130,7 +130,7 @@ public class ConfirmImportantSitesDialogFragment extends DialogFragment {
icon = mIconGenerator.generateIconForUrl(url);
return new BitmapDrawable(getResources(), icon);
} else {
return FaviconUtils.createRoundedBitmapDrawable(
return FaviconUtils.createRoundedBitmapDrawable(getResources(),
Bitmap.createScaledBitmap(icon, mFaviconSize, mFaviconSize, false));
}
}
......
......@@ -239,7 +239,8 @@ public class TileRenderer {
if (tile.getSource() == TileSource.EXPLORE) {
radius = mDesiredIconSize / 2;
}
RoundedBitmapDrawable roundedIcon = ViewUtils.createRoundedBitmapDrawable(icon, radius);
RoundedBitmapDrawable roundedIcon =
ViewUtils.createRoundedBitmapDrawable(mResources, icon, radius);
roundedIcon.setAntiAlias(true);
roundedIcon.setFilterBitmap(true);
......
......@@ -16,8 +16,6 @@ import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import org.chromium.base.ContextUtils;
/**
* View-related utility methods.
*/
......@@ -158,12 +156,13 @@ public class ViewUtils {
/**
* Creates a {@link RoundedBitmapDrawable} using the provided {@link Bitmap} and cornerRadius.
* @param resources The {@link Resources}.
* @param icon The {@link Bitmap} to round.
* @param cornerRadius The corner radius.
* @return A {@link RoundedBitmapDrawable} for the provided {@link Bitmap}.
*/
public static RoundedBitmapDrawable createRoundedBitmapDrawable(Bitmap icon, int cornerRadius) {
Resources resources = ContextUtils.getApplicationContext().getResources();
public static RoundedBitmapDrawable createRoundedBitmapDrawable(
Resources resources, Bitmap icon, int cornerRadius) {
RoundedBitmapDrawable roundedIcon = RoundedBitmapDrawableFactory.create(resources, icon);
roundedIcon.setCornerRadius(cornerRadius);
return roundedIcon;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment