create a local variable for accessing the packageManager
This commit is contained in:
parent
7172837da1
commit
d39446d1a9
|
@ -42,13 +42,14 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
||||||
// get the casual widgets
|
// get the casual widgets
|
||||||
var appWidgets = ArrayList<AppWidget>()
|
var appWidgets = ArrayList<AppWidget>()
|
||||||
val manager = AppWidgetManager.getInstance(context)
|
val manager = AppWidgetManager.getInstance(context)
|
||||||
|
val packageManager = context.packageManager
|
||||||
val infoList = manager.installedProviders
|
val infoList = manager.installedProviders
|
||||||
for (info in infoList) {
|
for (info in infoList) {
|
||||||
val appPackageName = info.provider.packageName
|
val appPackageName = info.provider.packageName
|
||||||
val appMetadata = getAppMetadataFromPackage(appPackageName) ?: continue
|
val appMetadata = getAppMetadataFromPackage(appPackageName) ?: continue
|
||||||
val appTitle = appMetadata.appTitle
|
val appTitle = appMetadata.appTitle
|
||||||
val appIcon = appMetadata.appIcon
|
val appIcon = appMetadata.appIcon
|
||||||
val widgetTitle = info.loadLabel(context.packageManager)
|
val widgetTitle = info.loadLabel(packageManager)
|
||||||
val widgetPreviewImage = info.loadPreviewImage(context, DisplayMetrics.DENSITY_MEDIUM) ?: appIcon
|
val widgetPreviewImage = info.loadPreviewImage(context, DisplayMetrics.DENSITY_MEDIUM) ?: appIcon
|
||||||
val width = info.minWidth
|
val width = info.minWidth
|
||||||
val height = info.minHeight
|
val height = info.minHeight
|
||||||
|
@ -58,15 +59,15 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
||||||
|
|
||||||
// show also the widgets that are technically shortcuts
|
// show also the widgets that are technically shortcuts
|
||||||
val intent = Intent(Intent.ACTION_CREATE_SHORTCUT, null)
|
val intent = Intent(Intent.ACTION_CREATE_SHORTCUT, null)
|
||||||
val list = context.packageManager.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED)
|
val list = packageManager.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED)
|
||||||
for (info in list) {
|
for (info in list) {
|
||||||
val componentInfo = info.activityInfo.applicationInfo
|
val componentInfo = info.activityInfo.applicationInfo
|
||||||
val appTitle = componentInfo.loadLabel(context.packageManager).toString()
|
val appTitle = componentInfo.loadLabel(packageManager).toString()
|
||||||
val appPackageName = componentInfo.packageName
|
val appPackageName = componentInfo.packageName
|
||||||
val appMetadata = getAppMetadataFromPackage(appPackageName) ?: continue
|
val appMetadata = getAppMetadataFromPackage(appPackageName) ?: continue
|
||||||
val appIcon = appMetadata.appIcon
|
val appIcon = appMetadata.appIcon
|
||||||
val widgetTitle = info.loadLabel(context.packageManager).toString()
|
val widgetTitle = info.loadLabel(packageManager).toString()
|
||||||
val widgetPreviewImage = activity!!.packageManager.getDrawable(activity!!.packageName, info.iconResource, componentInfo)
|
val widgetPreviewImage = packageManager.getDrawable(componentInfo.packageName, info.iconResource, componentInfo)
|
||||||
val widget = AppWidget(appPackageName, appTitle, appIcon, widgetTitle, widgetPreviewImage, 0, 0)
|
val widget = AppWidget(appPackageName, appTitle, appIcon, widgetTitle, widgetPreviewImage, 0, 0)
|
||||||
appWidgets.add(widget)
|
appWidgets.add(widget)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue