Commit aa788c1c authored by newt's avatar newt Committed by Commit bot

Fix favicon padding in Site Settings on pre-L devices.

The problem was that the preference layout is quite different between L
and pre-L devices, so adjusting the padding of the icon's parent view
had very different effects in those two cases. Now, we simply set the
padding of the icon view itself to get the favicon where we want it.

BUG=454850

Review URL: https://codereview.chromium.org/956303003

Cr-Commit-Position: refs/heads/master@{#318749}
parent 0ad537cd
...@@ -14,7 +14,6 @@ import android.preference.Preference; ...@@ -14,7 +14,6 @@ import android.preference.Preference;
import android.text.format.Formatter; import android.text.format.Formatter;
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import org.chromium.base.annotations.SuppressFBWarnings; import org.chromium.base.annotations.SuppressFBWarnings;
...@@ -46,12 +45,9 @@ class WebsitePreference extends Preference implements FaviconImageCallback { ...@@ -46,12 +45,9 @@ class WebsitePreference extends Preference implements FaviconImageCallback {
// Metrics for favicon processing. // Metrics for favicon processing.
private static final int FAVICON_CORNER_RADIUS_DP = 2; private static final int FAVICON_CORNER_RADIUS_DP = 2;
private static final int FAVICON_SIZE_DP = 16; private static final int FAVICON_SIZE_DP = 16;
private static final int FAVICON_PADDING_DP = 4;
private static final int FAVICON_TEXT_SIZE_SP = 10; private static final int FAVICON_TEXT_SIZE_SP = 10;
private static final int FAVICON_BACKGROUND_COLOR = 0xff969696; private static final int FAVICON_BACKGROUND_COLOR = 0xff969696;
// The minimum width of the preference icon parent field.
private static final int FAVICON_PARENT_MINWIDTH_DP = 55;
// The padding for the preference icon parent field.
private static final int FAVICON_PARENT_PADDING_DP = 12;
WebsitePreference(Context context, Website site, String categoryFilter) { WebsitePreference(Context context, Website site, String categoryFilter) {
super(context); super(context);
...@@ -61,15 +57,11 @@ class WebsitePreference extends Preference implements FaviconImageCallback { ...@@ -61,15 +57,11 @@ class WebsitePreference extends Preference implements FaviconImageCallback {
setWidgetLayoutResource(R.layout.website_features); setWidgetLayoutResource(R.layout.website_features);
// To make sure the layout stays stable throughout, we assign a // To make sure the layout stays stable throughout, we assign a
// transparent drawable of the same size as the favicon. This is so that // transparent drawable as the icon initially. This is so that
// we can fetch the favicon in the background and not have to worry // we can fetch the favicon in the background and not have to worry
// about the title appearing to jump (http://crbug.com/453626) when the // about the title appearing to jump (http://crbug.com/453626) when the
// favicon becomes available. // favicon becomes available.
ColorDrawable drawable = new ColorDrawable(Color.TRANSPARENT); setIcon(new ColorDrawable(Color.TRANSPARENT));
int size = Math.round(FAVICON_SIZE_DP
* getContext().getResources().getDisplayMetrics().density);
drawable.setBounds(0, 0, size, size);
setIcon(drawable);
refresh(); refresh();
} }
...@@ -146,8 +138,8 @@ class WebsitePreference extends Preference implements FaviconImageCallback { ...@@ -146,8 +138,8 @@ class WebsitePreference extends Preference implements FaviconImageCallback {
TextView usageText = (TextView) view.findViewById(R.id.usage_text); TextView usageText = (TextView) view.findViewById(R.id.usage_text);
usageText.setVisibility(View.GONE); usageText.setVisibility(View.GONE);
long totalUsage = mSite.getTotalUsage();
if (mFilter.showStorageSites(mCategoryFilter)) { if (mFilter.showStorageSites(mCategoryFilter)) {
long totalUsage = mSite.getTotalUsage();
if (totalUsage > 0) { if (totalUsage > 0) {
usageText.setText(Formatter.formatShortFileSize(getContext(), totalUsage)); usageText.setText(Formatter.formatShortFileSize(getContext(), totalUsage));
usageText.setTextSize(TEXT_SIZE_SP); usageText.setTextSize(TEXT_SIZE_SP);
...@@ -181,15 +173,9 @@ class WebsitePreference extends Preference implements FaviconImageCallback { ...@@ -181,15 +173,9 @@ class WebsitePreference extends Preference implements FaviconImageCallback {
mFaviconFetched = true; mFaviconFetched = true;
} }
ImageView icon = (ImageView) view.findViewById(android.R.id.icon); int iconPadding = Math.round(FAVICON_PADDING_DP * density);
View parent = (View) icon.getParent(); View iconView = view.findViewById(android.R.id.icon);
if (parent instanceof LinearLayout) { iconView.setPadding(iconPadding, iconPadding, iconPadding, iconPadding);
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);
}
} }
/** /**
......
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