calculate widget tiles from real sizes

This commit is contained in:
tibbi 2022-09-16 10:16:08 +02:00
parent d23893755a
commit 08de22c3c9
2 changed files with 7 additions and 5 deletions

View File

@ -50,9 +50,9 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
val appIcon = appMetadata.appIcon val appIcon = appMetadata.appIcon
val widgetTitle = info.loadLabel(packageManager) val widgetTitle = info.loadLabel(packageManager)
val widgetPreviewImage = info.loadPreviewImage(context, resources.displayMetrics.densityDpi) ?: appIcon val widgetPreviewImage = info.loadPreviewImage(context, resources.displayMetrics.densityDpi) ?: appIcon
val width = info.minWidth val widthTileCount = getTileCount(info.minWidth)
val height = info.minHeight val heightTileCount = getTileCount(info.minHeight)
val widget = AppWidget(appPackageName, appTitle, appIcon, widgetTitle, widgetPreviewImage, width, height) val widget = AppWidget(appPackageName, appTitle, appIcon, widgetTitle, widgetPreviewImage, widthTileCount, heightTileCount)
appWidgets.add(widget) appWidgets.add(widget)
} }
@ -76,6 +76,8 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
} }
} }
private fun getTileCount(size: Int) = Math.ceil(((size / resources.displayMetrics.density) - 30) / 70.0).toInt()
private fun splitWidgetsByApps(appWidgets: ArrayList<AppWidget>) { private fun splitWidgetsByApps(appWidgets: ArrayList<AppWidget>) {
var currentAppPackageName = "" var currentAppPackageName = ""
val widgetListItems = ArrayList<WidgetsListItem>() val widgetListItems = ArrayList<WidgetsListItem>()

View File

@ -8,6 +8,6 @@ data class AppWidget(
val appIcon: Drawable, val appIcon: Drawable,
val widgetTitle: String, val widgetTitle: String,
val widgetPreviewImage: Drawable?, val widgetPreviewImage: Drawable?,
var width: Int, var widthTiles: Int,
val height: Int val heightTiles: Int
) : WidgetsListItem() ) : WidgetsListItem()