diff options
author | Hyunyoung Song <hyunyoungs@google.com> | 2018-10-02 17:08:21 -0700 |
---|---|---|
committer | Hyunyoung Song <hyunyoungs@google.com> | 2018-10-03 16:33:40 -0700 |
commit | 44bd6fd0200588ebf1daba8de19b60ac6c49031c (patch) | |
tree | 9560af46605ac8094fffe66dfd47d346ebd476dc /src | |
parent | ff2d0d0a9eb51ea10262e51e87fd9fb1992900aa (diff) | |
download | android_packages_apps_Trebuchet-44bd6fd0200588ebf1daba8de19b60ac6c49031c.tar.gz android_packages_apps_Trebuchet-44bd6fd0200588ebf1daba8de19b60ac6c49031c.tar.bz2 android_packages_apps_Trebuchet-44bd6fd0200588ebf1daba8de19b60ac6c49031c.zip |
Fix clipping issue on adaptive icons
Bug: 116527322
More context: unlike previous issue that resulted in clipping on adaptive
icon due to launcher drawing issue (drawing outside the bounds, etc).
This issue is happening on b4 because when canvas is scaled after
the circle mask is digitized, there is a optical illusion that one line
of pixel seems missing. The issue is non observed if scaling is done
before setting the view bounds.
Change-Id: I7099075c88e77776c9cc4f23d79152293489cca2
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/launcher3/icons/LauncherIcons.java | 81 |
1 files changed, 36 insertions, 45 deletions
diff --git a/src/com/android/launcher3/icons/LauncherIcons.java b/src/com/android/launcher3/icons/LauncherIcons.java index b4cbf6530..244654bc5 100644 --- a/src/com/android/launcher3/icons/LauncherIcons.java +++ b/src/com/android/launcher3/icons/LauncherIcons.java @@ -30,6 +30,7 @@ import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; +import android.graphics.Paint; import android.graphics.PaintFlagsDrawFilter; import android.graphics.Rect; import android.graphics.RectF; @@ -311,59 +312,49 @@ public class LauncherIcons implements AutoCloseable { * @param scale the scale to apply before drawing {@param icon} on the canvas */ private Bitmap createIconBitmap(Drawable icon, float scale) { - int width = mIconBitmapSize; - int height = mIconBitmapSize; - - if (icon instanceof PaintDrawable) { - PaintDrawable painter = (PaintDrawable) icon; - painter.setIntrinsicWidth(width); - painter.setIntrinsicHeight(height); - } else if (icon instanceof BitmapDrawable) { - // Ensure the bitmap has a density. - BitmapDrawable bitmapDrawable = (BitmapDrawable) icon; - Bitmap bitmap = bitmapDrawable.getBitmap(); - if (bitmap != null && bitmap.getDensity() == Bitmap.DENSITY_NONE) { - bitmapDrawable.setTargetDensity(mContext.getResources().getDisplayMetrics()); - } - } - - int sourceWidth = icon.getIntrinsicWidth(); - int sourceHeight = icon.getIntrinsicHeight(); - if (sourceWidth > 0 && sourceHeight > 0) { - // Scale the icon proportionally to the icon dimensions - final float ratio = (float) sourceWidth / sourceHeight; - if (sourceWidth > sourceHeight) { - height = (int) (width / ratio); - } else if (sourceHeight > sourceWidth) { - width = (int) (height * ratio); - } - } - // no intrinsic size --> use default size - int textureWidth = mIconBitmapSize; - int textureHeight = mIconBitmapSize; - - Bitmap bitmap = Bitmap.createBitmap(textureWidth, textureHeight, + Bitmap bitmap = Bitmap.createBitmap(mIconBitmapSize, mIconBitmapSize, Bitmap.Config.ARGB_8888); mCanvas.setBitmap(bitmap); - - final int left = (textureWidth-width) / 2; - final int top = (textureHeight-height) / 2; - mOldBounds.set(icon.getBounds()); + if (Utilities.ATLEAST_OREO && icon instanceof AdaptiveIconDrawable) { - int offset = Math.max((int) Math.ceil(BLUR_FACTOR * textureWidth), Math.max(left, top)); - int size = Math.max(width, height); - icon.setBounds(offset, offset, size - offset, size - offset); + int offset = Math.max((int) Math.ceil(BLUR_FACTOR * mIconBitmapSize), + Math.round(mIconBitmapSize * (1 - scale) / 2 )); + icon.setBounds(offset, offset, mIconBitmapSize - offset, mIconBitmapSize - offset); + icon.draw(mCanvas); } else { - icon.setBounds(left, top, left+width, top+height); + if (icon instanceof BitmapDrawable) { + BitmapDrawable bitmapDrawable = (BitmapDrawable) icon; + Bitmap b = bitmapDrawable.getBitmap(); + if (bitmap != null && b.getDensity() == Bitmap.DENSITY_NONE) { + bitmapDrawable.setTargetDensity(mContext.getResources().getDisplayMetrics()); + } + } + int width = mIconBitmapSize; + int height = mIconBitmapSize; + + int intrinsicWidth = icon.getIntrinsicWidth(); + int intrinsicHeight = icon.getIntrinsicHeight(); + if (intrinsicWidth > 0 && intrinsicHeight > 0) { + // Scale the icon proportionally to the icon dimensions + final float ratio = (float) intrinsicWidth / intrinsicHeight; + if (intrinsicWidth > intrinsicHeight) { + height = (int) (width / ratio); + } else if (intrinsicHeight > intrinsicWidth) { + width = (int) (height * ratio); + } + } + final int left = (mIconBitmapSize - width) / 2; + final int top = (mIconBitmapSize - height) / 2; + icon.setBounds(left, top, left + width, top + height); + mCanvas.save(); + mCanvas.scale(scale, scale, mIconBitmapSize / 2, mIconBitmapSize / 2); + icon.draw(mCanvas); + mCanvas.restore(); + } - mCanvas.save(); - mCanvas.scale(scale, scale, textureWidth / 2, textureHeight / 2); - icon.draw(mCanvas); - mCanvas.restore(); icon.setBounds(mOldBounds); mCanvas.setBitmap(null); - return bitmap; } |