Loading iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java +11 −1 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Process; import android.os.UserHandle; import androidx.annotation.NonNull; /** Loading @@ -35,6 +36,8 @@ public class BaseIconFactory implements AutoCloseable { static final boolean ATLEAST_OREO = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O; static final boolean ATLEAST_P = Build.VERSION.SDK_INT >= Build.VERSION_CODES.P; private static final float ICON_BADGE_SCALE = 0.444f; private final Rect mOldBounds = new Rect(); protected final Context mContext; private final Canvas mCanvas; Loading Loading @@ -254,7 +257,7 @@ public class BaseIconFactory implements AutoCloseable { * Adds the {@param badge} on top of {@param target} using the badge dimensions. */ public void badgeWithDrawable(Canvas target, Drawable badge) { int badgeSize = mContext.getResources().getDimensionPixelSize(R.dimen.profile_badge_size); int badgeSize = getBadgeSizeForIconSize(mIconBitmapSize); badge.setBounds(mIconBitmapSize - badgeSize, mIconBitmapSize - badgeSize, mIconBitmapSize, mIconBitmapSize); badge.draw(target); Loading Loading @@ -334,6 +337,13 @@ public class BaseIconFactory implements AutoCloseable { iconDpi); } /** * Returns the correct badge size given an icon size */ public static int getBadgeSizeForIconSize(int iconSize) { return (int) (ICON_BADGE_SCALE * iconSize); } /** * An extension of {@link BitmapDrawable} which returns the bitmap pixel size as intrinsic size. * This allows the badging to be done based on the action bitmap size rather than Loading src/com/android/launcher3/Utilities.java +1 −1 Original line number Diff line number Diff line Loading @@ -584,7 +584,7 @@ public final class Utilities { LauncherIcons li = LauncherIcons.obtain(appState.getContext()); Bitmap badge = li.getShortcutInfoBadge(si, appState.getIconCache()).iconBitmap; li.recycle(); float badgeSize = launcher.getResources().getDimension(R.dimen.profile_badge_size); float badgeSize = iconSize * LauncherIcons.getBadgeSizeForIconSize(iconSize); float insetFraction = (iconSize - badgeSize) / iconSize; return new InsetDrawable(new FastBitmapDrawable(badge), insetFraction, insetFraction, 0, 0); Loading src/com/android/launcher3/graphics/DrawableFactory.java +3 −4 Original line number Diff line number Diff line Loading @@ -80,26 +80,25 @@ public class DrawableFactory implements ResourceBasedOverride { * Returns a drawable that can be used as a badge for the user or null. */ @UiThread public Drawable getBadgeForUser(UserHandle user, Context context) { public Drawable getBadgeForUser(UserHandle user, Context context, int badgeSize) { if (mMyUser.equals(user)) { return null; } Bitmap badgeBitmap = getUserBadge(user, context); Bitmap badgeBitmap = getUserBadge(user, context, badgeSize); FastBitmapDrawable d = new FastBitmapDrawable(badgeBitmap); d.setFilterBitmap(true); d.setBounds(0, 0, badgeBitmap.getWidth(), badgeBitmap.getHeight()); return d; } protected synchronized Bitmap getUserBadge(UserHandle user, Context context) { protected synchronized Bitmap getUserBadge(UserHandle user, Context context, int badgeSize) { Bitmap badgeBitmap = mUserBadges.get(user); if (badgeBitmap != null) { return badgeBitmap; } final Resources res = context.getApplicationContext().getResources(); int badgeSize = res.getDimensionPixelSize(R.dimen.profile_badge_size); badgeBitmap = Bitmap.createBitmap(badgeSize, badgeSize, Bitmap.Config.ARGB_8888); Drawable drawable = context.getPackageManager().getUserBadgedDrawableForDensity( Loading src/com/android/launcher3/widget/WidgetCell.java +8 −4 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ import com.android.launcher3.SimpleOnStylusPressListener; import com.android.launcher3.StylusEventHelper; import com.android.launcher3.WidgetPreviewLoader; import com.android.launcher3.graphics.DrawableFactory; import com.android.launcher3.icons.BaseIconFactory; import com.android.launcher3.model.WidgetItem; /** Loading Loading @@ -80,6 +81,7 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener { private Bitmap mDeferredBitmap; protected final BaseActivity mActivity; protected DeviceProfile mDeviceProfile; public WidgetCell(Context context) { this(context, null); Loading @@ -93,6 +95,7 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener { super(context, attrs, defStyle); mActivity = BaseActivity.fromContext(context); mDeviceProfile = mActivity.getDeviceProfile(); mStylusEventHelper = new StylusEventHelper(new SimpleOnStylusPressListener(this), this); setContainerWidth(); Loading @@ -102,8 +105,7 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener { } private void setContainerWidth() { DeviceProfile profile = mActivity.getDeviceProfile(); mCellSize = (int) (profile.allAppsCellWidthPx * WIDTH_SCALE); mCellSize = (int) (mDeviceProfile.allAppsCellWidthPx * WIDTH_SCALE); mPresetPreviewSize = (int) (mCellSize * PREVIEW_SCALE); } Loading Loading @@ -180,8 +182,10 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener { return; } if (bitmap != null) { mWidgetImage.setBitmap(bitmap, DrawableFactory.INSTANCE.get(getContext()) .getBadgeForUser(mItem.user, getContext())); mWidgetImage.setBitmap(bitmap, DrawableFactory.INSTANCE.get(getContext()).getBadgeForUser(mItem.user, getContext(), BaseIconFactory.getBadgeSizeForIconSize( mDeviceProfile.allAppsIconSizePx))); if (mAnimatePreview) { mWidgetImage.setAlpha(0f); ViewPropertyAnimator anim = mWidgetImage.animate(); Loading Loading
iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java +11 −1 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Process; import android.os.UserHandle; import androidx.annotation.NonNull; /** Loading @@ -35,6 +36,8 @@ public class BaseIconFactory implements AutoCloseable { static final boolean ATLEAST_OREO = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O; static final boolean ATLEAST_P = Build.VERSION.SDK_INT >= Build.VERSION_CODES.P; private static final float ICON_BADGE_SCALE = 0.444f; private final Rect mOldBounds = new Rect(); protected final Context mContext; private final Canvas mCanvas; Loading Loading @@ -254,7 +257,7 @@ public class BaseIconFactory implements AutoCloseable { * Adds the {@param badge} on top of {@param target} using the badge dimensions. */ public void badgeWithDrawable(Canvas target, Drawable badge) { int badgeSize = mContext.getResources().getDimensionPixelSize(R.dimen.profile_badge_size); int badgeSize = getBadgeSizeForIconSize(mIconBitmapSize); badge.setBounds(mIconBitmapSize - badgeSize, mIconBitmapSize - badgeSize, mIconBitmapSize, mIconBitmapSize); badge.draw(target); Loading Loading @@ -334,6 +337,13 @@ public class BaseIconFactory implements AutoCloseable { iconDpi); } /** * Returns the correct badge size given an icon size */ public static int getBadgeSizeForIconSize(int iconSize) { return (int) (ICON_BADGE_SCALE * iconSize); } /** * An extension of {@link BitmapDrawable} which returns the bitmap pixel size as intrinsic size. * This allows the badging to be done based on the action bitmap size rather than Loading
src/com/android/launcher3/Utilities.java +1 −1 Original line number Diff line number Diff line Loading @@ -584,7 +584,7 @@ public final class Utilities { LauncherIcons li = LauncherIcons.obtain(appState.getContext()); Bitmap badge = li.getShortcutInfoBadge(si, appState.getIconCache()).iconBitmap; li.recycle(); float badgeSize = launcher.getResources().getDimension(R.dimen.profile_badge_size); float badgeSize = iconSize * LauncherIcons.getBadgeSizeForIconSize(iconSize); float insetFraction = (iconSize - badgeSize) / iconSize; return new InsetDrawable(new FastBitmapDrawable(badge), insetFraction, insetFraction, 0, 0); Loading
src/com/android/launcher3/graphics/DrawableFactory.java +3 −4 Original line number Diff line number Diff line Loading @@ -80,26 +80,25 @@ public class DrawableFactory implements ResourceBasedOverride { * Returns a drawable that can be used as a badge for the user or null. */ @UiThread public Drawable getBadgeForUser(UserHandle user, Context context) { public Drawable getBadgeForUser(UserHandle user, Context context, int badgeSize) { if (mMyUser.equals(user)) { return null; } Bitmap badgeBitmap = getUserBadge(user, context); Bitmap badgeBitmap = getUserBadge(user, context, badgeSize); FastBitmapDrawable d = new FastBitmapDrawable(badgeBitmap); d.setFilterBitmap(true); d.setBounds(0, 0, badgeBitmap.getWidth(), badgeBitmap.getHeight()); return d; } protected synchronized Bitmap getUserBadge(UserHandle user, Context context) { protected synchronized Bitmap getUserBadge(UserHandle user, Context context, int badgeSize) { Bitmap badgeBitmap = mUserBadges.get(user); if (badgeBitmap != null) { return badgeBitmap; } final Resources res = context.getApplicationContext().getResources(); int badgeSize = res.getDimensionPixelSize(R.dimen.profile_badge_size); badgeBitmap = Bitmap.createBitmap(badgeSize, badgeSize, Bitmap.Config.ARGB_8888); Drawable drawable = context.getPackageManager().getUserBadgedDrawableForDensity( Loading
src/com/android/launcher3/widget/WidgetCell.java +8 −4 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ import com.android.launcher3.SimpleOnStylusPressListener; import com.android.launcher3.StylusEventHelper; import com.android.launcher3.WidgetPreviewLoader; import com.android.launcher3.graphics.DrawableFactory; import com.android.launcher3.icons.BaseIconFactory; import com.android.launcher3.model.WidgetItem; /** Loading Loading @@ -80,6 +81,7 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener { private Bitmap mDeferredBitmap; protected final BaseActivity mActivity; protected DeviceProfile mDeviceProfile; public WidgetCell(Context context) { this(context, null); Loading @@ -93,6 +95,7 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener { super(context, attrs, defStyle); mActivity = BaseActivity.fromContext(context); mDeviceProfile = mActivity.getDeviceProfile(); mStylusEventHelper = new StylusEventHelper(new SimpleOnStylusPressListener(this), this); setContainerWidth(); Loading @@ -102,8 +105,7 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener { } private void setContainerWidth() { DeviceProfile profile = mActivity.getDeviceProfile(); mCellSize = (int) (profile.allAppsCellWidthPx * WIDTH_SCALE); mCellSize = (int) (mDeviceProfile.allAppsCellWidthPx * WIDTH_SCALE); mPresetPreviewSize = (int) (mCellSize * PREVIEW_SCALE); } Loading Loading @@ -180,8 +182,10 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener { return; } if (bitmap != null) { mWidgetImage.setBitmap(bitmap, DrawableFactory.INSTANCE.get(getContext()) .getBadgeForUser(mItem.user, getContext())); mWidgetImage.setBitmap(bitmap, DrawableFactory.INSTANCE.get(getContext()).getBadgeForUser(mItem.user, getContext(), BaseIconFactory.getBadgeSizeForIconSize( mDeviceProfile.allAppsIconSizePx))); if (mAnimatePreview) { mWidgetImage.setAlpha(0f); ViewPropertyAnimator anim = mWidgetImage.animate(); Loading