Commit 73b83eb9 authored by Ehimare Okoyomon's avatar Ehimare Okoyomon Committed by Commit Bot

[Android] Edit permission icon strikethrough overlay

Make strikethrough thickness relative to icon size and introduce a bias
to shift the line to only one side of the transparent line, in order to
match mocks.

Screenshot: crbug.com/1077766#c106
Bug: 1077766
Change-Id: I0a4730d8aba05b6f266da1b0ba53dba254cc4000
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2552861
Commit-Queue: Ehimare Okoyomon <eokoyomon@chromium.org>
Reviewed-by: default avatarChristian Dullweber <dullweber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#830578}
parent 91b474fd
......@@ -259,10 +259,10 @@ public class ContentSettingsResources {
}
/**
* @return A {@link Drawable} that is the blocked version of the icon passed in. Achieved by
* adding a diagonal strike through the icon.
* @return A {@link Drawable} that is the blocked version of the square icon passed in.
* Achieved by adding a diagonal strike through the icon.
*/
public static Drawable getBlockedIcon(Resources resources, Drawable icon) {
public static Drawable getBlockedSquareIcon(Resources resources, Drawable icon) {
if (icon == null) return null;
// Save color filter in order to re-apply later
ColorFilter filter = icon.getColorFilter();
......@@ -271,25 +271,39 @@ public class ContentSettingsResources {
Bitmap iconBitmap = Bitmap.createBitmap(
icon.getIntrinsicWidth(), icon.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(iconBitmap);
int width = canvas.getWidth();
int height = canvas.getHeight();
icon.setBounds(0, 0, width, height);
int side = canvas.getWidth();
assert side == canvas.getHeight();
icon.setBounds(0, 0, side, side);
icon.draw(canvas);
// Thickness of the strikethrough line in pixels, relative to the icon size.
float thickness = 0.08f * side;
// Determines the axis bounds for where the line should start and finish.
float padding = side * 0.15f;
// The scaling ratio to get the axis bias. sin(45 degrees).
float ratio = 0.7071f;
// Calculated axis shift for the line in order to only be on one side of the transparent
// line.
float bias = (thickness / 2) * ratio;
// Draw diagonal transparent line
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.TRANSPARENT);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT));
paint.setStrokeWidth(12);
canvas.drawLine(0, 0, width, height, paint);
// Draw a strikethrough on top
// Scale by 1.5 then shift up by half of bias in order to ensure no weird gap between lines
// due to rounding.
float halfBias = 0.5f * bias;
paint.setStrokeWidth(1.5f * thickness);
canvas.drawLine(padding + halfBias, padding - halfBias, side - padding + halfBias,
side - padding - halfBias, paint);
// Draw a strikethrough directly below.
paint.setColor(Color.BLACK);
paint.setXfermode(null);
paint.setStrokeWidth(4);
canvas.drawLine(
width * 0.1f, height * 0.1f, width - width * 0.1f, height - height * 0.1f, paint);
paint.setStrokeWidth(thickness);
canvas.drawLine(padding - bias, padding + bias, side - padding - bias,
side - padding + bias, paint);
Drawable blocked = new BitmapDrawable(resources, iconBitmap);
// Re-apply color filter
......
......@@ -362,7 +362,7 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
: ContentSettingsResources.getDisabledIcon(contentSettingsType, getResources());
if (getSiteSettingsClient().isPageInfoV2Enabled() && value != null
&& value == ContentSettingValues.BLOCK) {
return ContentSettingsResources.getBlockedIcon(getResources(), icon);
return ContentSettingsResources.getBlockedSquareIcon(getResources(), icon);
}
return icon;
}
......
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