Refactor icons
This commit is contained in:
@@ -3,24 +3,22 @@ package de.mm20.launcher2.search.data
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageInstaller
|
||||
import android.graphics.Color
|
||||
import android.graphics.ColorMatrix
|
||||
import android.graphics.ColorMatrixColorFilter
|
||||
import android.graphics.drawable.BitmapDrawable
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import androidx.core.content.ContextCompat
|
||||
import de.mm20.launcher2.applications.R
|
||||
import de.mm20.launcher2.icons.LauncherIcon
|
||||
import de.mm20.launcher2.preferences.Settings
|
||||
import de.mm20.launcher2.preferences.Settings.IconSettings.LegacyIconBackground
|
||||
import de.mm20.launcher2.icons.*
|
||||
|
||||
class AppInstallation(
|
||||
val session: PackageInstaller.SessionInfo
|
||||
val session: PackageInstaller.SessionInfo
|
||||
) : Application(
|
||||
label = session.appLabel?.toString() ?: "",
|
||||
`package` = session.appPackageName ?: "",
|
||||
activity = "",
|
||||
flags = 0,
|
||||
version = null
|
||||
label = session.appLabel?.toString() ?: "",
|
||||
`package` = session.appPackageName ?: "",
|
||||
activity = "",
|
||||
flags = 0,
|
||||
version = null
|
||||
) {
|
||||
|
||||
override val key: String
|
||||
@@ -30,22 +28,31 @@ class AppInstallation(
|
||||
return session.createDetailsIntent()
|
||||
}
|
||||
|
||||
override fun getPlaceholderIcon(context: Context): LauncherIcon {
|
||||
return LauncherIcon(
|
||||
foreground = ContextCompat.getDrawable(context, R.drawable.ic_file_android)!!,
|
||||
background = ColorDrawable(ContextCompat.getColor(context, R.color.grey)),
|
||||
foregroundScale = 0.5f)
|
||||
override fun getPlaceholderIcon(context: Context): StaticLauncherIcon {
|
||||
return StaticLauncherIcon(
|
||||
foregroundLayer = TintedIconLayer(
|
||||
icon = ContextCompat.getDrawable(context, R.drawable.ic_file_android)!!,
|
||||
scale = 0.5f,
|
||||
color = Color.WHITE
|
||||
),
|
||||
backgroundLayer = ColorLayer(ContextCompat.getColor(context, R.color.grey))
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun loadIcon(context: Context, size: Int, legacyIconBackground: LegacyIconBackground): LauncherIcon? {
|
||||
override suspend fun loadIcon(
|
||||
context: Context,
|
||||
size: Int,
|
||||
): LauncherIcon {
|
||||
val icon = session.appIcon ?: return getPlaceholderIcon(context)
|
||||
val foreground = BitmapDrawable(context.resources, icon)
|
||||
foreground.colorFilter = ColorMatrixColorFilter(ColorMatrix().apply {
|
||||
setSaturation(0f)
|
||||
})
|
||||
return LauncherIcon(
|
||||
foreground = foreground,
|
||||
background = ColorDrawable(ContextCompat.getColor(context, R.color.grey))
|
||||
return StaticLauncherIcon(
|
||||
foregroundLayer = StaticIconLayer(
|
||||
icon = foreground,
|
||||
),
|
||||
backgroundLayer = ColorLayer(ContextCompat.getColor(context, R.color.grey))
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -4,12 +4,13 @@ import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.util.Log
|
||||
import android.graphics.Color
|
||||
import androidx.core.content.ContextCompat
|
||||
import de.mm20.launcher2.applications.R
|
||||
import de.mm20.launcher2.compat.PackageManagerCompat
|
||||
import de.mm20.launcher2.icons.LauncherIcon
|
||||
import de.mm20.launcher2.icons.ColorLayer
|
||||
import de.mm20.launcher2.icons.StaticLauncherIcon
|
||||
import de.mm20.launcher2.icons.TintedIconLayer
|
||||
import org.json.JSONObject
|
||||
|
||||
abstract class Application(
|
||||
@@ -34,11 +35,14 @@ abstract class Application(
|
||||
return intent
|
||||
}
|
||||
|
||||
override fun getPlaceholderIcon(context: Context): LauncherIcon {
|
||||
return LauncherIcon(
|
||||
foreground = ContextCompat.getDrawable(context, R.drawable.ic_file_android)!!,
|
||||
background = ColorDrawable(ContextCompat.getColor(context, R.color.lightgreen)),
|
||||
foregroundScale = 0.5f
|
||||
override fun getPlaceholderIcon(context: Context): StaticLauncherIcon {
|
||||
return StaticLauncherIcon(
|
||||
foregroundLayer = TintedIconLayer(
|
||||
icon = ContextCompat.getDrawable(context, R.drawable.ic_file_android)!!,
|
||||
scale = 0.5f,
|
||||
color = Color.WHITE,
|
||||
),
|
||||
backgroundLayer = ColorLayer(ContextCompat.getColor(context, R.color.android_green))
|
||||
)
|
||||
}
|
||||
|
||||
@@ -56,7 +60,10 @@ abstract class Application(
|
||||
get() = "app://$`package`:$activity"
|
||||
|
||||
companion object {
|
||||
internal fun getStoreLinkForInstaller(installerPackage: String?, packageName: String?): StoreLink? {
|
||||
internal fun getStoreLinkForInstaller(
|
||||
installerPackage: String?,
|
||||
packageName: String?
|
||||
): StoreLink? {
|
||||
if (packageName == null) return null
|
||||
return when (installerPackage) {
|
||||
"de.amazon.mShop.android", "com.amazon.venezia" -> {
|
||||
|
||||
@@ -11,9 +11,8 @@ import android.os.Bundle
|
||||
import android.os.Process
|
||||
import android.os.UserHandle
|
||||
import androidx.core.content.getSystemService
|
||||
import de.mm20.launcher2.icons.LauncherIcon
|
||||
import de.mm20.launcher2.icons.*
|
||||
import de.mm20.launcher2.ktx.getSerialNumber
|
||||
import de.mm20.launcher2.preferences.Settings.IconSettings.LegacyIconBackground
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.koin.core.component.KoinComponent
|
||||
@@ -45,7 +44,6 @@ class LauncherApp(
|
||||
override suspend fun loadIcon(
|
||||
context: Context,
|
||||
size: Int,
|
||||
legacyIconBackground: LegacyIconBackground
|
||||
): LauncherIcon? {
|
||||
try {
|
||||
val icon =
|
||||
@@ -54,17 +52,23 @@ class LauncherApp(
|
||||
|
||||
} ?: return null
|
||||
if (icon is AdaptiveIconDrawable) {
|
||||
return LauncherIcon(
|
||||
foreground = icon.foreground ?: return null,
|
||||
background = icon.background,
|
||||
foregroundScale = 1.5f,
|
||||
backgroundScale = 1.5f
|
||||
return StaticLauncherIcon(
|
||||
foregroundLayer = StaticIconLayer(
|
||||
icon = icon.foreground,
|
||||
scale = 1.5f,
|
||||
),
|
||||
backgroundLayer = StaticIconLayer(
|
||||
icon = icon.background,
|
||||
scale = 1.5f,
|
||||
)
|
||||
)
|
||||
} else {
|
||||
return LauncherIcon(
|
||||
foreground = icon,
|
||||
foregroundScale = 0.7f,
|
||||
autoGenerateBackgroundMode = legacyIconBackground.number
|
||||
return StaticLauncherIcon(
|
||||
foregroundLayer = StaticIconLayer(
|
||||
icon = icon,
|
||||
scale = 1f,
|
||||
),
|
||||
backgroundLayer = TransparentLayer
|
||||
)
|
||||
}
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
|
||||
Reference in New Issue
Block a user