From 84b0c9c88b1448e9db814560ff4bf70b91823b3d Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 17 Dec 2018 10:29:25 +0100 Subject: [PATCH] try filling in the whole available space at widgets --- .../gallery/pro/helpers/MyWidgetProvider.kt | 15 +++++++++++++-- app/src/main/res/layout/widget.xml | 5 ++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MyWidgetProvider.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MyWidgetProvider.kt index 8ffba7f09..44886cefd 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MyWidgetProvider.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MyWidgetProvider.kt @@ -5,6 +5,7 @@ import android.appwidget.AppWidgetManager import android.appwidget.AppWidgetProvider import android.content.Context import android.content.Intent +import android.os.Bundle import android.widget.RemoteViews import com.bumptech.glide.Glide import com.bumptech.glide.load.engine.DiskCacheStrategy @@ -31,7 +32,7 @@ class MyWidgetProvider : AppWidgetProvider() { super.onUpdate(context, appWidgetManager, appWidgetIds) Thread { val config = context.config - context.widgetsDB.getWidgets().forEach { + context.widgetsDB.getWidgets().filter { appWidgetIds.contains(it.widgetId) }.forEach { val views = RemoteViews(context.packageName, R.layout.widget).apply { setBackgroundColor(R.id.widget_holder, config.widgetBgColor) setVisibleIf(R.id.widget_folder_name, config.showWidgetFolderName) @@ -45,7 +46,12 @@ class MyWidgetProvider : AppWidgetProvider() { .diskCacheStrategy(DiskCacheStrategy.RESOURCE) if (context.config.cropThumbnails) options.centerCrop() else options.fitCenter() - val widgetSize = context.resources.getDimension(R.dimen.widget_initial_size).toInt() + val density = context.resources.displayMetrics.density + val appWidgetOptions = appWidgetManager.getAppWidgetOptions(appWidgetIds.first()) + val width = appWidgetOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH) + val height = appWidgetOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT) + + val widgetSize = (Math.max(width, height) * density).toInt() val image = Glide.with(context) .asBitmap() .load(path) @@ -61,6 +67,11 @@ class MyWidgetProvider : AppWidgetProvider() { }.start() } + override fun onAppWidgetOptionsChanged(context: Context, appWidgetManager: AppWidgetManager, appWidgetId: Int, newOptions: Bundle) { + super.onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, newOptions) + onUpdate(context, appWidgetManager, intArrayOf(appWidgetId)) + } + override fun onDeleted(context: Context, appWidgetIds: IntArray) { super.onDeleted(context, appWidgetIds) Thread { diff --git a/app/src/main/res/layout/widget.xml b/app/src/main/res/layout/widget.xml index 76adb41b1..87e79a942 100644 --- a/app/src/main/res/layout/widget.xml +++ b/app/src/main/res/layout/widget.xml @@ -9,9 +9,12 @@