diff options
author | Hyunyoung Song <hyunyoungs@google.com> | 2017-04-25 11:20:05 -0700 |
---|---|---|
committer | Hyunyoung Song <hyunyoungs@google.com> | 2017-04-27 14:19:58 -0700 |
commit | 9cb48d4a3896c86e347565646086ab4ef726d60c (patch) | |
tree | eb73920599cce4183d946665127329abf94f1c29 /src/com/android/launcher3/graphics | |
parent | ead1680e96dea834d3de7be852c2c1a60e046791 (diff) | |
download | android_packages_apps_Trebuchet-9cb48d4a3896c86e347565646086ab4ef726d60c.tar.gz android_packages_apps_Trebuchet-9cb48d4a3896c86e347565646086ab4ef726d60c.tar.bz2 android_packages_apps_Trebuchet-9cb48d4a3896c86e347565646086ab4ef726d60c.zip |
When creating bitmap, do not apply width/height ratio if AdaptiveIconDrawable
b/37670867
Change-Id: I60884c52e7eb4b2d6f0ae2a5dc8e7c730f1f2454
Diffstat (limited to 'src/com/android/launcher3/graphics')
-rw-r--r-- | src/com/android/launcher3/graphics/FixedScaleDrawable.java | 17 | ||||
-rw-r--r-- | src/com/android/launcher3/graphics/LauncherIcons.java | 20 |
2 files changed, 24 insertions, 13 deletions
diff --git a/src/com/android/launcher3/graphics/FixedScaleDrawable.java b/src/com/android/launcher3/graphics/FixedScaleDrawable.java index 7ee3d8002..262a95e2b 100644 --- a/src/com/android/launcher3/graphics/FixedScaleDrawable.java +++ b/src/com/android/launcher3/graphics/FixedScaleDrawable.java @@ -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; + } } } diff --git a/src/com/android/launcher3/graphics/LauncherIcons.java b/src/com/android/launcher3/graphics/LauncherIcons.java index e671a82e9..746a639ff 100644 --- a/src/com/android/launcher3/graphics/LauncherIcons.java +++ b/src/com/android/launcher3/graphics/LauncherIcons.java @@ -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; |