From 0807681537dedbf1027903fcafaabbe6112946f0 Mon Sep 17 00:00:00 2001 From: Yash Garg Date: Mon, 27 Mar 2023 12:23:32 +0530 Subject: [PATCH 01/10] chore: setup for gradle standalone build --- iconloaderlib/build.gradle | 18 ++++-------------- searchuilib/build.gradle | 26 +------------------------- 2 files changed, 5 insertions(+), 39 deletions(-) diff --git a/iconloaderlib/build.gradle b/iconloaderlib/build.gradle index 23c7cb04..7b92aac6 100644 --- a/iconloaderlib/build.gradle +++ b/iconloaderlib/build.gradle @@ -1,25 +1,15 @@ plugins { - id 'sysuigradleproject.android-library-conventions' + id 'com.android.library' + id 'org.jetbrains.kotlin.android' } android { + namespace "com.android.launcher3.icons" sourceSets { main { - java.srcDirs = ['src', 'src_full_lib'] + java.srcDirs = ['src'] manifest.srcFile 'AndroidManifest.xml' res.srcDirs = ['res'] } } - - lintOptions { - abortOnError false - } - - tasks.withType(JavaCompile) { - options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" - } -} - -dependencies { - implementation "androidx.core:core" } diff --git a/searchuilib/build.gradle b/searchuilib/build.gradle index 6b5027b2..4e763db6 100644 --- a/searchuilib/build.gradle +++ b/searchuilib/build.gradle @@ -3,35 +3,11 @@ plugins { } android { - compileSdk TARGET_SDK.toInteger() - buildToolsVersion = BUILD_TOOLS_VERSION - - defaultConfig { - minSdkVersion TARGET_SDK.toInteger() - targetSdkVersion TARGET_SDK.toInteger() - } - + namespace "com.android.app.search" sourceSets { main { java.srcDirs = ['src'] manifest.srcFile 'AndroidManifest.xml' } } - - lintOptions { - abortOnError false - } - - tasks.withType(JavaCompile) { - options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" - } - - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } -} - -dependencies { - implementation "androidx.core:core:+" } -- GitLab From be47c1fd935ca4a687ae5ca7fe352652ff59c408 Mon Sep 17 00:00:00 2001 From: Yash Garg Date: Mon, 27 Mar 2023 21:17:45 +0530 Subject: [PATCH 02/10] feat(dots): notification count support for launcher3 app badges --- .../android/launcher3/icons/DotRenderer.java | 67 +++++++++++++++++-- 1 file changed, 63 insertions(+), 4 deletions(-) diff --git a/iconloaderlib/src/com/android/launcher3/icons/DotRenderer.java b/iconloaderlib/src/com/android/launcher3/icons/DotRenderer.java index a42232e3..f64688f0 100644 --- a/iconloaderlib/src/com/android/launcher3/icons/DotRenderer.java +++ b/iconloaderlib/src/com/android/launcher3/icons/DotRenderer.java @@ -27,9 +27,12 @@ import android.graphics.Path; import android.graphics.PathMeasure; import android.graphics.Rect; import android.graphics.RectF; +import android.graphics.Typeface; import android.util.Log; import android.view.ViewDebug; +import androidx.core.graphics.ColorUtils; + /** * Used to draw a notification dot on top of an icon. */ @@ -38,10 +41,15 @@ public class DotRenderer { private static final String TAG = "DotRenderer"; // The dot size is defined as a percentage of the app icon size. - private static final float SIZE_PERCENTAGE = 0.228f; + private static final float SIZE_PERCENTAGE = 0.21f; + private static final float SIZE_PERCENTAGE_WITH_COUNT = 0.28f; + + // The max number to draw on dots + private static final int MAX_COUNT = 99; private final float mCircleRadius; private final Paint mCirclePaint = new Paint(ANTI_ALIAS_FLAG | FILTER_BITMAP_FLAG); + private final Paint mTextPaint = new Paint(ANTI_ALIAS_FLAG | FILTER_BITMAP_FLAG); private final Bitmap mBackgroundWithShadow; private final float mBitmapOffset; @@ -51,8 +59,12 @@ public class DotRenderer { private final float[] mLeftDotPosition; private static final int MIN_DOT_SIZE = 1; - public DotRenderer(int iconSizePx, Path iconShapePath, int pathSize) { - int size = Math.round(SIZE_PERCENTAGE * iconSizePx); + private final Rect mTextRect = new Rect(); + private final boolean mDisplayCount; + + public DotRenderer(int iconSizePx, Path iconShapePath, int pathSize, Boolean displayCount, Typeface typeface) { + mDisplayCount = displayCount; + int size = Math.round((displayCount ? SIZE_PERCENTAGE_WITH_COUNT : SIZE_PERCENTAGE) * iconSizePx); if (size <= 0) { size = MIN_DOT_SIZE; } @@ -66,6 +78,10 @@ public class DotRenderer { // Find the points on the path that are closest to the top left and right corners. mLeftDotPosition = getPathPoint(iconShapePath, pathSize, -1); mRightDotPosition = getPathPoint(iconShapePath, pathSize, 1); + + mTextPaint.setTextSize(size * 0.65f); + mTextPaint.setTextAlign(Paint.Align.LEFT); + mTextPaint.setTypeface(typeface); } private static float[] getPathPoint(Path path, float size, float direction) { @@ -100,7 +116,7 @@ public class DotRenderer { /** * Draw a circle on top of the canvas according to the given params. */ - public void draw(Canvas canvas, DrawParams params) { + public void draw(Canvas canvas, DrawParams params, int numNotifications) { if (params == null) { Log.e(TAG, "Invalid null argument(s) passed in call to draw."); return; @@ -127,9 +143,30 @@ public class DotRenderer { canvas.drawBitmap(mBackgroundWithShadow, mBitmapOffset, mBitmapOffset, mCirclePaint); mCirclePaint.setColor(params.dotColor); canvas.drawCircle(0, 0, mCircleRadius, mCirclePaint); + + if (mDisplayCount && numNotifications > 0) { + // Draw the numNotifications text + mTextPaint.setColor(getCounterTextColor(Color.WHITE)); + String text = String.valueOf(Math.min(numNotifications, MAX_COUNT)); + mTextPaint.getTextBounds(text, 0, text.length(), mTextRect); + float x = (-mTextRect.width() / 2f - mTextRect.left) * getAdjustment(numNotifications); + float y = mTextRect.height() / 2f - mTextRect.bottom; + canvas.drawText(text, x, y, mTextPaint); + } + canvas.restore(); } + /** + * Returns the color to use for the counter text based on the dot's background color. + * + * @param dotBackgroundColor The color of the dot background. + * @return The color to use on the counter text. + */ + private int getCounterTextColor(int dotBackgroundColor) { + return ColorUtils.setAlphaComponent(dotBackgroundColor, 0xFF); + } + public static class DrawParams { /** The color (possibly based on the icon) to use for the dot. */ @ViewDebug.ExportedProperty(category = "notification dot", formatToHexString = true) @@ -147,4 +184,26 @@ public class DotRenderer { @ViewDebug.ExportedProperty(category = "notification dot") public boolean leftAlign; } + + /** + * An attempt to adjust digits to their perceived center, they were tuned with Roboto but should + * (hopefully) work with other OEM fonts as well. + */ + private float getAdjustment(int number) { + switch (number) { + case 1: + return 1.01f; + case 2: + return 0.99f; + case 3: + case 4: + case 6: + return 0.98f; + case 7: + return 1.02f; + case 9: + return 0.9f; + } + return 1f; + } } -- GitLab From 0fd9988aa6027818662efd0efc84acdfbb9d2656 Mon Sep 17 00:00:00 2001 From: TheScarastic Date: Tue, 4 Apr 2023 19:32:07 +0530 Subject: [PATCH 03/10] feat(icons): Add month icon support for calendar --- .../android/launcher3/icons/IconProvider.java | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/iconloaderlib/src/com/android/launcher3/icons/IconProvider.java b/iconloaderlib/src/com/android/launcher3/icons/IconProvider.java index e8ce3b18..2f36d741 100644 --- a/iconloaderlib/src/com/android/launcher3/icons/IconProvider.java +++ b/iconloaderlib/src/com/android/launcher3/icons/IconProvider.java @@ -69,6 +69,8 @@ public class IconProvider { public static final boolean ATLEAST_T = BuildCompat.isAtLeastT(); private static final String ICON_METADATA_KEY_PREFIX = ".dynamic_icons"; + private static final String MONTH_BG_ICON_METADATA_KEY_PREFIX = ".month_dynamic_icons"; + private static final String DAY_FG_ICON_METADATA_KEY_PREFIX = ".day_dynamic_icons"; private static final String SYSTEM_STATE_SEPARATOR = " "; @@ -173,7 +175,9 @@ public class IconProvider { .metaData; final Resources resources = pm.getResourcesForApplication(mCalendar.getPackageName()); final int id = getDynamicIconId(metadata, resources); - if (id != ID_NULL) { + final int[] monthDayIds = getDynamicBackgroundIconId(metadata, resources); + if (id != ID_NULL && (monthDayIds == null || + monthDayIds[0] == ID_NULL || monthDayIds[1] == ID_NULL )) { if (DEBUG) Log.d(TAG, "Got icon #" + id); Drawable drawable = resources.getDrawableForDensity(id, iconDpi, null /* theme */); if (ATLEAST_T && drawable instanceof AdaptiveIconDrawable && td != null) { @@ -191,6 +195,10 @@ public class IconProvider { } } return drawable; + } else if (monthDayIds != null) { + Drawable background = resources.getDrawableForDensity(monthDayIds[0], iconDpi, null /* theme */); + Drawable foreground = resources.getDrawableForDensity(monthDayIds[1], iconDpi, null /* theme */); + return new AdaptiveIconDrawable(background, foreground); } } catch (PackageManager.NameNotFoundException e) { if (DEBUG) { @@ -225,6 +233,28 @@ public class IconProvider { } } + private int[] getDynamicBackgroundIconId(Bundle metadata, Resources resources) { + if (metadata == null) { + return null; + } + String bgKey = mCalendar.getPackageName() + MONTH_BG_ICON_METADATA_KEY_PREFIX; + String fgKey = mCalendar.getPackageName() + DAY_FG_ICON_METADATA_KEY_PREFIX; + final int bgArrayId = metadata.getInt(bgKey, ID_NULL); + final int fgArrayId = metadata.getInt(fgKey, ID_NULL); + if (bgArrayId == ID_NULL || fgArrayId == ID_NULL) { + return null; + } + try { + return new int[] {resources.obtainTypedArray(bgArrayId).getResourceId(getMonth(), ID_NULL), + resources.obtainTypedArray(fgArrayId).getResourceId(getDay(), ID_NULL)}; + } catch (Resources.NotFoundException e) { + if (DEBUG) { + Log.d(TAG, "package defines '" + bgKey + " and " + fgKey + "' but corresponding array not found"); + } + return null; + } + } + /** * @return Today's day of the month, zero-indexed. */ @@ -232,6 +262,10 @@ public class IconProvider { return Calendar.getInstance().get(Calendar.DAY_OF_MONTH) - 1; } + private static int getMonth() { + return Calendar.getInstance().get(Calendar.MONTH); + } + private static ComponentName parseComponentOrNull(Context context, int resId) { String cn = context.getString(resId); return TextUtils.isEmpty(cn) ? null : ComponentName.unflattenFromString(cn); -- GitLab From da0c12663f2424657db40625a71018b57ee66508 Mon Sep 17 00:00:00 2001 From: TheScarastic Date: Thu, 13 Apr 2023 18:49:02 +0530 Subject: [PATCH 04/10] iconloader: Add unchanges constructor for aosp --- .../src/com/android/launcher3/icons/DotRenderer.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/iconloaderlib/src/com/android/launcher3/icons/DotRenderer.java b/iconloaderlib/src/com/android/launcher3/icons/DotRenderer.java index f64688f0..1f5c49be 100644 --- a/iconloaderlib/src/com/android/launcher3/icons/DotRenderer.java +++ b/iconloaderlib/src/com/android/launcher3/icons/DotRenderer.java @@ -62,6 +62,10 @@ public class DotRenderer { private final Rect mTextRect = new Rect(); private final boolean mDisplayCount; + public DotRenderer(int iconSizePx, Path iconShapePath, int pathSize) { + this(iconSizePx, iconShapePath, pathSize, false, null); + } + public DotRenderer(int iconSizePx, Path iconShapePath, int pathSize, Boolean displayCount, Typeface typeface) { mDisplayCount = displayCount; int size = Math.round((displayCount ? SIZE_PERCENTAGE_WITH_COUNT : SIZE_PERCENTAGE) * iconSizePx); @@ -116,6 +120,10 @@ public class DotRenderer { /** * Draw a circle on top of the canvas according to the given params. */ + public void draw(Canvas canvas, DrawParams params) { + draw(canvas, params, 0); + } + public void draw(Canvas canvas, DrawParams params, int numNotifications) { if (params == null) { Log.e(TAG, "Invalid null argument(s) passed in call to draw."); -- GitLab From b770cf906e52da888475aaa170314b01184d5238 Mon Sep 17 00:00:00 2001 From: TheScarastic Date: Thu, 12 Oct 2023 13:50:36 +0530 Subject: [PATCH 05/10] beautiful icons --- .../launcher3/icons/AdaptiveIconGenerator.kt | 26 +++++++++++++++++++ .../launcher3/icons/BaseIconFactory.java | 7 +++-- 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 iconloaderlib/src/com/android/launcher3/icons/AdaptiveIconGenerator.kt diff --git a/iconloaderlib/src/com/android/launcher3/icons/AdaptiveIconGenerator.kt b/iconloaderlib/src/com/android/launcher3/icons/AdaptiveIconGenerator.kt new file mode 100644 index 00000000..4a38395b --- /dev/null +++ b/iconloaderlib/src/com/android/launcher3/icons/AdaptiveIconGenerator.kt @@ -0,0 +1,26 @@ +package com.android.launcher3.icons + +import android.graphics.Bitmap +import android.graphics.drawable.Drawable +import androidx.core.graphics.drawable.toBitmap + +object AdaptiveIconGenerator { + private const val ICON_SCALE = 1.46f + + @JvmStatic + fun toBitmap(drawable: Drawable) = drawable.toBitmap() + + @JvmStatic + fun getScale(bitmap: Bitmap, scale: Float): Float { + val topRightPx = bitmap.getPixel(0, 0) + val topLeftPx = bitmap.getPixel(0, bitmap.height - 1) + val bottomRightPx = bitmap.getPixel(bitmap.width - 1, 0) + val bottomLeftPx = bitmap.getPixel(bitmap.width - 1, bitmap.height - 1) + + return if (!(topRightPx != 0 && topLeftPx != 0 && bottomRightPx != 0 && bottomLeftPx != 0)) { + scale + } else { + ICON_SCALE + } + } +} diff --git a/iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java b/iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java index 704df6f9..c694c947 100644 --- a/iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java +++ b/iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java @@ -38,6 +38,7 @@ import androidx.annotation.ColorInt; import androidx.annotation.IntDef; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.core.graphics.ColorUtils; import com.android.launcher3.icons.BitmapInfo.Extender; import com.android.launcher3.util.FlagOp; @@ -323,10 +324,12 @@ public class BaseIconFactory implements AutoCloseable { if (!outShape[0]) { FixedScaleDrawable fsd = ((FixedScaleDrawable) dr.getForeground()); fsd.setDrawable(icon); - fsd.setScale(scale); + Bitmap bitmap = AdaptiveIconGenerator.toBitmap(icon); + fsd.setScale(AdaptiveIconGenerator.getScale(bitmap, scale)); icon = dr; scale = getNormalizer().getScale(icon, outIconBounds, null, null); - ((ColorDrawable) dr.getBackground()).setColor(mWrapperBackgroundColor); + int color = ColorUtils.setAlphaComponent(new ColorExtractor().findDominantColorByHue(bitmap), 200); + ((ColorDrawable) dr.getBackground()).setColor(color); } } else { scale = getNormalizer().getScale(icon, outIconBounds, null, null); -- GitLab From e8460b863ee34cb4adb4f4e7a9cb8d5811011453 Mon Sep 17 00:00:00 2001 From: Yash Garg Date: Sat, 14 Oct 2023 09:27:56 +0000 Subject: [PATCH 06/10] chore: include core-ktx and .kt files --- iconloaderlib/Android.bp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/iconloaderlib/Android.bp b/iconloaderlib/Android.bp index 6867e6b5..fa3a34fe 100644 --- a/iconloaderlib/Android.bp +++ b/iconloaderlib/Android.bp @@ -22,12 +22,14 @@ android_library { min_sdk_version: "26", static_libs: [ "androidx.core_core", + "androidx.core_core-ktx", ], resource_dirs: [ "res", ], srcs: [ "src/**/*.java", + "src/**/*.kt", ], } @@ -37,6 +39,7 @@ android_library { min_sdk_version: "26", static_libs: [ "androidx.core_core", + "androidx.core_core-ktx", ], resource_dirs: [ "res", @@ -44,5 +47,6 @@ android_library { srcs: [ "src/**/*.java", "src_full_lib/**/*.java", + "src/**/*.kt", ], } -- GitLab From 213e7fdf655731501b2d1d9c05e3137c2c305f1b Mon Sep 17 00:00:00 2001 From: Yash Garg Date: Sun, 26 Nov 2023 23:03:41 +0530 Subject: [PATCH 07/10] feat: convert badge to round rect when count > 99 --- .../android/launcher3/icons/DotRenderer.java | 36 +++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/iconloaderlib/src/com/android/launcher3/icons/DotRenderer.java b/iconloaderlib/src/com/android/launcher3/icons/DotRenderer.java index 1f5c49be..0ffcede5 100644 --- a/iconloaderlib/src/com/android/launcher3/icons/DotRenderer.java +++ b/iconloaderlib/src/com/android/launcher3/icons/DotRenderer.java @@ -45,7 +45,7 @@ public class DotRenderer { private static final float SIZE_PERCENTAGE_WITH_COUNT = 0.28f; // The max number to draw on dots - private static final int MAX_COUNT = 99; + private static final int MAX_COUNT = 999; private final float mCircleRadius; private final Paint mCirclePaint = new Paint(ANTI_ALIAS_FLAG | FILTER_BITMAP_FLAG); @@ -144,18 +144,34 @@ public class DotRenderer { float offsetY = Math.max(0, canvasBounds.top - (dotCenterY + mBitmapOffset)); // We draw the dot relative to its center. - canvas.translate(dotCenterX + offsetX, dotCenterY + offsetY); + float dx = dotCenterX + offsetX; + float dy = dotCenterY + offsetY - 15f; + + if (numNotifications > 9 && numNotifications < 100) { + canvas.translate(dx - 3f, dy); + } else if (numNotifications > 99 && numNotifications < 1000) { + canvas.translate(dx + 6f, dy); + } else { + canvas.translate(dx - 12f, dy); + } + canvas.scale(params.scale, params.scale); - mCirclePaint.setColor(Color.BLACK); - canvas.drawBitmap(mBackgroundWithShadow, mBitmapOffset, mBitmapOffset, mCirclePaint); mCirclePaint.setColor(params.dotColor); - canvas.drawCircle(0, 0, mCircleRadius, mCirclePaint); + if (numNotifications > 9 && numNotifications < 100) { + canvas.drawRoundRect(new RectF(-mCircleRadius - 10, -mCircleRadius, mCircleRadius + 10, mCircleRadius), 50, 50, mCirclePaint); + } else if (numNotifications > 99 && numNotifications < 1000) { + canvas.drawRoundRect(new RectF(-mCircleRadius - 20, -mCircleRadius, mCircleRadius + 20, mCircleRadius), 50, 50, mCirclePaint); + } else { + canvas.drawCircle(0, 0, mCircleRadius, mCirclePaint); + } if (mDisplayCount && numNotifications > 0) { // Draw the numNotifications text mTextPaint.setColor(getCounterTextColor(Color.WHITE)); - String text = String.valueOf(Math.min(numNotifications, MAX_COUNT)); + mTextPaint.setTextSize(42f); + mTextPaint.setTypeface(Typeface.DEFAULT_BOLD); + String text = numToNotation(numNotifications); mTextPaint.getTextBounds(text, 0, text.length(), mTextRect); float x = (-mTextRect.width() / 2f - mTextRect.left) * getAdjustment(numNotifications); float y = mTextRect.height() / 2f - mTextRect.bottom; @@ -165,6 +181,14 @@ public class DotRenderer { canvas.restore(); } + private String numToNotation(int num) { + if (num < 1000) { + return String.valueOf(num); + } else { + return num / 1000 + "k"; + } + } + /** * Returns the color to use for the counter text based on the dot's background color. * -- GitLab From 291cbef9885c05283985c05c58797108d3f93b5d Mon Sep 17 00:00:00 2001 From: TheScarastic Date: Tue, 12 Dec 2023 14:08:26 +0530 Subject: [PATCH 08/10] DotRenderer: Add shadow to notification dots --- .../src/com/android/launcher3/icons/DotRenderer.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/iconloaderlib/src/com/android/launcher3/icons/DotRenderer.java b/iconloaderlib/src/com/android/launcher3/icons/DotRenderer.java index 0ffcede5..6de00d42 100644 --- a/iconloaderlib/src/com/android/launcher3/icons/DotRenderer.java +++ b/iconloaderlib/src/com/android/launcher3/icons/DotRenderer.java @@ -49,6 +49,8 @@ public class DotRenderer { private final float mCircleRadius; private final Paint mCirclePaint = new Paint(ANTI_ALIAS_FLAG | FILTER_BITMAP_FLAG); + private final Paint mCircleShadowPaint = new Paint(ANTI_ALIAS_FLAG | FILTER_BITMAP_FLAG); + private final Paint mTextPaint = new Paint(ANTI_ALIAS_FLAG | FILTER_BITMAP_FLAG); private final Bitmap mBackgroundWithShadow; @@ -158,11 +160,15 @@ public class DotRenderer { canvas.scale(params.scale, params.scale); mCirclePaint.setColor(params.dotColor); + mCircleShadowPaint.setColor(params.shadowDotColor); if (numNotifications > 9 && numNotifications < 100) { + canvas.drawRoundRect(new RectF(-mCircleRadius - 10, -mCircleRadius, mCircleRadius + 10, mCircleRadius + 3), 50, 50, mCircleShadowPaint); canvas.drawRoundRect(new RectF(-mCircleRadius - 10, -mCircleRadius, mCircleRadius + 10, mCircleRadius), 50, 50, mCirclePaint); } else if (numNotifications > 99 && numNotifications < 1000) { + canvas.drawRoundRect(new RectF(-mCircleRadius - 20, -mCircleRadius, mCircleRadius + 20, mCircleRadius + 3), 50, 50, mCircleShadowPaint); canvas.drawRoundRect(new RectF(-mCircleRadius - 20, -mCircleRadius, mCircleRadius + 20, mCircleRadius), 50, 50, mCirclePaint); } else { + canvas.drawCircle(0, 3, mCircleRadius, mCircleShadowPaint); canvas.drawCircle(0, 0, mCircleRadius, mCirclePaint); } @@ -215,6 +221,8 @@ public class DotRenderer { /** Whether the dot should align to the top left of the icon rather than the top right. */ @ViewDebug.ExportedProperty(category = "notification dot") public boolean leftAlign; + @ViewDebug.ExportedProperty(category = "notification dot", formatToHexString = true) + public int shadowDotColor; } /** -- GitLab From 1d7c8aae3e714f15de84d92965367cfc8f938087 Mon Sep 17 00:00:00 2001 From: Yash Garg Date: Thu, 1 Feb 2024 12:55:49 +0530 Subject: [PATCH 09/10] fix: check height width before converting to bitmap --- .../android/launcher3/icons/BaseIconFactory.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java b/iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java index c694c947..842d0eb0 100644 --- a/iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java +++ b/iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java @@ -324,11 +324,19 @@ public class BaseIconFactory implements AutoCloseable { if (!outShape[0]) { FixedScaleDrawable fsd = ((FixedScaleDrawable) dr.getForeground()); fsd.setDrawable(icon); - Bitmap bitmap = AdaptiveIconGenerator.toBitmap(icon); - fsd.setScale(AdaptiveIconGenerator.getScale(bitmap, scale)); + + int color; + if (icon.getIntrinsicHeight() > 0 && icon.getIntrinsicWidth() > 0) { + Bitmap bitmap = AdaptiveIconGenerator.toBitmap(icon); + fsd.setScale(AdaptiveIconGenerator.getScale(bitmap, scale)); + color = ColorUtils.setAlphaComponent(new ColorExtractor().findDominantColorByHue(bitmap), 200); + } else { + fsd.setScale(scale); + color = mWrapperBackgroundColor; + } + icon = dr; scale = getNormalizer().getScale(icon, outIconBounds, null, null); - int color = ColorUtils.setAlphaComponent(new ColorExtractor().findDominantColorByHue(bitmap), 200); ((ColorDrawable) dr.getBackground()).setColor(color); } } else { -- GitLab From 307cb3d518e6acadf18b23cd670f850dd32127bb Mon Sep 17 00:00:00 2001 From: althafvly Date: Thu, 29 Feb 2024 21:22:20 +0530 Subject: [PATCH 10/10] feat: adjust dot size accordingly --- .../android/launcher3/icons/DotRenderer.java | 51 +++++++------------ 1 file changed, 17 insertions(+), 34 deletions(-) diff --git a/iconloaderlib/src/com/android/launcher3/icons/DotRenderer.java b/iconloaderlib/src/com/android/launcher3/icons/DotRenderer.java index 6de00d42..066760de 100644 --- a/iconloaderlib/src/com/android/launcher3/icons/DotRenderer.java +++ b/iconloaderlib/src/com/android/launcher3/icons/DotRenderer.java @@ -76,7 +76,7 @@ public class DotRenderer { } ShadowGenerator.Builder builder = new ShadowGenerator.Builder(Color.TRANSPARENT); builder.ambientShadowAlpha = 88; - mBackgroundWithShadow = builder.setupBlurForSize(size).createPill(size, size); + mBackgroundWithShadow = builder.setupBlurForSize(size).createPill(size, displayCount ? (size - 25) : size); mCircleRadius = builder.radius; mBitmapOffset = -mBackgroundWithShadow.getHeight() * 0.5f; // Same as width. @@ -161,27 +161,32 @@ public class DotRenderer { mCirclePaint.setColor(params.dotColor); mCircleShadowPaint.setColor(params.shadowDotColor); - if (numNotifications > 9 && numNotifications < 100) { - canvas.drawRoundRect(new RectF(-mCircleRadius - 10, -mCircleRadius, mCircleRadius + 10, mCircleRadius + 3), 50, 50, mCircleShadowPaint); - canvas.drawRoundRect(new RectF(-mCircleRadius - 10, -mCircleRadius, mCircleRadius + 10, mCircleRadius), 50, 50, mCirclePaint); - } else if (numNotifications > 99 && numNotifications < 1000) { - canvas.drawRoundRect(new RectF(-mCircleRadius - 20, -mCircleRadius, mCircleRadius + 20, mCircleRadius + 3), 50, 50, mCircleShadowPaint); - canvas.drawRoundRect(new RectF(-mCircleRadius - 20, -mCircleRadius, mCircleRadius + 20, mCircleRadius), 50, 50, mCirclePaint); + + if (numNotifications >= 10 && numNotifications < 1000) { + canvas.drawRoundRect(new RectF(-mCircleRadius + 10, -mCircleRadius, mCircleRadius + 20, mCircleRadius), 50, 50, mCircleShadowPaint); + canvas.drawRoundRect(new RectF(-mCircleRadius + 10, -mCircleRadius, mCircleRadius + 20, mCircleRadius), 50, 50, mCirclePaint); } else { - canvas.drawCircle(0, 3, mCircleRadius, mCircleShadowPaint); - canvas.drawCircle(0, 0, mCircleRadius, mCirclePaint); + canvas.drawCircle(5, 10, mCircleRadius, mCircleShadowPaint); + canvas.drawCircle(5, 10, mCircleRadius, mCirclePaint); } if (mDisplayCount && numNotifications > 0) { // Draw the numNotifications text mTextPaint.setColor(getCounterTextColor(Color.WHITE)); - mTextPaint.setTextSize(42f); mTextPaint.setTypeface(Typeface.DEFAULT_BOLD); + mTextPaint.setTextSize(32f); String text = numToNotation(numNotifications); mTextPaint.getTextBounds(text, 0, text.length(), mTextRect); - float x = (-mTextRect.width() / 2f - mTextRect.left) * getAdjustment(numNotifications); float y = mTextRect.height() / 2f - mTextRect.bottom; - canvas.drawText(text, x, y, mTextPaint); + if (numNotifications < 10) { + canvas.drawText(text, -4f, 22f, mTextPaint); + } else if (numNotifications < 100) { + canvas.drawText(text, -4f, y, mTextPaint); + } else if (numNotifications >= 1000) { + canvas.drawText(text, -14f, 20f, mTextPaint); + } else { + canvas.drawText(text, -14f, y, mTextPaint); + } } canvas.restore(); @@ -224,26 +229,4 @@ public class DotRenderer { @ViewDebug.ExportedProperty(category = "notification dot", formatToHexString = true) public int shadowDotColor; } - - /** - * An attempt to adjust digits to their perceived center, they were tuned with Roboto but should - * (hopefully) work with other OEM fonts as well. - */ - private float getAdjustment(int number) { - switch (number) { - case 1: - return 1.01f; - case 2: - return 0.99f; - case 3: - case 4: - case 6: - return 0.98f; - case 7: - return 1.02f; - case 9: - return 0.9f; - } - return 1f; - } } -- GitLab