pass the proper context at creating widgets

This commit is contained in:
tibbi
2022-09-29 12:21:41 +02:00
parent 624cc02299
commit 0bb2c1066e
2 changed files with 4 additions and 3 deletions

View File

@ -95,8 +95,8 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
val widgetPreviewImage = info.loadPreviewImage(context, resources.displayMetrics.densityDpi) ?: appIcon val widgetPreviewImage = info.loadPreviewImage(context, resources.displayMetrics.densityDpi) ?: appIcon
val widthCells = Math.min(COLUMN_COUNT, getTileCount(info.minWidth)) val widthCells = Math.min(COLUMN_COUNT, getTileCount(info.minWidth))
val heightCells = Math.min(ROW_COUNT, getTileCount(info.minHeight)) val heightCells = Math.min(ROW_COUNT, getTileCount(info.minHeight))
val widget = val className = info.provider.shortClassName
AppWidget(appPackageName, appTitle, appIcon, widgetTitle, widgetPreviewImage, widthCells, heightCells, false, info.provider.shortClassName) val widget = AppWidget(appPackageName, appTitle, appIcon, widgetTitle, widgetPreviewImage, widthCells, heightCells, false, className)
appWidgets.add(widget) appWidgets.add(widget)
} }

View File

@ -282,7 +282,8 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
null null
) )
} else { } else {
val widgetView = appWidgetHost.createView(context, appWidgetId, appWidgetProviderInfo) as MyAppWidgetHostView // we have to pass the base context here, else there will be errors with the themes
val widgetView = appWidgetHost.createView(activity.baseContext, appWidgetId, appWidgetProviderInfo) as MyAppWidgetHostView
widgetView.setAppWidget(appWidgetId, appWidgetProviderInfo) widgetView.setAppWidget(appWidgetId, appWidgetProviderInfo)
widgetView.x = item.left * rowWidth + sideMargins.left.toFloat() widgetView.x = item.left * rowWidth + sideMargins.left.toFloat()