Use compat adaptive icons for themed icon packs
This commit is contained in:
parent
f9cab47ca2
commit
fee45590d1
@ -243,10 +243,9 @@ icons.
|
|||||||
|
|
||||||
Themed icons can be provided in any of the following ways:
|
Themed icons can be provided in any of the following ways:
|
||||||
|
|
||||||
- If the icon is an adaptive icon, the device runs at least Android 13 and the drawable has
|
- If the icon is an adaptive icon, and the drawable has
|
||||||
a `<monochrome>` layer, this icon will be used as the themed icon.
|
a `<monochrome>` layer, this icon will be used as the themed icon.
|
||||||
- If the icon is an adaptive icon, and it does not have a `<monochrome>` layer or the device runs on
|
- If the icon is an adaptive icon, and it does not have a `<monochrome>` layer, the foreground layer will be used.
|
||||||
Android 12 or lower, the foreground layer will be used.
|
|
||||||
- If the icon is not an adaptive icon, the entire icon will be used.
|
- If the icon is not an adaptive icon, the entire icon will be used.
|
||||||
|
|
||||||
In any case, the icon will be tinted using the theme color and the background will be set to a solid
|
In any case, the icon will be tinted using the theme color and the background will be set to a solid
|
||||||
|
|||||||
@ -19,6 +19,8 @@ import androidx.core.content.res.ResourcesCompat
|
|||||||
import androidx.core.graphics.drawable.toBitmap
|
import androidx.core.graphics.drawable.toBitmap
|
||||||
import androidx.room.withTransaction
|
import androidx.room.withTransaction
|
||||||
import de.mm20.launcher2.database.AppDatabase
|
import de.mm20.launcher2.database.AppDatabase
|
||||||
|
import de.mm20.launcher2.icons.compat.AdaptiveIconDrawableCompat
|
||||||
|
import de.mm20.launcher2.icons.compat.toLauncherIcon
|
||||||
import de.mm20.launcher2.icons.loaders.AppFilterIconPackInstaller
|
import de.mm20.launcher2.icons.loaders.AppFilterIconPackInstaller
|
||||||
import de.mm20.launcher2.icons.loaders.GrayscaleMapIconPackInstaller
|
import de.mm20.launcher2.icons.loaders.GrayscaleMapIconPackInstaller
|
||||||
import de.mm20.launcher2.ktx.isAtLeastApiLevel
|
import de.mm20.launcher2.ktx.isAtLeastApiLevel
|
||||||
@ -247,6 +249,11 @@ class IconPackManager(
|
|||||||
val resId =
|
val resId =
|
||||||
resources.getIdentifier(icon.drawable, "drawable", icon.iconPack).takeIf { it != 0 }
|
resources.getIdentifier(icon.drawable, "drawable", icon.iconPack).takeIf { it != 0 }
|
||||||
?: return null
|
?: return null
|
||||||
|
|
||||||
|
val adaptiveIconCompat = AdaptiveIconDrawableCompat.from(resources, resId)
|
||||||
|
if (adaptiveIconCompat != null) {
|
||||||
|
return adaptiveIconCompat.toLauncherIcon(themed = allowThemed && icon.themed)
|
||||||
|
}
|
||||||
val drawable = try {
|
val drawable = try {
|
||||||
ResourcesCompat.getDrawable(resources, resId, context.theme) ?: return null
|
ResourcesCompat.getDrawable(resources, resId, context.theme) ?: return null
|
||||||
} catch (e: Resources.NotFoundException) {
|
} catch (e: Resources.NotFoundException) {
|
||||||
@ -342,9 +349,18 @@ class IconPackManager(
|
|||||||
resources: Resources,
|
resources: Resources,
|
||||||
allowThemed: Boolean,
|
allowThemed: Boolean,
|
||||||
): LauncherIcon? {
|
): LauncherIcon? {
|
||||||
var drawable = try {
|
val drawableId = try {
|
||||||
resources.getIdentifier(icon.drawable, "drawable", icon.iconPack).takeIf { it != 0 }
|
resources.getIdentifier(icon.drawable, "drawable", icon.iconPack).takeIf { it != 0 }
|
||||||
?.let { ResourcesCompat.getDrawable(resources, it, null) }
|
?: return null
|
||||||
|
} catch (e: Resources.NotFoundException) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
val adaptiveIconCompat = AdaptiveIconDrawableCompat.from(resources, drawableId)
|
||||||
|
if (adaptiveIconCompat != null) {
|
||||||
|
return adaptiveIconCompat.toLauncherIcon(icon.themed && allowThemed, icon.config)
|
||||||
|
}
|
||||||
|
val drawable = try {
|
||||||
|
ResourcesCompat.getDrawable(resources, drawableId, null)
|
||||||
} catch (e: Resources.NotFoundException) {
|
} catch (e: Resources.NotFoundException) {
|
||||||
null
|
null
|
||||||
} ?: return null
|
} ?: return null
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user