Merge "When creating bitmap, do not apply width/height ratio if AdaptiveIconDrawable b/37670867" into ub-launcher3-dorval
am: b4c2f07cd3
Change-Id: If56ed7ea3476c62348c1912cf94a3c9690c25d4b
This commit is contained in:
@@ -19,17 +19,18 @@ public class FixedScaleDrawable extends DrawableWrapper {
|
||||
|
||||
// TODO b/33553066 use the constant defined in MaskableIconDrawable
|
||||
private static final float LEGACY_ICON_SCALE = .7f * .6667f;
|
||||
private float mScale;
|
||||
private float mScaleX, mScaleY;
|
||||
|
||||
public FixedScaleDrawable() {
|
||||
super(new ColorDrawable());
|
||||
mScale = LEGACY_ICON_SCALE;
|
||||
mScaleX = LEGACY_ICON_SCALE;
|
||||
mScaleY = LEGACY_ICON_SCALE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
int saveCount = canvas.save(Canvas.MATRIX_SAVE_FLAG);
|
||||
canvas.scale(mScale, mScale,
|
||||
canvas.scale(mScaleX, mScaleY,
|
||||
getBounds().exactCenterX(), getBounds().exactCenterY());
|
||||
super.draw(canvas);
|
||||
canvas.restoreToCount(saveCount);
|
||||
@@ -42,6 +43,14 @@ public class FixedScaleDrawable extends DrawableWrapper {
|
||||
public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Theme theme) { }
|
||||
|
||||
public void setScale(float scale) {
|
||||
mScale = scale * LEGACY_ICON_SCALE;
|
||||
float h = getIntrinsicHeight();
|
||||
float w = getIntrinsicWidth();
|
||||
mScaleX = scale * LEGACY_ICON_SCALE;
|
||||
mScaleY = scale * LEGACY_ICON_SCALE;
|
||||
if (h > w && w > 0) {
|
||||
mScaleX *= w / h;
|
||||
} else if (w > h && h > 0) {
|
||||
mScaleY *= h / w;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,7 +252,6 @@ public class LauncherIcons {
|
||||
width = (int) (height * ratio);
|
||||
}
|
||||
}
|
||||
|
||||
// no intrinsic size --> use default size
|
||||
int textureWidth = iconBitmapSize;
|
||||
int textureHeight = iconBitmapSize;
|
||||
@@ -266,7 +265,13 @@ public class LauncherIcons {
|
||||
final int top = (textureHeight-height) / 2;
|
||||
|
||||
sOldBounds.set(icon.getBounds());
|
||||
icon.setBounds(left, top, left+width, top+height);
|
||||
if (icon instanceof AdaptiveIconDrawable) {
|
||||
int offset = Math.min(left, top);
|
||||
int size = Math.max(width, height);
|
||||
icon.setBounds(offset, offset, offset + size, offset + size);
|
||||
} else {
|
||||
icon.setBounds(left, top, left+width, top+height);
|
||||
}
|
||||
canvas.save(Canvas.MATRIX_SAVE_FLAG);
|
||||
canvas.scale(scale, scale, textureWidth / 2, textureHeight / 2);
|
||||
icon.draw(canvas);
|
||||
@@ -289,16 +294,13 @@ public class LauncherIcons {
|
||||
}
|
||||
|
||||
try {
|
||||
Class clazz = Class.forName("android.graphics.drawable.AdaptiveIconDrawable");
|
||||
if (!clazz.isAssignableFrom(drawable.getClass())) {
|
||||
Drawable iconWrapper =
|
||||
if (!(drawable instanceof AdaptiveIconDrawable)) {
|
||||
AdaptiveIconDrawable iconWrapper = (AdaptiveIconDrawable)
|
||||
context.getDrawable(R.drawable.adaptive_icon_drawable_wrapper).mutate();
|
||||
FixedScaleDrawable fsd = ((FixedScaleDrawable) clazz.getMethod("getForeground")
|
||||
.invoke(iconWrapper));
|
||||
FixedScaleDrawable fsd = ((FixedScaleDrawable) iconWrapper.getForeground());
|
||||
fsd.setDrawable(drawable);
|
||||
fsd.setScale(scale);
|
||||
|
||||
return iconWrapper;
|
||||
return (Drawable) iconWrapper;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return drawable;
|
||||
|
||||
Reference in New Issue
Block a user