adding some widget UI related improvements

This commit is contained in:
tibbi 2022-05-14 22:30:06 +02:00
parent 290a84f699
commit 9addf4b235
4 changed files with 27 additions and 21 deletions

View file

@ -6,7 +6,6 @@ import android.content.Intent
import android.graphics.Color import android.graphics.Color
import android.graphics.drawable.ColorDrawable import android.graphics.drawable.ColorDrawable
import android.os.Bundle import android.os.Bundle
import android.widget.RelativeLayout
import android.widget.RemoteViews import android.widget.RemoteViews
import com.bumptech.glide.signature.ObjectKey import com.bumptech.glide.signature.ObjectKey
import com.simplemobiletools.commons.dialogs.ColorPickerDialog import com.simplemobiletools.commons.dialogs.ColorPickerDialog
@ -179,7 +178,5 @@ class WidgetConfigureActivity : SimpleActivity() {
private fun handleFolderNameDisplay() { private fun handleFolderNameDisplay() {
val showFolderName = folder_picker_show_folder_name.isChecked val showFolderName = folder_picker_show_folder_name.isChecked
config_folder_name.beVisibleIf(showFolderName) config_folder_name.beVisibleIf(showFolderName)
(config_image.layoutParams as RelativeLayout.LayoutParams).bottomMargin =
if (showFolderName) 0 else resources.getDimension(R.dimen.normal_margin).toInt()
} }
} }

View file

@ -10,8 +10,8 @@ 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
import com.bumptech.glide.request.RequestOptions import com.bumptech.glide.request.RequestOptions
import com.simplemobiletools.commons.extensions.applyColorFilter
import com.simplemobiletools.commons.extensions.getFileSignature import com.simplemobiletools.commons.extensions.getFileSignature
import com.simplemobiletools.commons.extensions.setBackgroundColor
import com.simplemobiletools.commons.extensions.setText import com.simplemobiletools.commons.extensions.setText
import com.simplemobiletools.commons.extensions.setVisibleIf import com.simplemobiletools.commons.extensions.setVisibleIf
import com.simplemobiletools.commons.helpers.ensureBackgroundThread import com.simplemobiletools.commons.helpers.ensureBackgroundThread
@ -39,7 +39,7 @@ class MyWidgetProvider : AppWidgetProvider() {
val config = context.config val config = context.config
context.widgetsDB.getWidgets().filter { appWidgetIds.contains(it.widgetId) }.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) applyColorFilter(R.id.widget_background, config.widgetBgColor)
setVisibleIf(R.id.widget_folder_name, config.showWidgetFolderName) setVisibleIf(R.id.widget_folder_name, config.showWidgetFolderName)
setTextColor(R.id.widget_folder_name, config.widgetTextColor) setTextColor(R.id.widget_folder_name, config.widgetTextColor)
setText(R.id.widget_folder_name, context.getFolderNameFromPath(it.folderPath)) setText(R.id.widget_folder_name, context.getFolderNameFromPath(it.folderPath))
@ -47,8 +47,8 @@ class MyWidgetProvider : AppWidgetProvider() {
val path = context.directoryDao.getDirectoryThumbnail(it.folderPath) ?: return@forEach val path = context.directoryDao.getDirectoryThumbnail(it.folderPath) ?: return@forEach
val options = RequestOptions() val options = RequestOptions()
.signature(path.getFileSignature()) .signature(path.getFileSignature())
.diskCacheStrategy(DiskCacheStrategy.RESOURCE) .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
if (context.config.cropThumbnails) { if (context.config.cropThumbnails) {
options.centerCrop() options.centerCrop()
@ -64,11 +64,11 @@ class MyWidgetProvider : AppWidgetProvider() {
val widgetSize = (Math.max(width, height) * density).toInt() val widgetSize = (Math.max(width, height) * density).toInt()
try { try {
val image = Glide.with(context) val image = Glide.with(context)
.asBitmap() .asBitmap()
.load(path) .load(path)
.apply(options) .apply(options)
.submit(widgetSize, widgetSize) .submit(widgetSize, widgetSize)
.get() .get()
views.setImageViewBitmap(R.id.widget_imageview, image) views.setImageViewBitmap(R.id.widget_imageview, image)
} catch (e: Exception) { } catch (e: Exception) {
} }

View file

@ -64,9 +64,10 @@
android:layout_width="@dimen/widget_initial_size" android:layout_width="@dimen/widget_initial_size"
android:layout_height="@dimen/widget_initial_size" android:layout_height="@dimen/widget_initial_size"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:layout_marginLeft="@dimen/normal_margin" android:layout_marginStart="@dimen/normal_margin"
android:layout_marginTop="@dimen/normal_margin" android:layout_marginTop="@dimen/small_margin"
android:layout_marginRight="@dimen/normal_margin" /> android:layout_marginEnd="@dimen/normal_margin"
android:layout_marginBottom="@dimen/small_margin" />
<com.simplemobiletools.commons.views.MyTextView <com.simplemobiletools.commons.views.MyTextView
android:id="@+id/config_folder_name" android:id="@+id/config_folder_name"
@ -75,8 +76,9 @@
android:layout_below="@+id/config_image" android:layout_below="@+id/config_image"
android:ellipsize="end" android:ellipsize="end"
android:gravity="center" android:gravity="center"
android:includeFontPadding="false"
android:lines="1" android:lines="1"
android:padding="@dimen/tiny_margin" android:paddingBottom="@dimen/small_margin"
android:textSize="@dimen/bigger_text_size" android:textSize="@dimen/bigger_text_size"
tools:text="@string/internal" /> tools:text="@string/internal" />

View file

@ -1,11 +1,16 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/widget_holder" android:id="@+id/widget_holder"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<ImageView
android:id="@+id/widget_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/widget_round_background" />
<ImageView <ImageView
android:id="@+id/widget_imageview" android:id="@+id/widget_imageview"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -13,9 +18,10 @@
android:layout_above="@+id/widget_folder_name" android:layout_above="@+id/widget_folder_name"
android:layout_centerInParent="true" android:layout_centerInParent="true"
android:paddingLeft="@dimen/tiny_margin" android:paddingLeft="@dimen/tiny_margin"
android:paddingTop="@dimen/tiny_margin" android:paddingTop="@dimen/small_margin"
android:paddingRight="@dimen/tiny_margin" android:paddingRight="@dimen/tiny_margin"
tools:src="@mipmap/ic_launcher"/> android:paddingBottom="@dimen/small_margin"
tools:src="@mipmap/ic_launcher" />
<TextView <TextView
android:id="@+id/widget_folder_name" android:id="@+id/widget_folder_name"
@ -24,9 +30,10 @@
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:ellipsize="end" android:ellipsize="end"
android:gravity="center" android:gravity="center"
android:includeFontPadding="false"
android:lines="1" android:lines="1"
android:padding="@dimen/tiny_margin" android:padding="@dimen/tiny_margin"
android:textSize="@dimen/bigger_text_size" android:textSize="@dimen/bigger_text_size"
tools:text="@string/internal"/> tools:text="@string/internal" />
</RelativeLayout> </RelativeLayout>