list also those widgets that are acutally shortcuts
This commit is contained in:
parent
67911bbd59
commit
a78374ee59
1 changed files with 18 additions and 1 deletions
|
@ -2,7 +2,9 @@ package com.simplemobiletools.launcher.fragments
|
|||
|
||||
import android.appwidget.AppWidgetManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.LauncherApps
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Process
|
||||
import android.util.AttributeSet
|
||||
import android.view.Surface
|
||||
|
@ -37,6 +39,7 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
|||
|
||||
private fun getAppWidgets() {
|
||||
ensureBackgroundThread {
|
||||
// get the casual widgets
|
||||
var appWidgets = ArrayList<AppWidget>()
|
||||
val manager = AppWidgetManager.getInstance(context)
|
||||
val infoList = manager.installedProviders
|
||||
|
@ -45,13 +48,27 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
|||
val appMetadata = getAppMetadataFromPackage(appPackageName) ?: continue
|
||||
val appTitle = appMetadata.appTitle
|
||||
val appIcon = appMetadata.appIcon
|
||||
val widgetTitle = info.loadLabel(activity?.packageManager)
|
||||
val widgetTitle = info.loadLabel(context.packageManager)
|
||||
val width = info.minWidth
|
||||
val height = info.minHeight
|
||||
val widget = AppWidget(appPackageName, appTitle, appIcon, widgetTitle, width, height)
|
||||
appWidgets.add(widget)
|
||||
}
|
||||
|
||||
// list also the widgets that are technically shortcuts
|
||||
val intent = Intent(Intent.ACTION_CREATE_SHORTCUT, null)
|
||||
val list = context.packageManager.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED)
|
||||
for (info in list) {
|
||||
val componentInfo = info.activityInfo.applicationInfo
|
||||
val appTitle = componentInfo.loadLabel(context.packageManager).toString()
|
||||
val appPackageName = componentInfo.packageName
|
||||
val appMetadata = getAppMetadataFromPackage(appPackageName) ?: continue
|
||||
val appIcon = appMetadata.appIcon
|
||||
val widgetTitle = info.loadLabel(context.packageManager).toString()
|
||||
val widget = AppWidget(appPackageName, appTitle, appIcon, widgetTitle, 0, 0)
|
||||
appWidgets.add(widget)
|
||||
}
|
||||
|
||||
appWidgets = appWidgets.sortedWith(compareBy({ it.appTitle }, { it.widgetTitle })).toMutableList() as ArrayList<AppWidget>
|
||||
splitWidgetsByApps(appWidgets)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue