Skip to content

Commit

Permalink
Themed Icons: Improve icon quality and fix some icon generation
Browse files Browse the repository at this point in the history
Signed-off-by: DrDisagree <[email protected]>
  • Loading branch information
Mahmud0808 committed Feb 16, 2025
1 parent 6d1afce commit 4792204
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ open class MonochromeIconFactory internal constructor(
drawDrawable(icon.background)
drawDrawable(icon.foreground)
generateMono()
return ClippedMonoDrawable(this, insetForeground).create(context)
return ClippedMonoDrawable(this, insetForeground).create(context, mBitmapSize)
} else {
mFlatCanvas.drawColor(Color.WHITE)
drawDrawable(icon)
Expand Down Expand Up @@ -198,14 +198,14 @@ open class MonochromeIconFactory internal constructor(
}

companion object {
fun ClippedMonoDrawable.create(context: Context): BitmapDrawable {
val bitmap = drawableToBitmap(this)
fun ClippedMonoDrawable.create(context: Context, iconSize: Int): BitmapDrawable {
val bitmap = drawableToBitmap(this, iconSize)
return BitmapDrawable(context.resources, bitmap)
}

private fun drawableToBitmap(drawable: Drawable): Bitmap {
val width = drawable.intrinsicWidth.takeIf { it > 0 } ?: 100
val height = drawable.intrinsicHeight.takeIf { it > 0 } ?: 100
private fun drawableToBitmap(drawable: Drawable, iconSize: Int): Bitmap {
val width = drawable.intrinsicWidth.takeIf { it > 0 } ?: iconSize
val height = drawable.intrinsicHeight.takeIf { it > 0 } ?: iconSize
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
drawable.setBounds(0, 0, canvas.width, canvas.height)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.graphics.drawable.Drawable
import android.os.Build
import android.os.Handler
import android.os.Looper
import com.drdisagree.iconify.common.Const.LAUNCHER3_PACKAGE
import com.drdisagree.iconify.common.Preferences.APP_DRAWER_THEMED_ICONS
import com.drdisagree.iconify.common.Preferences.FORCE_THEMED_ICONS
import com.drdisagree.iconify.xposed.ModPack
Expand Down Expand Up @@ -66,6 +67,9 @@ class ThemedIcons(context: Context) : ModPack(context) {
}

try {
// Only for modified Launcher3
if (mContext.packageName != LAUNCHER3_PACKAGE) throw Throwable()

val launcherIconsClass = findClass("com.android.launcher3.icons.LauncherIcons")

launcherIconsClass
Expand Down Expand Up @@ -95,9 +99,9 @@ class ThemedIcons(context: Context) : ModPack(context) {
// If it's from com.android.launcher3.icons.IconProvider class and
// mentioned methods, monochrome is already included
Throwable().stackTrace.forEach { stackTrace ->
stackTrace.methodName.lowercase().let { methodName ->
stackTrace.methodName.lowercase().let { name ->
if (stackTrace.className.contains("IconProvider") &&
(methodName == "getIconWithOverrides" || methodName == "getIcon")
(name.contains("override") || name == "geticon")
) return@runAfter2
}
}
Expand Down

0 comments on commit 4792204

Please sign in to comment.