diff options
author | Christian Schneppe <christian@pix-art.de> | 2019-01-27 10:16:18 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2019-01-27 10:19:46 +0100 |
commit | e859e69674cd13e82fb6363e219b80853e87ef15 (patch) | |
tree | 2114545b2f68e4e9dd882f45df60d5255756fd08 /src/main/java/de/pixart/messenger/ui/XmppActivity.java | |
parent | 7b9ced9fb752ee485b657daf6d827f311ed6e8bc (diff) |
make bitmap worker task static
Diffstat (limited to '')
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/XmppActivity.java | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/XmppActivity.java b/src/main/java/de/pixart/messenger/ui/XmppActivity.java index 87e89ecff..5b714984b 100644 --- a/src/main/java/de/pixart/messenger/ui/XmppActivity.java +++ b/src/main/java/de/pixart/messenger/ui/XmppActivity.java @@ -1122,7 +1122,7 @@ public abstract class XmppActivity extends ActionBarActivity { if (cancelPotentialWork(message, imageView)) { imageView.setBackgroundColor(0xff333333); imageView.setImageDrawable(null); - final BitmapWorkerTask task = new BitmapWorkerTask(this, imageView); + final BitmapWorkerTask task = new BitmapWorkerTask(imageView); final AsyncDrawable asyncDrawable = new AsyncDrawable( getResources(), null, task); imageView.setImageDrawable(asyncDrawable); @@ -1177,11 +1177,9 @@ public abstract class XmppActivity extends ActionBarActivity { static class BitmapWorkerTask extends AsyncTask<Message, Void, Bitmap> { private final WeakReference<ImageView> imageViewReference; - private final WeakReference<XmppActivity> activity; private Message message = null; - private BitmapWorkerTask(XmppActivity activity, ImageView imageView) { - this.activity = new WeakReference<>(activity); + private BitmapWorkerTask(ImageView imageView) { this.imageViewReference = new WeakReference<>(imageView); } @@ -1192,7 +1190,7 @@ public abstract class XmppActivity extends ActionBarActivity { } message = params[0]; try { - XmppActivity activity = this.activity.get(); + final XmppActivity activity = find(imageViewReference); if (activity != null && activity.xmppConnectionService != null) { return activity.xmppConnectionService.getFileBackend().getThumbnail(message, (int) (activity.metrics.density * 288), false); } else { @@ -1230,6 +1228,18 @@ public abstract class XmppActivity extends ActionBarActivity { } } + public static XmppActivity find(WeakReference<ImageView> viewWeakReference) { + final View view = viewWeakReference.get(); + if (view == null) { + return null; + } + final Context context = view.getContext(); + if (context instanceof XmppActivity) { + return (XmppActivity) context; + } + return null; + } + protected boolean installFromUnknownSourceAllowed() { boolean installFromUnknownSource = false; final PackageManager packageManager = this.getPackageManager(); |