aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2017-01-05 22:57:18 +0100
committerChristian Schneppe <christian@pix-art.de>2017-01-05 22:57:18 +0100
commit94fb468742e88abae4690b81fd02dab80f77fc97 (patch)
treed8ea243430ddc97c401c724502a97049e085c30d /src/main/java/de
parent0eaa0bf5c593f82fcdbae74f341d78c9f1721c93 (diff)
add overlay to indicate that image is gif
Diffstat (limited to 'src/main/java/de')
-rw-r--r--src/main/java/de/pixart/messenger/persistance/FileBackend.java31
1 files changed, 25 insertions, 6 deletions
diff --git a/src/main/java/de/pixart/messenger/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java
index 88e53efd4..c85c2c34a 100644
--- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java
+++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java
@@ -9,6 +9,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
+import android.graphics.Paint;
import android.graphics.RectF;
import android.media.MediaMetadataRetriever;
import android.net.Uri;
@@ -426,7 +427,8 @@ public class FileBackend {
return thumbnail;
}
DownloadableFile file = getFile(message);
- if (file.getMimeType().startsWith("video/")) {
+ final String mime = file.getMimeType();
+ if (mime.startsWith("video/")) {
thumbnail = getVideoPreview(file, size);
} else {
Bitmap fullsize = getFullsizeImagePreview(file, size);
@@ -435,6 +437,12 @@ public class FileBackend {
}
thumbnail = resize(fullsize, size);
thumbnail = rotate(thumbnail, getRotation(file));
+ if (mime.equals("image/gif")) {
+ Bitmap withGifOverlay = thumbnail.copy(Bitmap.Config.ARGB_8888, true);
+ drawOverlay(withGifOverlay, R.drawable.play_gif, 1.0f);
+ thumbnail.recycle();
+ thumbnail = withGifOverlay;
+ }
}
this.mXmppConnectionService.getBitmapCache().put(uuid, thumbnail);
}
@@ -453,6 +461,21 @@ public class FileBackend {
}
}
+ private void drawOverlay(Bitmap bitmap, int resource, float factor) {
+ Bitmap overlay = BitmapFactory.decodeResource(mXmppConnectionService.getResources(), resource);
+ Canvas canvas = new Canvas(bitmap);
+ Paint paint = new Paint();
+ paint.setAntiAlias(true);
+ paint.setFilterBitmap(true);
+ paint.setDither(true);
+ float targetSize = Math.min(canvas.getWidth(), canvas.getHeight()) * factor;
+ Log.d(Config.LOGTAG, "target size overlay: " + targetSize + " overlay bitmap size was " + overlay.getHeight());
+ float left = (canvas.getWidth() - targetSize) / 2.0f;
+ float top = (canvas.getHeight() - targetSize) / 2.0f;
+ RectF dst = new RectF(left, top, left + targetSize - 1, top + targetSize - 1);
+ canvas.drawBitmap(overlay, null, dst, paint);
+ }
+
private Bitmap getVideoPreview(File file, int size) {
MediaMetadataRetriever metadataRetriever = new MediaMetadataRetriever();
Bitmap frame;
@@ -465,11 +488,7 @@ public class FileBackend {
frame = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
frame.eraseColor(0xff000000);
}
- Canvas canvas = new Canvas(frame);
- Bitmap play = BitmapFactory.decodeResource(mXmppConnectionService.getResources(), R.drawable.play_video);
- float x = (frame.getWidth() - play.getWidth()) / 2.0f;
- float y = (frame.getHeight() - play.getHeight()) / 2.0f;
- canvas.drawBitmap(play, x, y, null);
+ drawOverlay(frame,R.drawable.play_video,0.75f);
return frame;
}