From 899f3af5e4a7e2b42d06068583ea0d561b3a1f4a Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Sat, 17 Dec 2016 18:59:47 -0800 Subject: [PATCH] Scale down bitmap during scribble rendering on lowmem devices Fixes #5969 // FREEBIE --- .../scribbles/widget/ScribbleView.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/org/thoughtcrime/securesms/scribbles/widget/ScribbleView.java b/src/org/thoughtcrime/securesms/scribbles/widget/ScribbleView.java index 4c205e6b8c..4c8fde1970 100644 --- a/src/org/thoughtcrime/securesms/scribbles/widget/ScribbleView.java +++ b/src/org/thoughtcrime/securesms/scribbles/widget/ScribbleView.java @@ -32,12 +32,14 @@ import android.widget.ImageView; import com.bumptech.glide.Glide; import com.bumptech.glide.load.engine.DiskCacheStrategy; +import com.bumptech.glide.request.target.Target; import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.crypto.MasterSecret; import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri; import org.thoughtcrime.securesms.scribbles.widget.entity.MotionEntity; import org.thoughtcrime.securesms.scribbles.widget.entity.TextEntity; +import org.thoughtcrime.securesms.util.Util; import org.thoughtcrime.securesms.util.concurrent.ListenableFuture; import org.thoughtcrime.securesms.util.concurrent.SettableFuture; @@ -82,12 +84,14 @@ public class ScribbleView extends FrameLayout { Glide.with(getContext()) .load(new DecryptableUri(masterSecret, uri)) .diskCacheStrategy(DiskCacheStrategy.NONE) + .fitCenter() .into(imageView); } public @NonNull ListenableFuture getRenderedImage() { - final SettableFuture future = new SettableFuture<>(); - final Context context = getContext(); + final SettableFuture future = new SettableFuture<>(); + final Context context = getContext(); + final boolean isLowMemory = Util.isLowMemory(context); if (imageUri == null || masterSecret == null) { future.set(null); @@ -98,12 +102,20 @@ public class ScribbleView extends FrameLayout { @Override protected @Nullable Bitmap doInBackground(Void... params) { try { + int width = Target.SIZE_ORIGINAL; + int height = Target.SIZE_ORIGINAL; + + if (isLowMemory) { + width = 768; + height = 768; + } + return Glide.with(context) .load(new DecryptableUri(masterSecret, imageUri)) .asBitmap() .diskCacheStrategy(DiskCacheStrategy.NONE) .skipMemoryCache(true) - .into(-1, -1) + .into(width, height) .get(); } catch (InterruptedException | ExecutionException e) { Log.w(TAG, e);