mirror of
https://github.com/SimpleMobileTools/Simple-Launcher.git
synced 2025-06-05 21:59:15 +02:00
adding an initial implementation of the home screen grid
This commit is contained in:
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user