Merge "When creating bitmap, do not apply width/height ratio if AdaptiveIconDrawable b/37670867" into ub-launcher3-dorval
am: b4c2f07cd3
Change-Id: If56ed7ea3476c62348c1912cf94a3c9690c25d4b
diff --git a/src/com/android/launcher3/graphics/FixedScaleDrawable.java b/src/com/android/launcher3/graphics/FixedScaleDrawable.java
index 7ee3d80..262a95e 100644
--- a/src/com/android/launcher3/graphics/FixedScaleDrawable.java
+++ b/src/com/android/launcher3/graphics/FixedScaleDrawable.java
@@ -19,17 +19,18 @@
// 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 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;
+ }
}
}
diff --git a/src/com/android/launcher3/graphics/LauncherIcons.java b/src/com/android/launcher3/graphics/LauncherIcons.java
index e671a82..746a639 100644
--- a/src/com/android/launcher3/graphics/LauncherIcons.java
+++ b/src/com/android/launcher3/graphics/LauncherIcons.java
@@ -252,7 +252,6 @@
width = (int) (height * ratio);
}
}
-
// no intrinsic size --> use default size
int textureWidth = iconBitmapSize;
int textureHeight = iconBitmapSize;
@@ -266,7 +265,13 @@
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 @@
}
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;