adding an initial implementation of the home screen grid

This commit is contained in:
tibbi
2022-09-17 18:58:28 +02:00
parent 0b51fb87d3
commit 889e70468e
6 changed files with 103 additions and 21 deletions

View File

@ -1,6 +1,9 @@
package com.simplemobiletools.launcher.extensions
import android.content.Context
import android.content.pm.LauncherApps
import android.graphics.drawable.Drawable
import android.os.Process
import com.simplemobiletools.commons.extensions.portrait
import com.simplemobiletools.launcher.R
import com.simplemobiletools.launcher.helpers.Config
@ -14,3 +17,25 @@ fun Context.getColumnCount(): Int {
resources.getInteger(R.integer.landscape_column_count)
}
}
fun Context.getDrawableForPackageName(packageName: String): Drawable? {
var drawable: Drawable? = null
try {
// try getting the properly colored launcher icons
val launcher = getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
val activityList = launcher.getActivityList(packageName, Process.myUserHandle())[0]
drawable = activityList.getBadgedIcon(0)
} catch (e: Exception) {
} catch (e: Error) {
}
if (drawable == null) {
drawable = try {
packageManager.getApplicationIcon(packageName)
} catch (ignored: Exception) {
null
}
}
return drawable
}