aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/persistance/FileBackend.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/eu/siacs/conversations/persistance/FileBackend.java')
-rw-r--r--src/eu/siacs/conversations/persistance/FileBackend.java56
1 files changed, 54 insertions, 2 deletions
diff --git a/src/eu/siacs/conversations/persistance/FileBackend.java b/src/eu/siacs/conversations/persistance/FileBackend.java
index 3032f375..129176a4 100644
--- a/src/eu/siacs/conversations/persistance/FileBackend.java
+++ b/src/eu/siacs/conversations/persistance/FileBackend.java
@@ -6,6 +6,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.lang.ref.WeakReference;
import android.content.Context;
import android.graphics.Bitmap;
@@ -13,6 +14,9 @@ import android.graphics.BitmapFactory;
import android.net.Uri;
import android.util.Log;
import android.util.LruCache;
+import android.view.View;
+import android.widget.ImageView;
+import android.widget.TextView;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Conversation;
@@ -39,6 +43,10 @@ public class FileBackend {
};
}
+
+ public LruCache<String, Bitmap> getThumbnailCache() {
+ return thumbnailCache;
+ }
public JingleFile getJingleFile(Message message) {
Conversation conversation = message.getConversation();
@@ -49,7 +57,7 @@ public class FileBackend {
return new JingleFile(path + "/" + filename);
}
- private Bitmap resize(Bitmap originalBitmap, int size) {
+ public Bitmap resize(Bitmap originalBitmap, int size) {
int w = originalBitmap.getWidth();
int h = originalBitmap.getHeight();
if (Math.max(w, h) > size) {
@@ -87,7 +95,12 @@ public class FileBackend {
if (!success) {
// Log.d("xmppService", "couldnt compress");
}
+ os.flush();
os.close();
+ long size = file.getSize();
+ int width = scalledBitmap.getWidth();
+ int height = scalledBitmap.getHeight();
+ message.setBody(""+size+","+width+","+height);
return file;
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
@@ -105,7 +118,7 @@ public class FileBackend {
.getAbsolutePath());
}
- public Bitmap getThumbnailFromMessage(Message message, int size)
+ public Bitmap getThumbnail(Message message, int size)
throws FileNotFoundException {
Bitmap thumbnail = thumbnailCache.get(message.getUuid());
if (thumbnail == null) {
@@ -119,6 +132,45 @@ public class FileBackend {
}
return thumbnail;
}
+
+ public void getThumbnailAsync(final Message message, final int size, ImageView imageView, TextView textView) {
+
+ Bitmap thumbnail = thumbnailCache.get(message.getUuid());
+ if (thumbnail == null) {
+ final WeakReference<ImageView> image = new WeakReference<ImageView>(imageView);
+ final WeakReference<TextView> text = new WeakReference<TextView>(textView);
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ if (image.get()!=null) {
+ image.get().setVisibility(View.GONE);
+ }
+ if (text.get()!=null) {
+ text.get().setVisibility(View.VISIBLE);
+ text.get().setText("loading image");
+ }
+ Bitmap fullsize = BitmapFactory.decodeFile(getJingleFile(message)
+ .getAbsolutePath());
+ if (fullsize!=null) {
+ Bitmap thumbnail = resize(fullsize, size);
+ thumbnailCache.put(message.getUuid(), thumbnail);
+ if (image.get()!=null) {
+ image.get().setVisibility(View.VISIBLE);
+ image.get().setImageBitmap(thumbnail);
+ }
+ if (text.get()!=null) {
+ text.get().setVisibility(View.GONE);
+ }
+ }
+ }
+ }).start();
+ } else {
+ textView.setVisibility(View.GONE);
+ imageView.setVisibility(View.VISIBLE);
+ imageView.setImageBitmap(thumbnail);
+ }
+ }
public void removeFiles(Conversation conversation) {
String prefix = context.getFilesDir().getAbsolutePath();