diff options
author | Daniel Gultsch <daniel.gultsch@rwth-aachen.de> | 2014-04-19 01:14:30 +0200 |
---|---|---|
committer | Daniel Gultsch <daniel.gultsch@rwth-aachen.de> | 2014-04-19 01:14:30 +0200 |
commit | 5c0873c7cab8bdb95754f4a67839aa6ed5a3d2e8 (patch) | |
tree | 8783b29c032b4c0410943d411be404f036d9988e /src/eu/siacs/conversations/persistance/FileBackend.java | |
parent | 7ccbf0008a600cd00e3dea1b95890d7454509af3 (diff) |
cleaned up debug log a little bit
Diffstat (limited to '')
-rw-r--r-- | src/eu/siacs/conversations/persistance/FileBackend.java | 47 |
1 files changed, 36 insertions, 11 deletions
diff --git a/src/eu/siacs/conversations/persistance/FileBackend.java b/src/eu/siacs/conversations/persistance/FileBackend.java index 7433946b..307a9e2c 100644 --- a/src/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/eu/siacs/conversations/persistance/FileBackend.java @@ -1,5 +1,6 @@ package eu.siacs.conversations.persistance; +import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; @@ -10,6 +11,7 @@ import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; +import android.util.Log; import android.util.LruCache; import eu.siacs.conversations.entities.Conversation; @@ -25,7 +27,7 @@ public class FileBackend { public FileBackend(Context context) { this.context = context; - + int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); int cacheSize = maxMemory / 8; thumbnailCache = new LruCache<String, Bitmap>(cacheSize) { @@ -45,7 +47,7 @@ public class FileBackend { String filename = message.getUuid() + ".webp"; return new JingleFile(path + "/" + filename); } - + private Bitmap resize(Bitmap originalBitmap, int size) { int w = originalBitmap.getWidth(); int h = originalBitmap.getHeight(); @@ -59,8 +61,8 @@ public class FileBackend { scalledW = size; scalledH = (int) (h / ((double) w / size)); } - Bitmap scalledBitmap = Bitmap.createScaledBitmap( - originalBitmap, scalledW, scalledH, true); + Bitmap scalledBitmap = Bitmap.createScaledBitmap(originalBitmap, + scalledW, scalledH, true); return scalledBitmap; } else { return originalBitmap; @@ -78,9 +80,10 @@ public class FileBackend { Bitmap originalBitmap = BitmapFactory.decodeStream(is); is.close(); Bitmap scalledBitmap = resize(originalBitmap, IMAGE_SIZE); - boolean success = scalledBitmap.compress(Bitmap.CompressFormat.WEBP,75,os); + boolean success = scalledBitmap.compress( + Bitmap.CompressFormat.WEBP, 75, os); if (!success) { - //Log.d("xmppService", "couldnt compress"); + // Log.d("xmppService", "couldnt compress"); } os.close(); return file; @@ -96,16 +99,17 @@ public class FileBackend { } public Bitmap getImageFromMessage(Message message) { - return BitmapFactory - .decodeFile(getJingleFile(message).getAbsolutePath()); + return BitmapFactory.decodeFile(getJingleFile(message) + .getAbsolutePath()); } - public Bitmap getThumbnailFromMessage(Message message, int size) throws FileNotFoundException { + public Bitmap getThumbnailFromMessage(Message message, int size) + throws FileNotFoundException { Bitmap thumbnail = thumbnailCache.get(message.getUuid()); - if (thumbnail==null) { + if (thumbnail == null) { Bitmap fullsize = BitmapFactory.decodeFile(getJingleFile(message) .getAbsolutePath()); - if (fullsize==null) { + if (fullsize == null) { throw new FileNotFoundException(); } thumbnail = resize(fullsize, size); @@ -113,4 +117,25 @@ public class FileBackend { } return thumbnail; } + + public void removeFiles(Conversation conversation) { + String prefix = context.getFilesDir().getAbsolutePath(); + String path = prefix + "/" + conversation.getAccount().getJid() + "/" + + conversation.getContactJid(); + File file = new File(path); + try { + this.deleteFile(file); + } catch (IOException e) { + Log.d("xmppService", + "error deleting file: " + file.getAbsolutePath()); + } + } + + private void deleteFile(File f) throws IOException { + if (f.isDirectory()) { + for (File c : f.listFiles()) + deleteFile(c); + } + f.delete(); + } } |