Skip to content

Commit b3de3be

Browse files
Fix: Update widget dimensions and bitmap scaling
This commit updates the minimum width and height of the `widget_fab` and `widget_home_apps` app widgets. The `drawableToBitmap` function in `HomeAppsWidgetProvider.kt` has been refactored to: - Take a single `maxSizePx` parameter to clamp both width and height. - Ensure the created bitmap uses `ARGB_8888` configuration. - Coerce bitmap dimensions to be at least 1px to prevent errors. Specific changes: - `app/src/main/res/xml/widget_fab_info.xml`: `android:minWidth` changed from `410dp` to `350dp`. - `app/src/main/res/xml/widget_home_apps_info.xml`: `android:minWidth` changed from `410dp` to `350dp` and `android:minHeight` changed from `410dp` to `350dp`. - `app/src/main/java/com/github/droidworksstudio/mlauncher/ui/widgets/home/HomeAppsWidgetProvider.kt`: `drawableToBitmap` method signature and implementation updated for better bitmap scaling and safety.
1 parent 5465abc commit b3de3be

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

app/src/main/java/com/github/droidworksstudio/mlauncher/ui/widgets/home/HomeAppsWidgetProvider.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class HomeAppsWidgetProvider : AppWidgetProvider() {
8686
val drawableToUse = recoloredDrawable ?: nonNullDrawable
8787

8888
// Convert drawable to bitmap
89-
val bitmap = drawableToBitmap(drawableToUse, iconSize, iconSize)
89+
val bitmap = drawableToBitmap(drawableToUse, iconSize)
9090

9191
// Apply alignment
9292
when (prefs.homeAlignment) {
@@ -138,13 +138,21 @@ class HomeAppsWidgetProvider : AppWidgetProvider() {
138138
}
139139
}
140140

141-
fun drawableToBitmap(drawable: Drawable, width: Int, height: Int): Bitmap {
142-
val bitmap = createBitmap(width, height)
141+
fun drawableToBitmap(drawable: Drawable, maxSizePx: Int): Bitmap {
142+
// Clamp width and height to maxSizePx to avoid RemoteViews exceptions
143+
val intrinsicWidth = drawable.intrinsicWidth.coerceAtMost(maxSizePx)
144+
val intrinsicHeight = drawable.intrinsicHeight.coerceAtMost(maxSizePx)
145+
146+
// Create bitmap with ARGB_8888 (safe for RemoteViews)
147+
val bitmap = createBitmap(intrinsicWidth.coerceAtLeast(1), intrinsicHeight.coerceAtLeast(1))
148+
143149
val canvas = Canvas(bitmap)
144-
drawable.setBounds(0, 0, width, height)
150+
drawable.setBounds(0, 0, canvas.width, canvas.height)
145151
drawable.draw(canvas)
152+
146153
return bitmap
147154
}
148155

156+
149157
}
150158

app/src/main/res/xml/widget_fab_info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
33
android:initialLayout="@layout/widget_fab"
44
android:label="@string/widget_fab_name"
5-
android:minWidth="410dp"
5+
android:minWidth="350dp"
66
android:minHeight="40dp"
77
android:previewImage="@drawable/app_launcher"
88
android:resizeMode="horizontal|vertical"

app/src/main/res/xml/widget_home_apps_info.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
33
android:initialLayout="@layout/widget_home_apps"
44
android:label="@string/widget_home_name"
5-
android:minWidth="410dp"
6-
android:minHeight="410dp"
5+
android:minWidth="350dp"
6+
android:minHeight="350dp"
77
android:previewImage="@drawable/app_launcher"
88
android:resizeMode="horizontal|vertical"
99
android:updatePeriodMillis="60"

0 commit comments

Comments
 (0)