aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/ui/ConversationActivity.java
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-04-25 23:06:20 +0200
committerDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-04-25 23:06:20 +0200
commit645139eb68cb966b90d36790e5b60c0bc6727c78 (patch)
tree9633c20bd4f2e5aa1906373bdea5a07b1aacd6fc /src/eu/siacs/conversations/ui/ConversationActivity.java
parentbf2d0d5596a08872230056d056241ee906962171 (diff)
couple of more optimazations on image loading
Diffstat (limited to 'src/eu/siacs/conversations/ui/ConversationActivity.java')
-rw-r--r--src/eu/siacs/conversations/ui/ConversationActivity.java35
1 files changed, 20 insertions, 15 deletions
diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java
index 32e3588b2..91fde31ec 100644
--- a/src/eu/siacs/conversations/ui/ConversationActivity.java
+++ b/src/eu/siacs/conversations/ui/ConversationActivity.java
@@ -649,42 +649,51 @@ public class ConversationActivity extends XmppActivity {
private Message message = null;
public BitmapWorkerTask(ImageView imageView) {
- // Use a WeakReference to ensure the ImageView can be garbage collected
imageViewReference = new WeakReference<ImageView>(imageView);
}
- // Decode image in background.
@Override
protected Bitmap doInBackground(Message... params) {
message = params[0];
try {
- return xmppConnectionService.getFileBackend().getThumbnail(message, (int) (metrics.density * 288));
+ return xmppConnectionService.getFileBackend().getThumbnail(message, (int) (metrics.density * 288),false);
} catch (FileNotFoundException e) {
Log.d("xmppService","file not found!");
return null;
}
}
- // Once complete, see if ImageView is still around and set bitmap.
@Override
protected void onPostExecute(Bitmap bitmap) {
if (imageViewReference != null && bitmap != null) {
final ImageView imageView = imageViewReference.get();
if (imageView != null) {
imageView.setImageBitmap(bitmap);
+ imageView.setBackgroundColor(0x00000000);
}
}
}
}
public void loadBitmap(Message message, ImageView imageView) {
- if (cancelPotentialWork(message, imageView)) {
- final BitmapWorkerTask task = new BitmapWorkerTask(imageView);
- final AsyncDrawable asyncDrawable =
- new AsyncDrawable(getResources(), null, task);
- imageView.setImageDrawable(asyncDrawable);
- task.execute(message);
- }
+ Bitmap bm;
+ try {
+ bm = xmppConnectionService.getFileBackend().getThumbnail(message, (int) (metrics.density * 288), true);
+ } catch (FileNotFoundException e) {
+ bm = null;
+ }
+ if (bm!=null) {
+ imageView.setImageBitmap(bm);
+ } else {
+ if (cancelPotentialWork(message, imageView)) {
+ imageView.setBackgroundColor(0xff333333);
+ final BitmapWorkerTask task = new BitmapWorkerTask(imageView);
+ final AsyncDrawable asyncDrawable =
+ new AsyncDrawable(getResources(), null, task);
+ imageView.setImageDrawable(asyncDrawable);
+ task.execute(message);
+ }
+ }
}
public static boolean cancelPotentialWork(Message message, ImageView imageView) {
@@ -692,16 +701,12 @@ public class ConversationActivity extends XmppActivity {
if (bitmapWorkerTask != null) {
final Message oldMessage = bitmapWorkerTask.message;
- // If bitmapData is not yet set or it differs from the new data
if (oldMessage == null || message != oldMessage) {
- // Cancel previous task
bitmapWorkerTask.cancel(true);
} else {
- // The same work is already in progress
return false;
}
}
- // No task associated with the ImageView, or an existing task was cancelled
return true;
}