Add support for Android 13 themed icons

This commit is contained in:
MM20 2022-09-04 11:53:27 +02:00
parent 8be8875462
commit 57449d4fce
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
9 changed files with 33 additions and 6 deletions

View File

@ -41,6 +41,7 @@ class AppInstallation(
override suspend fun loadIcon(
context: Context,
size: Int,
themed: Boolean,
): LauncherIcon {
val icon = session.appIcon ?: return getPlaceholderIcon(context)
val foreground = BitmapDrawable(context.resources, icon)

View File

@ -13,9 +13,9 @@ import android.os.UserHandle
import androidx.core.content.getSystemService
import de.mm20.launcher2.icons.*
import de.mm20.launcher2.ktx.getSerialNumber
import de.mm20.launcher2.ktx.isAtLeastApiLevel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.koin.core.component.KoinComponent
/**
* An [Application] based on an [android.content.pm.LauncherActivityInfo]
@ -29,7 +29,7 @@ class LauncherApp(
activity = launcherActivityInfo.name,
flags = launcherActivityInfo.applicationInfo.flags,
version = getPackageVersionName(context, launcherActivityInfo.applicationInfo.packageName),
), KoinComponent {
) {
internal val userSerialNumber: Long = launcherActivityInfo.user.getSerialNumber(context)
val isMainProfile = launcherActivityInfo.user == Process.myUserHandle()
@ -44,6 +44,7 @@ class LauncherApp(
override suspend fun loadIcon(
context: Context,
size: Int,
themed: Boolean,
): LauncherIcon? {
try {
val icon =
@ -52,6 +53,15 @@ class LauncherApp(
} ?: return null
if (icon is AdaptiveIconDrawable) {
if (themed && isAtLeastApiLevel(33) && icon.monochrome != null) {
return StaticLauncherIcon(
foregroundLayer = TintedIconLayer(
scale = 1f,
icon = icon.monochrome!!,
),
backgroundLayer = ColorLayer()
)
}
return StaticLauncherIcon(
foregroundLayer = icon.foreground?.let {
StaticIconLayer(

View File

@ -15,6 +15,7 @@ import androidx.core.content.getSystemService
import de.mm20.launcher2.appshortcuts.R
import de.mm20.launcher2.icons.*
import de.mm20.launcher2.ktx.getSerialNumber
import de.mm20.launcher2.ktx.isAtLeastApiLevel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
@ -68,6 +69,7 @@ class AppShortcut(
override suspend fun loadIcon(
context: Context,
size: Int,
themed: Boolean,
): LauncherIcon? {
val launcherApps = context.getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
val icon = withContext(Dispatchers.IO) {
@ -77,6 +79,15 @@ class AppShortcut(
)
} ?: return null
if (icon is AdaptiveIconDrawable) {
if (themed && isAtLeastApiLevel(33) && icon.monochrome != null) {
return StaticLauncherIcon(
foregroundLayer = TintedIconLayer(
scale = 1f,
icon = icon.monochrome!!,
),
backgroundLayer = ColorLayer()
)
}
return StaticLauncherIcon(
foregroundLayer = icon.foreground?.let {
StaticIconLayer(

View File

@ -51,6 +51,7 @@ class Contact(
override suspend fun loadIcon(
context: Context,
size: Int,
themed: Boolean,
): LauncherIcon? {
val contentResolver = context.contentResolver
val bmp = withContext(Dispatchers.IO) {

View File

@ -42,6 +42,7 @@ open class LocalFile(
override suspend fun loadIcon(
context: Context,
size: Int,
themed: Boolean,
): LauncherIcon? {
if (!JavaIOFile(path).exists()) return null
when {

View File

@ -81,7 +81,7 @@ class IconRepository(
}
providers.add(GoogleClockIconProvider(context))
providers.add(CalendarIconProvider(context))
providers.add(SystemIconProvider(context))
providers.add(SystemIconProvider(context, settings.themedIcons))
providers.add(placeholderProvider)
cache.evictAll()
@ -131,7 +131,7 @@ class IconRepository(
private fun getProviders(customIcon: CustomIcon?): List<IconProvider> {
if (customIcon is UnmodifiedSystemDefaultIcon) {
return listOf(
SystemIconProvider(context)
SystemIconProvider(context, false)
)
}
if (customIcon is CustomIconPackIcon) {

View File

@ -5,9 +5,10 @@ import de.mm20.launcher2.icons.LauncherIcon
import de.mm20.launcher2.search.data.Searchable
class SystemIconProvider(
private val context: Context
private val context: Context,
private val themedIcons: Boolean,
) : IconProvider {
override suspend fun getIcon(searchable: Searchable, size: Int): LauncherIcon? {
return searchable.loadIcon(context, size)
return searchable.loadIcon(context, size, themedIcons)
}
}

View File

@ -37,6 +37,7 @@ abstract class Searchable : Comparable<Searchable> {
open suspend fun loadIcon(
context: Context,
size: Int,
themed: Boolean,
): LauncherIcon? = null
abstract fun getPlaceholderIcon(context: Context): StaticLauncherIcon

View File

@ -25,6 +25,7 @@ class Website(
override suspend fun loadIcon(
context: Context,
size: Int,
themed: Boolean,
): LauncherIcon? {
if (favicon.isEmpty()) return null
try {