mirror of
https://github.com/SimpleMobileTools/Simple-Gallery.git
synced 2025-02-19 21:40:37 +01:00
show the image at the widget
This commit is contained in:
parent
a7f2cc61c8
commit
3e06d78791
@ -145,6 +145,8 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
|||||||
config.filterMedia += TYPE_SVGS
|
config.filterMedia += TYPE_SVGS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateWidgets()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.simplemobiletools.gallery.pro.extensions
|
package com.simplemobiletools.gallery.pro.extensions
|
||||||
|
|
||||||
|
import android.appwidget.AppWidgetManager
|
||||||
|
import android.content.ComponentName
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
@ -487,3 +489,14 @@ fun Context.getUpdatedDeletedMedia(mediumDao: MediumDao): ArrayList<Medium> {
|
|||||||
fun Context.deleteDBPath(mediumDao: MediumDao, path: String) {
|
fun Context.deleteDBPath(mediumDao: MediumDao, path: String) {
|
||||||
mediumDao.deleteMediumPath(path.replaceFirst(recycleBinPath, RECYCLE_BIN))
|
mediumDao.deleteMediumPath(path.replaceFirst(recycleBinPath, RECYCLE_BIN))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Context.updateWidgets() {
|
||||||
|
val widgetIDs = AppWidgetManager.getInstance(applicationContext).getAppWidgetIds(ComponentName(applicationContext, MyWidgetProvider::class.java))
|
||||||
|
if (widgetIDs.isNotEmpty()) {
|
||||||
|
Intent(applicationContext, MyWidgetProvider::class.java).apply {
|
||||||
|
action = AppWidgetManager.ACTION_APPWIDGET_UPDATE
|
||||||
|
putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, widgetIDs)
|
||||||
|
sendBroadcast(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -3,13 +3,23 @@ package com.simplemobiletools.gallery.pro.helpers
|
|||||||
import android.app.PendingIntent
|
import android.app.PendingIntent
|
||||||
import android.appwidget.AppWidgetManager
|
import android.appwidget.AppWidgetManager
|
||||||
import android.appwidget.AppWidgetProvider
|
import android.appwidget.AppWidgetProvider
|
||||||
|
import android.content.ComponentName
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
|
import android.util.Log
|
||||||
import android.widget.RemoteViews
|
import android.widget.RemoteViews
|
||||||
|
import com.bumptech.glide.Glide
|
||||||
|
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||||
|
import com.bumptech.glide.request.RequestOptions
|
||||||
|
import com.bumptech.glide.request.target.AppWidgetTarget
|
||||||
import com.simplemobiletools.commons.extensions.setBackgroundColor
|
import com.simplemobiletools.commons.extensions.setBackgroundColor
|
||||||
import com.simplemobiletools.gallery.pro.R
|
import com.simplemobiletools.gallery.pro.R
|
||||||
import com.simplemobiletools.gallery.pro.activities.MediaActivity
|
import com.simplemobiletools.gallery.pro.activities.MediaActivity
|
||||||
import com.simplemobiletools.gallery.pro.extensions.config
|
import com.simplemobiletools.gallery.pro.extensions.config
|
||||||
|
import com.simplemobiletools.gallery.pro.extensions.directoryDB
|
||||||
|
import com.simplemobiletools.gallery.pro.extensions.getFileSignature
|
||||||
import com.simplemobiletools.gallery.pro.extensions.widgetsDB
|
import com.simplemobiletools.gallery.pro.extensions.widgetsDB
|
||||||
import com.simplemobiletools.gallery.pro.models.Widget
|
import com.simplemobiletools.gallery.pro.models.Widget
|
||||||
|
|
||||||
@ -29,8 +39,27 @@ class MyWidgetProvider : AppWidgetProvider() {
|
|||||||
context.widgetsDB.getWidgets().forEach {
|
context.widgetsDB.getWidgets().forEach {
|
||||||
val views = RemoteViews(context.packageName, R.layout.widget)
|
val views = RemoteViews(context.packageName, R.layout.widget)
|
||||||
views.setBackgroundColor(R.id.widget_holder, context.config.widgetBgColor)
|
views.setBackgroundColor(R.id.widget_holder, context.config.widgetBgColor)
|
||||||
setupAppOpenIntent(context, views, R.id.widget_holder, it)
|
|
||||||
appWidgetManager.updateAppWidget(it.widgetId, views)
|
val path = context.directoryDB.getDirectoryThumbnail(it.folderPath)
|
||||||
|
val options = RequestOptions()
|
||||||
|
.signature(path!!.getFileSignature())
|
||||||
|
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
|
||||||
|
if (context.config.cropThumbnails) options.centerCrop() else options.fitCenter()
|
||||||
|
|
||||||
|
Handler(Looper.getMainLooper()).post {
|
||||||
|
val widgetSize = context.resources.getDimension(R.dimen.widget_initial_width).toInt()
|
||||||
|
val componentName = ComponentName(context, MyWidgetProvider::class.java)
|
||||||
|
val appWidgetTarget = object : AppWidgetTarget(context, widgetSize, widgetSize, R.id.widget_imageview, views, componentName) {}
|
||||||
|
|
||||||
|
Glide.with(context)
|
||||||
|
.asBitmap()
|
||||||
|
.load(path)
|
||||||
|
.apply(options)
|
||||||
|
.into(appWidgetTarget)
|
||||||
|
|
||||||
|
setupAppOpenIntent(context, views, R.id.widget_holder, it)
|
||||||
|
appWidgetManager.updateAppWidget(it.widgetId, views)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<?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"
|
||||||
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">
|
||||||
@ -9,6 +10,6 @@
|
|||||||
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="wrap_content"
|
||||||
android:src="@mipmap/ic_launcher"/>
|
tools:src="@mipmap/ic_launcher"/>
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
@ -33,9 +33,10 @@
|
|||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/config_image_holder"
|
android:id="@+id/config_image_holder"
|
||||||
android:layout_width="110dp"
|
android:layout_width="134dp"
|
||||||
android:layout_height="110dp"
|
android:layout_height="134dp"
|
||||||
android:layout_below="@+id/folder_picker_holder">
|
android:layout_below="@+id/folder_picker_holder"
|
||||||
|
android:padding="@dimen/normal_margin">
|
||||||
|
|
||||||
<com.simplemobiletools.gallery.pro.views.MySquareImageView
|
<com.simplemobiletools.gallery.pro.views.MySquareImageView
|
||||||
android:id="@+id/config_image"
|
android:id="@+id/config_image"
|
||||||
|
@ -15,4 +15,5 @@
|
|||||||
<dimen name="bottom_filters_height">90dp</dimen>
|
<dimen name="bottom_filters_height">90dp</dimen>
|
||||||
<dimen name="bottom_editor_actions_shadow_height">180dp</dimen>
|
<dimen name="bottom_editor_actions_shadow_height">180dp</dimen>
|
||||||
<dimen name="default_status_action_height">86dp</dimen>
|
<dimen name="default_status_action_height">86dp</dimen>
|
||||||
|
<dimen name="widget_initial_width">110dp</dimen>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:configure="com.simplemobiletools.gallery.pro.activities.WidgetConfigureActivity"
|
android:configure="com.simplemobiletools.gallery.pro.activities.WidgetConfigureActivity"
|
||||||
android:initialLayout="@layout/widget"
|
android:initialLayout="@layout/widget"
|
||||||
android:minWidth="40dp"
|
android:minWidth="@dimen/widget_initial_width"
|
||||||
android:minHeight="40dp"
|
android:minHeight="40dp"
|
||||||
android:minResizeWidth="40dp"
|
android:minResizeWidth="40dp"
|
||||||
android:minResizeHeight="40dp"
|
android:minResizeHeight="40dp"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user