From ead87ef7208ee03e12bbf761cf197b6cc9c62447 Mon Sep 17 00:00:00 2001 From: Kshitij Gupta Date: Mon, 27 Jan 2025 14:55:10 +0530 Subject: [PATCH] fix: Revert badge size and position to pre-tablet [2/2] --- .../android/launcher3/icons/DotRenderer.java | 56 ++++++++++++------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/iconloaderlib/src/com/android/launcher3/icons/DotRenderer.java b/iconloaderlib/src/com/android/launcher3/icons/DotRenderer.java index 3131e67f..daede101 100644 --- a/iconloaderlib/src/com/android/launcher3/icons/DotRenderer.java +++ b/iconloaderlib/src/com/android/launcher3/icons/DotRenderer.java @@ -42,7 +42,8 @@ public class DotRenderer { // The dot size is defined as a percentage of the app icon size. private static final float SIZE_PERCENTAGE = 0.21f; - private static final float SIZE_PERCENTAGE_WITH_COUNT = 0.24f; + private static final float SIZE_PERCENTAGE_WITH_COUNT = 0.28f; + private static final float SIZE_PERCENTAGE_WITH_COUNT_TABLET = 0.24f; // The max number to draw on dots private static final int MAX_COUNT = 999; @@ -65,12 +66,12 @@ public class DotRenderer { private final boolean mDisplayCount; public DotRenderer(int iconSizePx, Path iconShapePath, int pathSize) { - this(iconSizePx, iconShapePath, pathSize, false, null); + this(iconSizePx, iconShapePath, pathSize, false, null, false); } - public DotRenderer(int iconSizePx, Path iconShapePath, int pathSize, Boolean displayCount, Typeface typeface) { + public DotRenderer(int iconSizePx, Path iconShapePath, int pathSize, Boolean displayCount, Typeface typeface, boolean isTablet) { mDisplayCount = displayCount; - int size = Math.round((displayCount ? SIZE_PERCENTAGE_WITH_COUNT : SIZE_PERCENTAGE) * iconSizePx); + int size = Math.round((displayCount ? (isTablet ? SIZE_PERCENTAGE_WITH_COUNT_TABLET : SIZE_PERCENTAGE_WITH_COUNT) : SIZE_PERCENTAGE) * iconSizePx); if (size <= 0) { size = MIN_DOT_SIZE; } @@ -146,21 +147,38 @@ public class DotRenderer { // Ensure dot fits entirely in canvas clip bounds. Rect canvasBounds = canvas.getClipBounds(); - // We draw the dot relative to its center. - float availableWidth = (float) (canvasBounds.width() - iconBounds.width()) / 2; - - // We check if the dot is too close to the edge of the screen and nudge it if necessary. - boolean mustNudge = isTablet && availableWidth < mCircleRadius; - float dx = mustNudge? mCircleRadius: dotCenterX; - - // Taskbar icons are too small and do not show the dot text. - // We will displace the dot to the correct position. - if (isTaskbar) { - canvas.translate(dotCenterX - mCircleRadius, dotCenterY - mCircleRadius); - } else if (numNotifications > 9 && numNotifications < 1000) { - canvas.translate(dx - (mustNudge ? 12f : 17f), dotCenterY); - } else if (numNotifications > 0) { - canvas.translate(dx - 12f, dotCenterY); + if (isTablet) { + // We draw the dot relative to its center. + float availableWidth = (float) (canvasBounds.width() - iconBounds.width()) / 2; + + // We check if the dot is too close to the edge of the screen and nudge it if necessary. + boolean mustNudge = availableWidth < mCircleRadius; + float dx = mustNudge ? mCircleRadius : dotCenterX; + + // Taskbar icons are too small and do not show the dot text. + // We will displace the dot to the correct position. + if (isTaskbar) { + canvas.translate(dotCenterX - mCircleRadius, dotCenterY - mCircleRadius); + } else if (numNotifications > 9 && numNotifications < 1000) { + canvas.translate(dx - (mustNudge ? 12f : 17f), dotCenterY); + } else if (numNotifications > 0) { + canvas.translate(dx - 12f, dotCenterY); + } + } else { + float offsetX = params.leftAlign + ? Math.max(0, canvasBounds.left - (dotCenterX + mBitmapOffset)) + : Math.min(0, canvasBounds.right - (dotCenterX - mBitmapOffset)); + float offsetY = Math.max(0, canvasBounds.top - (dotCenterY + mBitmapOffset)); + + // We draw the dot relative to its center. + float dx = dotCenterX + offsetX; + float dy = dotCenterY + offsetY - 15f; + + if (numNotifications > 9 && numNotifications < 1000) { + canvas.translate(dx - 17f, dy); + } else if (numNotifications > 0) { + canvas.translate(dx - 12f, dy); + } } float scale = params.scale * (isTablet && !isTaskbar ? 0.75f : 1f); -- GitLab