Skip to content

Commit

Permalink
fix: use static icon for splash screen because it draws only foregrou…
Browse files Browse the repository at this point in the history
…nd for non complicated icons
  • Loading branch information
RichardLuo0 committed Feb 20, 2025
1 parent cd9f3f8 commit 503a967
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.richardluo.globalIconPack.iconPack

import android.app.AndroidAppHelper
import android.content.ComponentName
import android.content.SharedPreferences
import android.content.pm.ApplicationInfo
Expand Down Expand Up @@ -27,6 +28,12 @@ abstract class IconPack(pref: SharedPreferences, val pack: String, val resources
}

protected val iconPackAsFallback = pref.get(Pref.ICON_PACK_AS_FALLBACK)
protected val staticIcon =
when (AndroidAppHelper.currentPackageName()) {
// https://cs.android.com/android/platform/superproject/+/android15-qpr1-release:frameworks/base/libs/WindowManager/Shell/src/com/android/wm/shell/startingsurface/SplashscreenContentDrawer.java;l=676
"com.android.systemui" -> true
else -> false
}
protected var iconFallback: IconFallback? = null

protected fun initFallbackSettings(fs: FallbackSettings, pref: SharedPreferences) {
Expand All @@ -48,7 +55,7 @@ abstract class IconPack(pref: SharedPreferences, val pack: String, val resources
protected abstract fun getIconNotAdaptive(entry: IconEntry, iconDpi: Int): Drawable?

fun getIcon(entry: IconEntry, iconDpi: Int) =
getIconNotAdaptive(entry, iconDpi)?.let { IconHelper.makeAdaptive(it) }
getIconNotAdaptive(entry, iconDpi)?.let { IconHelper.makeAdaptive(it, staticIcon) }

fun getIcon(id: Int, iconDpi: Int) = getIconEntry(id)?.let { getIcon(it, iconDpi) }

Expand All @@ -63,6 +70,7 @@ abstract class IconPack(pref: SharedPreferences, val pack: String, val resources
iconUpons.randomOrNull(),
iconMasks.randomOrNull(),
iconScale,
staticIcon,
)
} ?: baseIcon
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.richardluo.globalIconPack.utils

import android.app.AndroidAppHelper
import android.content.res.Resources
import android.graphics.Bitmap
import android.graphics.Canvas
Expand Down Expand Up @@ -118,7 +117,7 @@ object IconHelper {
}
}

fun processIconToStatic(
private fun processIconToStatic(
res: Resources,
drawable: Drawable,
back: Bitmap?,
Expand All @@ -137,7 +136,7 @@ object IconHelper {
else CustomDrawable(it, back, upon, mask)
}

fun processIconToAdaptive(
private fun processIconToAdaptive(
res: Resources,
drawable: Drawable,
back: Bitmap?,
Expand Down Expand Up @@ -170,12 +169,13 @@ object IconHelper {
upon: Bitmap?,
mask: Bitmap?,
iconScale: Float = 1f,
static: Boolean = false,
) =
if (useUnClipAdaptive) processIconToAdaptive(res, drawable, back, upon, mask, iconScale)
else processIconToStatic(res, drawable, back, upon, mask, iconScale)
if (static) processIconToStatic(res, drawable, back, upon, mask, iconScale)
else processIconToAdaptive(res, drawable, back, upon, mask, iconScale)

fun makeAdaptive(drawable: Drawable) =
if (useUnClipAdaptive && drawable !is AdaptiveIconDrawable)
fun makeAdaptive(drawable: Drawable, static: Boolean = false) =
if (!static && drawable !is AdaptiveIconDrawable)
UnClipAdaptiveIconDrawable(ColorDrawable(Color.TRANSPARENT), createScaledDrawable(drawable))
else drawable

Expand Down Expand Up @@ -230,20 +230,3 @@ object IconHelper {
return InsetDrawable(drawable, scaleX, scaleY, scaleX, scaleY)
}
}

/**
* UnClipAdaptiveIconDrawable does not work correctly for some apps. It maybe clipped by adaptive
* icon mask or shows black background, but we don't know how to efficiently convert Bitmap to Path.
*/
private val useUnClipAdaptive: Boolean by lazy {
if (!isInMod) false
else
when (AndroidAppHelper.currentPackageName()) {
// Fix app list, black background sometimes
"com.android.settings" -> false
// Fix splash screen
"com.android.systemui" -> false
"com.android.intentresolver" -> true
else -> true
}
}

0 comments on commit 503a967

Please sign in to comment.