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 { ...@@ -58,7 +58,7 @@ public class TabListFaviconProvider {
} }
if (sRoundedChromeDrawable == null) { if (sRoundedChromeDrawable == null) {
Bitmap chromeBitmap = Bitmap chromeBitmap =
BitmapFactory.decodeResource(context.getResources(), R.drawable.chromelogo16); BitmapFactory.decodeResource(mContext.getResources(), R.drawable.chromelogo16);
sRoundedChromeDrawable = processBitmap(chromeBitmap); sRoundedChromeDrawable = processBitmap(chromeBitmap);
} }
mDefaultIconColor = mContext.getResources().getColor(R.color.default_icon_color); mDefaultIconColor = mContext.getResources().getColor(R.color.default_icon_color);
...@@ -66,7 +66,7 @@ public class TabListFaviconProvider { ...@@ -66,7 +66,7 @@ public class TabListFaviconProvider {
} }
private Drawable processBitmap(Bitmap bitmap) { private Drawable processBitmap(Bitmap bitmap) {
return FaviconUtils.createRoundedBitmapDrawable( return FaviconUtils.createRoundedBitmapDrawable(mContext.getResources(),
Bitmap.createScaledBitmap(bitmap, mFaviconSize, mFaviconSize, true)); Bitmap.createScaledBitmap(bitmap, mFaviconSize, mFaviconSize, true));
} }
......
...@@ -81,7 +81,8 @@ public class BookmarkItemRow extends BookmarkRow implements LargeIconCallback { ...@@ -81,7 +81,8 @@ public class BookmarkItemRow extends BookmarkRow implements LargeIconCallback {
icon = mIconGenerator.generateIconForUrl(mUrl); icon = mIconGenerator.generateIconForUrl(mUrl);
setIconDrawable(new BitmapDrawable(getResources(), icon)); setIconDrawable(new BitmapDrawable(getResources(), icon));
} else { } else {
setIconDrawable(FaviconUtils.createRoundedBitmapDrawable(Bitmap.createScaledBitmap( setIconDrawable(FaviconUtils.createRoundedBitmapDrawable(getResources(),
Bitmap.createScaledBitmap(
icon, mDisplayedIconSize, mDisplayedIconSize, false))); icon, mDisplayedIconSize, mDisplayedIconSize, false)));
} }
} }
......
...@@ -238,7 +238,7 @@ public class EphemeralTabCoordinator { ...@@ -238,7 +238,7 @@ public class EphemeralTabCoordinator {
Bitmap.createScaledBitmap(image, mFaviconSize, mFaviconSize, true)); Bitmap.createScaledBitmap(image, mFaviconSize, mFaviconSize, true));
} }
return FaviconUtils.createRoundedBitmapDrawable( return FaviconUtils.createRoundedBitmapDrawable(mContext.getResources(),
Bitmap.createScaledBitmap(image, mFaviconSize, mFaviconSize, true)); Bitmap.createScaledBitmap(image, mFaviconSize, mFaviconSize, true));
} }
} }
......
...@@ -71,7 +71,7 @@ public class ExperimentalExploreSitesCategoryTileView extends LinearLayout { ...@@ -71,7 +71,7 @@ public class ExperimentalExploreSitesCategoryTileView extends LinearLayout {
drawable = new BitmapDrawable(mResources, drawable = new BitmapDrawable(mResources,
mIconGenerator.generateIconForText(mCategoryData.getCategoryName())); mIconGenerator.generateIconForText(mCategoryData.getCategoryName()));
} else { } else {
drawable = ViewUtils.createRoundedBitmapDrawable( drawable = ViewUtils.createRoundedBitmapDrawable(mResources,
Bitmap.createScaledBitmap(bitmap, mIconWidthPx, mIconHeightPx, false), Bitmap.createScaledBitmap(bitmap, mIconWidthPx, mIconHeightPx, false),
mResources.getDimensionPixelSize(R.dimen.experimental_explore_sites_radius)); mResources.getDimensionPixelSize(R.dimen.experimental_explore_sites_radius));
} }
......
...@@ -175,7 +175,7 @@ public class ExploreSitesSection { ...@@ -175,7 +175,7 @@ public class ExploreSitesSection {
mProfile, category.getId(), iconSizePx, (Bitmap image) -> { mProfile, category.getId(), iconSizePx, (Bitmap image) -> {
if (image != null) { if (image != null) {
category.setDrawable(ViewUtils.createRoundedBitmapDrawable( category.setDrawable(ViewUtils.createRoundedBitmapDrawable(
image, iconSizePx / 2)); v.getContext().getResources(), image, iconSizePx / 2));
v.renderIcon(category); v.renderIcon(category);
} }
}); });
......
...@@ -9,7 +9,6 @@ import android.graphics.Bitmap; ...@@ -9,7 +9,6 @@ import android.graphics.Bitmap;
import android.support.v4.graphics.drawable.RoundedBitmapDrawable; import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
import org.chromium.base.ApiCompatibilityUtils; import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ContextUtils;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.ui.widget.RoundedIconGenerator; import org.chromium.chrome.browser.ui.widget.RoundedIconGenerator;
import org.chromium.chrome.browser.util.ViewUtils; import org.chromium.chrome.browser.util.ViewUtils;
...@@ -50,13 +49,14 @@ public class FaviconUtils { ...@@ -50,13 +49,14 @@ public class FaviconUtils {
/** /**
* Creates a {@link RoundedBitmapDrawable} using the provided {@link Bitmap} and a default * Creates a {@link RoundedBitmapDrawable} using the provided {@link Bitmap} and a default
* favicon corner radius. * favicon corner radius.
* @param resources The {@link Resources}.
* @param icon The {@link Bitmap} to round. * @param icon The {@link Bitmap} to round.
* @return A {@link RoundedBitmapDrawable} for the provided {@link Bitmap}. * @return A {@link RoundedBitmapDrawable} for the provided {@link Bitmap}.
*/ */
public static RoundedBitmapDrawable createRoundedBitmapDrawable(Bitmap icon) { public static RoundedBitmapDrawable createRoundedBitmapDrawable(
Resources resources = ContextUtils.getApplicationContext().getResources(); Resources resources, Bitmap icon) {
return ViewUtils.createRoundedBitmapDrawable( return ViewUtils.createRoundedBitmapDrawable(resources, icon,
icon, resources.getDimensionPixelSize(R.dimen.default_favicon_corner_radius)); resources.getDimensionPixelSize(R.dimen.default_favicon_corner_radius));
} }
private static int getIconColor(Resources resources) { private static int getIconColor(Resources resources) {
......
...@@ -169,7 +169,8 @@ public class HistoryItemView extends SelectableItemView<HistoryItem> implements ...@@ -169,7 +169,8 @@ public class HistoryItemView extends SelectableItemView<HistoryItem> implements
icon = mIconGenerator.generateIconForUrl(getItem().getUrl()); icon = mIconGenerator.generateIconForUrl(getItem().getUrl());
setIconDrawable(new BitmapDrawable(getResources(), icon)); setIconDrawable(new BitmapDrawable(getResources(), icon));
} else { } else {
setIconDrawable(FaviconUtils.createRoundedBitmapDrawable(Bitmap.createScaledBitmap( setIconDrawable(FaviconUtils.createRoundedBitmapDrawable(getResources(),
Bitmap.createScaledBitmap(
icon, mDisplayedIconSize, mDisplayedIconSize, false))); icon, mDisplayedIconSize, mDisplayedIconSize, false)));
} }
} }
......
...@@ -715,7 +715,7 @@ public class RecentTabsRowAdapter extends BaseExpandableListAdapter { ...@@ -715,7 +715,7 @@ public class RecentTabsRowAdapter extends BaseExpandableListAdapter {
// TODO(injae): Move shared code between Bookmarks/History/Downloads/here to ViewUtils.java. // TODO(injae): Move shared code between Bookmarks/History/Downloads/here to ViewUtils.java.
// Also applies to RoundedIconGenerator. crbug.com/829550 // Also applies to RoundedIconGenerator. crbug.com/829550
return FaviconUtils.createRoundedBitmapDrawable( 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) { private void loadForeignFavicon(final ViewHolder viewHolder, final String url) {
......
...@@ -130,7 +130,7 @@ public class ConfirmImportantSitesDialogFragment extends DialogFragment { ...@@ -130,7 +130,7 @@ public class ConfirmImportantSitesDialogFragment extends DialogFragment {
icon = mIconGenerator.generateIconForUrl(url); icon = mIconGenerator.generateIconForUrl(url);
return new BitmapDrawable(getResources(), icon); return new BitmapDrawable(getResources(), icon);
} else { } else {
return FaviconUtils.createRoundedBitmapDrawable( return FaviconUtils.createRoundedBitmapDrawable(getResources(),
Bitmap.createScaledBitmap(icon, mFaviconSize, mFaviconSize, false)); Bitmap.createScaledBitmap(icon, mFaviconSize, mFaviconSize, false));
} }
} }
......
...@@ -239,7 +239,8 @@ public class TileRenderer { ...@@ -239,7 +239,8 @@ public class TileRenderer {
if (tile.getSource() == TileSource.EXPLORE) { if (tile.getSource() == TileSource.EXPLORE) {
radius = mDesiredIconSize / 2; radius = mDesiredIconSize / 2;
} }
RoundedBitmapDrawable roundedIcon = ViewUtils.createRoundedBitmapDrawable(icon, radius); RoundedBitmapDrawable roundedIcon =
ViewUtils.createRoundedBitmapDrawable(mResources, icon, radius);
roundedIcon.setAntiAlias(true); roundedIcon.setAntiAlias(true);
roundedIcon.setFilterBitmap(true); roundedIcon.setFilterBitmap(true);
......
...@@ -16,8 +16,6 @@ import android.util.TypedValue; ...@@ -16,8 +16,6 @@ import android.util.TypedValue;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import org.chromium.base.ContextUtils;
/** /**
* View-related utility methods. * View-related utility methods.
*/ */
...@@ -158,12 +156,13 @@ public class ViewUtils { ...@@ -158,12 +156,13 @@ public class ViewUtils {
/** /**
* Creates a {@link RoundedBitmapDrawable} using the provided {@link Bitmap} and cornerRadius. * Creates a {@link RoundedBitmapDrawable} using the provided {@link Bitmap} and cornerRadius.
* @param resources The {@link Resources}.
* @param icon The {@link Bitmap} to round. * @param icon The {@link Bitmap} to round.
* @param cornerRadius The corner radius. * @param cornerRadius The corner radius.
* @return A {@link RoundedBitmapDrawable} for the provided {@link Bitmap}. * @return A {@link RoundedBitmapDrawable} for the provided {@link Bitmap}.
*/ */
public static RoundedBitmapDrawable createRoundedBitmapDrawable(Bitmap icon, int cornerRadius) { public static RoundedBitmapDrawable createRoundedBitmapDrawable(
Resources resources = ContextUtils.getApplicationContext().getResources(); Resources resources, Bitmap icon, int cornerRadius) {
RoundedBitmapDrawable roundedIcon = RoundedBitmapDrawableFactory.create(resources, icon); RoundedBitmapDrawable roundedIcon = RoundedBitmapDrawableFactory.create(resources, icon);
roundedIcon.setCornerRadius(cornerRadius); roundedIcon.setCornerRadius(cornerRadius);
return roundedIcon; 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