try filling in the whole available space at widgets

This commit is contained in:
tibbi 2018-12-17 10:29:25 +01:00
parent d2b75008d3
commit 84b0c9c88b
2 changed files with 17 additions and 3 deletions

View file

@ -5,6 +5,7 @@ import android.appwidget.AppWidgetManager
import android.appwidget.AppWidgetProvider import android.appwidget.AppWidgetProvider
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Bundle
import android.widget.RemoteViews import android.widget.RemoteViews
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.load.engine.DiskCacheStrategy
@ -31,7 +32,7 @@ class MyWidgetProvider : AppWidgetProvider() {
super.onUpdate(context, appWidgetManager, appWidgetIds) super.onUpdate(context, appWidgetManager, appWidgetIds)
Thread { Thread {
val config = context.config 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 { val views = RemoteViews(context.packageName, R.layout.widget).apply {
setBackgroundColor(R.id.widget_holder, config.widgetBgColor) setBackgroundColor(R.id.widget_holder, config.widgetBgColor)
setVisibleIf(R.id.widget_folder_name, config.showWidgetFolderName) setVisibleIf(R.id.widget_folder_name, config.showWidgetFolderName)
@ -45,7 +46,12 @@ class MyWidgetProvider : AppWidgetProvider() {
.diskCacheStrategy(DiskCacheStrategy.RESOURCE) .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
if (context.config.cropThumbnails) options.centerCrop() else options.fitCenter() 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) val image = Glide.with(context)
.asBitmap() .asBitmap()
.load(path) .load(path)
@ -61,6 +67,11 @@ class MyWidgetProvider : AppWidgetProvider() {
}.start() }.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) { override fun onDeleted(context: Context, appWidgetIds: IntArray) {
super.onDeleted(context, appWidgetIds) super.onDeleted(context, appWidgetIds)
Thread { Thread {

View file

@ -9,9 +9,12 @@
<ImageView <ImageView
android:id="@+id/widget_imageview" android:id="@+id/widget_imageview"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_above="@+id/widget_folder_name" android:layout_above="@+id/widget_folder_name"
android:layout_centerInParent="true"
android:paddingLeft="@dimen/tiny_margin"
android:paddingTop="@dimen/tiny_margin" android:paddingTop="@dimen/tiny_margin"
android:paddingRight="@dimen/tiny_margin"
tools:src="@mipmap/ic_launcher"/> tools:src="@mipmap/ic_launcher"/>
<TextView <TextView