Add shape detection logic only for circle icons

b/119330044

Change-Id: I93042effa8417167d844f073275e8b941e861e60
This commit is contained in:
Hyunyoung Song committed 2019-06-03 14:05:20 -07:00
1 parent ebd5e88164
commit f69426c484
6 files changed
+139 -16

No files matched your search

@@ -46,13 +46,15 @@ public class BaseIconFactory implements AutoCloseable {
private IconNormalizer mNormalizer;
private ShadowGenerator mShadowGenerator;
private final boolean mShapeDetection;
private Drawable mWrapperIcon;
private int mWrapperBackgroundColor = DEFAULT_WRAPPER_BACKGROUND;
protected BaseIconFactory(Context context, int fillResIconDpi, int iconBitmapSize) {
protected BaseIconFactory(Context context, int fillResIconDpi, int iconBitmapSize,
boolean shapeDetection) {
mContext = context.getApplicationContext();
mShapeDetection = shapeDetection;
mFillResIconDpi = fillResIconDpi;
mIconBitmapSize = iconBitmapSize;
@@ -64,6 +66,10 @@ public class BaseIconFactory implements AutoCloseable {
clear();
}
protected BaseIconFactory(Context context, int fillResIconDpi, int iconBitmapSize) {
this(context, fillResIconDpi, iconBitmapSize, false);
}
protected void clear() {
mWrapperBackgroundColor = DEFAULT_WRAPPER_BACKGROUND;
mDisableColorExtractor = false;
@@ -78,7 +84,7 @@ public class BaseIconFactory implements AutoCloseable {
public IconNormalizer getNormalizer() {
if (mNormalizer == null) {
mNormalizer = new IconNormalizer(mIconBitmapSize);
mNormalizer = new IconNormalizer(mContext, mIconBitmapSize, mShapeDetection);
}
return mNormalizer;
}
@@ -212,18 +218,19 @@ public class BaseIconFactory implements AutoCloseable {
}
AdaptiveIconDrawable dr = (AdaptiveIconDrawable) mWrapperIcon;
dr.setBounds(0, 0, 1, 1);
scale = getNormalizer().getScale(icon, outIconBounds);
if (!(icon instanceof AdaptiveIconDrawable)) {
boolean[] outShape = new boolean[1];
scale = getNormalizer().getScale(icon, outIconBounds, dr.getIconMask(), outShape);
if (!(icon instanceof AdaptiveIconDrawable) && !outShape[0]) {
FixedScaleDrawable fsd = ((FixedScaleDrawable) dr.getForeground());
fsd.setDrawable(icon);
fsd.setScale(scale);
icon = dr;
scale = getNormalizer().getScale(icon, outIconBounds);
scale = getNormalizer().getScale(icon, outIconBounds, null, null);
((ColorDrawable) dr.getBackground()).setColor(mWrapperBackgroundColor);
}
} else {
scale = getNormalizer().getScale(icon, outIconBounds);
scale = getNormalizer().getScale(icon, outIconBounds, null, null);
}
outScale[0] = scale;