From 71b8db0d90fe3339ca6e406eb49fbf9316e74b99 Mon Sep 17 00:00:00 2001 From: Federico Iosue Date: Tue, 5 Nov 2019 16:21:45 +0100 Subject: [PATCH] Restored Glide to load attachments images into widget It is actually a process runned into a parallel thread so I don't know why it broke. Actually I've also added some (currentyl) unused code to async load uri into the RemoteViews compoment, just in case... --- gradle.properties | 2 +- .../android/omninotes/utils/BitmapHelper.java | 41 ++++++++++++++++++- .../widget/ListRemoteViewsFactory.java | 7 ++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 5dab97e4cd..69783ccc8c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,7 +15,7 @@ # along with this program. If not, see . # VERSION_NAME=6.0.3 -VERSION_CODE=277 +VERSION_CODE=278 PACKAGE=it.feio.android.omninotes MIN_SDK=16 TARGET_SDK=28 diff --git a/omniNotes/src/main/java/it/feio/android/omninotes/utils/BitmapHelper.java b/omniNotes/src/main/java/it/feio/android/omninotes/utils/BitmapHelper.java index ab914f3a04..83da470c4b 100644 --- a/omniNotes/src/main/java/it/feio/android/omninotes/utils/BitmapHelper.java +++ b/omniNotes/src/main/java/it/feio/android/omninotes/utils/BitmapHelper.java @@ -28,10 +28,17 @@ import android.media.ThumbnailUtils; import android.net.Uri; import android.text.TextUtils; +import android.widget.RemoteViews; +import com.bumptech.glide.Glide; +import com.bumptech.glide.RequestBuilder; +import com.bumptech.glide.request.RequestOptions; +import com.bumptech.glide.request.target.AppWidgetTarget; +import it.feio.android.omninotes.OmniNotes; import it.feio.android.omninotes.R; import it.feio.android.omninotes.helpers.AttachmentsHelper; import it.feio.android.omninotes.models.Attachment; import it.feio.android.simplegallery.util.BitmapUtils; +import java.util.concurrent.ExecutionException; import org.apache.commons.io.FilenameUtils; @@ -47,7 +54,16 @@ public static Bitmap getBitmapFromAttachment (Context mContext, Attachment mAtta mAttachment.getUri().getPath(); if (AttachmentsHelper.typeOf(mAttachment, MIME_TYPE_VIDEO, MIME_TYPE_IMAGE, MIME_TYPE_SKETCH)) { - bmp = BitmapUtils.getThumbnail(mContext, FileProviderHelper.getShareableUri(mAttachment), width, height); + try { + bmp = Glide.with(OmniNotes.getAppContext()).asBitmap() + .apply(new RequestOptions() + .centerCrop() + .error(R.drawable.attachment_broken)) + .load(mAttachment.getUri()) + .submit(width, height).get(); + } catch (NullPointerException | InterruptedException | ExecutionException e) { + bmp = null; + } } else if (MIME_TYPE_AUDIO.equals(mAttachment.getMime_type())) { bmp = ThumbnailUtils.extractThumbnail( @@ -69,6 +85,29 @@ public static Bitmap getBitmapFromAttachment (Context mContext, Attachment mAtta return bmp; } + public static void loadAttachmentIntoWidget (Attachment mAttachment, AppWidgetTarget awt) { + mAttachment.getUri().getPath(); + + RequestBuilder builder = Glide.with(OmniNotes.getAppContext()).asBitmap() + .apply(new RequestOptions() + .centerCrop() + .error(R.drawable.attachment_broken)); + + if (AttachmentsHelper.typeOf(mAttachment, MIME_TYPE_VIDEO, MIME_TYPE_IMAGE, MIME_TYPE_SKETCH)) { + builder = builder.load(mAttachment.getUri()); + } else if (MIME_TYPE_AUDIO.equals(mAttachment.getMime_type())) { + builder = builder.load(R.raw.play); + } else if (MIME_TYPE_FILES.equals(mAttachment.getMime_type())) { + if (MIME_TYPE_CONTACT_EXT.equals(FilenameUtils.getExtension(mAttachment.getName()))) { + builder = builder.load(R.raw.vcard); + } else { + builder = builder.load(R.raw.files); + } + } + + builder.into(awt); + } + public static Uri getThumbnailUri (Context mContext, Attachment mAttachment) { Uri uri = mAttachment.getUri(); diff --git a/omniNotes/src/main/java/it/feio/android/omninotes/widget/ListRemoteViewsFactory.java b/omniNotes/src/main/java/it/feio/android/omninotes/widget/ListRemoteViewsFactory.java index c0bee16d48..8bc24bc85e 100644 --- a/omniNotes/src/main/java/it/feio/android/omninotes/widget/ListRemoteViewsFactory.java +++ b/omniNotes/src/main/java/it/feio/android/omninotes/widget/ListRemoteViewsFactory.java @@ -120,6 +120,13 @@ public RemoteViews getViewAt (int position) { if (!note.isLocked() && showThumbnails && !note.getAttachmentsList().isEmpty()) { Attachment mAttachment = note.getAttachmentsList().get(0); +// AppWidgetTarget awt = new AppWidgetTarget(app, R.id.attachmentThumbnail, row, appWidgetId) { +// @Override +// public void onResourceReady(Bitmap resource, Transition transition) { +// super.onResourceReady(resource, transition); +// } +// }; +// BitmapHelper.loadAttachmentIntoWidget(mAttachment, awt); Bitmap bmp = BitmapHelper.getBitmapFromAttachment(app, mAttachment, WIDTH, HEIGHT); row.setBitmap(R.id.attachmentThumbnail, "setImageBitmap", bmp); row.setInt(R.id.attachmentThumbnail, "setVisibility", View.VISIBLE);