Loading iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java +4 −25 Original line number Diff line number Diff line Loading @@ -200,7 +200,7 @@ public class BaseIconFactory implements AutoCloseable { /** * Creates bitmap using the source drawable and various parameters. * The bitmap is visually normalized with other icons. * The bitmap is visually normalized with other icons and has enough spacing to add shadow. * * @param icon source of the icon * @param user info can be used for a badge Loading @@ -211,37 +211,16 @@ public class BaseIconFactory implements AutoCloseable { */ public BitmapInfo createBadgedIconBitmap(@NonNull Drawable icon, UserHandle user, boolean shrinkNonAdaptiveIcons, boolean isInstantApp, float[] scale) { return createBadgedIconBitmap(icon, user, shrinkNonAdaptiveIcons, isInstantApp, scale, false /* addShadow */); } /** * Creates bitmap using the source drawable and various parameters. * The bitmap is visually normalized with other icons and has enough spacing to add shadow. * * @param icon source of the icon * @param user info can be used for a badge * @param shrinkNonAdaptiveIcons {@code true} if non adaptive icons should be treated * @param isInstantApp info can be used for a badge * @param scale returns the scale result from normalization * @param addShadow If true, adds a shadow under the icon. * @return a bitmap suitable for disaplaying as an icon at various system UIs. */ private BitmapInfo createBadgedIconBitmap(@NonNull Drawable icon, UserHandle user, boolean shrinkNonAdaptiveIcons, boolean isInstantApp, float[] scale, boolean addShadow) { if (scale == null) { scale = new float[1]; } icon = normalizeAndWrapToAdaptiveIcon(icon, shrinkNonAdaptiveIcons, null, scale); Bitmap bitmap = createIconBitmap(icon, scale[0]); if (ATLEAST_OREO && icon instanceof AdaptiveIconDrawable) { if (addShadow) { mCanvas.setBitmap(bitmap); getShadowGenerator().recreateIcon(Bitmap.createBitmap(bitmap), mCanvas); mCanvas.setBitmap(null); } } if (isInstantApp) { badgeWithDrawable(bitmap, mContext.getDrawable(R.drawable.ic_instant_app_badge)); Loading iconloaderlib/src/com/android/launcher3/icons/ShadowGenerator.java +45 −29 Original line number Diff line number Diff line Loading @@ -32,6 +32,9 @@ import android.graphics.RectF; * Utility class to add shadows to bitmaps. */ public class ShadowGenerator { public static final boolean ENABLE_SHADOWS = false; public static final float BLUR_FACTOR = 0.5f/48; // Percent of actual icon size Loading Loading @@ -60,6 +63,7 @@ public class ShadowGenerator { public synchronized void recreateIcon(Bitmap icon, BlurMaskFilter blurMaskFilter, int ambientAlpha, int keyAlpha, Canvas out) { if (ENABLE_SHADOWS) { int[] offset = new int[2]; mBlurPaint.setMaskFilter(blurMaskFilter); Bitmap shadow = icon.extractAlpha(mBlurPaint, offset); Loading @@ -70,7 +74,9 @@ public class ShadowGenerator { // Draw key shadow mDrawPaint.setAlpha(keyAlpha); out.drawBitmap(shadow, offset[0], offset[1] + KEY_SHADOW_DISTANCE * mIconSize, mDrawPaint); out.drawBitmap(shadow, offset[0], offset[1] + KEY_SHADOW_DISTANCE * mIconSize, mDrawPaint); } // Draw the icon mDrawPaint.setAlpha(255); Loading @@ -84,6 +90,7 @@ public class ShadowGenerator { public static float getScaleForBounds(RectF bounds) { float scale = 1; if (ENABLE_SHADOWS) { // For top, left & right, we need same space. float minSide = Math.min(Math.min(bounds.left, bounds.right), bounds.top); if (minSide < BLUR_FACTOR) { Loading @@ -92,7 +99,9 @@ public class ShadowGenerator { float bottomSpace = BLUR_FACTOR + KEY_SHADOW_DISTANCE; if (bounds.bottom < bottomSpace) { scale = Math.min(scale, (HALF_DISTANCE - bottomSpace) / (HALF_DISTANCE - bounds.bottom)); scale = Math.min(scale, (HALF_DISTANCE - bottomSpace) / (HALF_DISTANCE - bounds.bottom)); } } return scale; } Loading @@ -115,8 +124,13 @@ public class ShadowGenerator { } public Builder setupBlurForSize(int height) { if (ENABLE_SHADOWS) { shadowBlur = height * 1f / 24; keyShadowDistance = height * 1f / 16; } else { shadowBlur = 0; keyShadowDistance = 0; } return this; } Loading @@ -141,6 +155,7 @@ public class ShadowGenerator { Paint p = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG); p.setColor(color); if (ENABLE_SHADOWS) { // Key shadow p.setShadowLayer(shadowBlur, 0, keyShadowDistance, setColorAlphaBound(Color.BLACK, keyShadowAlpha)); Loading @@ -150,6 +165,7 @@ public class ShadowGenerator { p.setShadowLayer(shadowBlur, 0, 0, setColorAlphaBound(Color.BLACK, ambientShadowAlpha)); c.drawRoundRect(bounds, radius, radius, p); } if (Color.alpha(color) < 255) { // Clear any content inside the pill-rect for translucent fill. Loading iconloaderlib/src/com/android/launcher3/icons/cache/BaseIconCache.java +1 −1 Original line number Diff line number Diff line Loading @@ -510,7 +510,7 @@ public abstract class BaseIconCache { * Cache class to store the actual entries on disk */ public static final class IconDB extends SQLiteCacheHelper { private static final int RELEASE_VERSION = 28; private static final int RELEASE_VERSION = 29; public static final String TABLE_NAME = "icons"; public static final String COLUMN_ROWID = "rowid"; Loading Loading
iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java +4 −25 Original line number Diff line number Diff line Loading @@ -200,7 +200,7 @@ public class BaseIconFactory implements AutoCloseable { /** * Creates bitmap using the source drawable and various parameters. * The bitmap is visually normalized with other icons. * The bitmap is visually normalized with other icons and has enough spacing to add shadow. * * @param icon source of the icon * @param user info can be used for a badge Loading @@ -211,37 +211,16 @@ public class BaseIconFactory implements AutoCloseable { */ public BitmapInfo createBadgedIconBitmap(@NonNull Drawable icon, UserHandle user, boolean shrinkNonAdaptiveIcons, boolean isInstantApp, float[] scale) { return createBadgedIconBitmap(icon, user, shrinkNonAdaptiveIcons, isInstantApp, scale, false /* addShadow */); } /** * Creates bitmap using the source drawable and various parameters. * The bitmap is visually normalized with other icons and has enough spacing to add shadow. * * @param icon source of the icon * @param user info can be used for a badge * @param shrinkNonAdaptiveIcons {@code true} if non adaptive icons should be treated * @param isInstantApp info can be used for a badge * @param scale returns the scale result from normalization * @param addShadow If true, adds a shadow under the icon. * @return a bitmap suitable for disaplaying as an icon at various system UIs. */ private BitmapInfo createBadgedIconBitmap(@NonNull Drawable icon, UserHandle user, boolean shrinkNonAdaptiveIcons, boolean isInstantApp, float[] scale, boolean addShadow) { if (scale == null) { scale = new float[1]; } icon = normalizeAndWrapToAdaptiveIcon(icon, shrinkNonAdaptiveIcons, null, scale); Bitmap bitmap = createIconBitmap(icon, scale[0]); if (ATLEAST_OREO && icon instanceof AdaptiveIconDrawable) { if (addShadow) { mCanvas.setBitmap(bitmap); getShadowGenerator().recreateIcon(Bitmap.createBitmap(bitmap), mCanvas); mCanvas.setBitmap(null); } } if (isInstantApp) { badgeWithDrawable(bitmap, mContext.getDrawable(R.drawable.ic_instant_app_badge)); Loading
iconloaderlib/src/com/android/launcher3/icons/ShadowGenerator.java +45 −29 Original line number Diff line number Diff line Loading @@ -32,6 +32,9 @@ import android.graphics.RectF; * Utility class to add shadows to bitmaps. */ public class ShadowGenerator { public static final boolean ENABLE_SHADOWS = false; public static final float BLUR_FACTOR = 0.5f/48; // Percent of actual icon size Loading Loading @@ -60,6 +63,7 @@ public class ShadowGenerator { public synchronized void recreateIcon(Bitmap icon, BlurMaskFilter blurMaskFilter, int ambientAlpha, int keyAlpha, Canvas out) { if (ENABLE_SHADOWS) { int[] offset = new int[2]; mBlurPaint.setMaskFilter(blurMaskFilter); Bitmap shadow = icon.extractAlpha(mBlurPaint, offset); Loading @@ -70,7 +74,9 @@ public class ShadowGenerator { // Draw key shadow mDrawPaint.setAlpha(keyAlpha); out.drawBitmap(shadow, offset[0], offset[1] + KEY_SHADOW_DISTANCE * mIconSize, mDrawPaint); out.drawBitmap(shadow, offset[0], offset[1] + KEY_SHADOW_DISTANCE * mIconSize, mDrawPaint); } // Draw the icon mDrawPaint.setAlpha(255); Loading @@ -84,6 +90,7 @@ public class ShadowGenerator { public static float getScaleForBounds(RectF bounds) { float scale = 1; if (ENABLE_SHADOWS) { // For top, left & right, we need same space. float minSide = Math.min(Math.min(bounds.left, bounds.right), bounds.top); if (minSide < BLUR_FACTOR) { Loading @@ -92,7 +99,9 @@ public class ShadowGenerator { float bottomSpace = BLUR_FACTOR + KEY_SHADOW_DISTANCE; if (bounds.bottom < bottomSpace) { scale = Math.min(scale, (HALF_DISTANCE - bottomSpace) / (HALF_DISTANCE - bounds.bottom)); scale = Math.min(scale, (HALF_DISTANCE - bottomSpace) / (HALF_DISTANCE - bounds.bottom)); } } return scale; } Loading @@ -115,8 +124,13 @@ public class ShadowGenerator { } public Builder setupBlurForSize(int height) { if (ENABLE_SHADOWS) { shadowBlur = height * 1f / 24; keyShadowDistance = height * 1f / 16; } else { shadowBlur = 0; keyShadowDistance = 0; } return this; } Loading @@ -141,6 +155,7 @@ public class ShadowGenerator { Paint p = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG); p.setColor(color); if (ENABLE_SHADOWS) { // Key shadow p.setShadowLayer(shadowBlur, 0, keyShadowDistance, setColorAlphaBound(Color.BLACK, keyShadowAlpha)); Loading @@ -150,6 +165,7 @@ public class ShadowGenerator { p.setShadowLayer(shadowBlur, 0, 0, setColorAlphaBound(Color.BLACK, ambientShadowAlpha)); c.drawRoundRect(bounds, radius, radius, p); } if (Color.alpha(color) < 255) { // Clear any content inside the pill-rect for translucent fill. Loading
iconloaderlib/src/com/android/launcher3/icons/cache/BaseIconCache.java +1 −1 Original line number Diff line number Diff line Loading @@ -510,7 +510,7 @@ public abstract class BaseIconCache { * Cache class to store the actual entries on disk */ public static final class IconDB extends SQLiteCacheHelper { private static final int RELEASE_VERSION = 28; private static final int RELEASE_VERSION = 29; public static final String TABLE_NAME = "icons"; public static final String COLUMN_ROWID = "rowid"; Loading