aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/ui
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
parentbf2d0d5596a08872230056d056241ee906962171 (diff)
couple of more optimazations on image loading
Diffstat (limited to 'src/eu/siacs/conversations/ui')
-rw-r--r--src/eu/siacs/conversations/ui/ConversationActivity.java35
-rw-r--r--src/eu/siacs/conversations/ui/ConversationFragment.java6
2 files changed, 23 insertions, 18 deletions
diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java
index 32e3588b..91fde31e 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;
}
diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java
index d42b33c4..5ade8a53 100644
--- a/src/eu/siacs/conversations/ui/ConversationFragment.java
+++ b/src/eu/siacs/conversations/ui/ConversationFragment.java
@@ -301,16 +301,16 @@ public class ConversationFragment extends Fragment {
viewHolder.image.setVisibility(View.VISIBLE);
String[] params = item.getBody().split(",");
if (params.length==3) {
- int target = (int) (metrics.density * 288);
+ double target = metrics.density * 288;
int w = Integer.parseInt(params[1]);
int h = Integer.parseInt(params[2]);
int scalledW;
int scalledH;
if (w <= h) {
scalledW = (int) (w / ((double) h / target));
- scalledH = target;
+ scalledH = (int) target;
} else {
- scalledW = target;
+ scalledW = (int) target;
scalledH = (int) (h / ((double) w / target));
}
viewHolder.image.setLayoutParams(new LinearLayout.LayoutParams(scalledW, scalledH));