From 84f9169e7a78fbea2e2e801e05e06f1c02a01817 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Sat, 22 Aug 2015 07:49:35 +0200 Subject: [PATCH] Thumbnails add checkerboard to png --- .../datamodel/ThumbnailsCacheManager.java | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java b/src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java index 0e59a8341d..362106e6e3 100644 --- a/src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java +++ b/src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java @@ -33,6 +33,8 @@ import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Bitmap.CompressFormat; import android.graphics.BitmapFactory; +import android.graphics.Canvas; +import android.graphics.Shader; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.media.ThumbnailUtils; @@ -259,10 +261,16 @@ public class ThumbnailsCacheManager { int px = getThumbnailDimension(); if (file.isDown()) { - Bitmap bitmap = BitmapUtils.decodeSampledBitmapFromFile( + Bitmap temp = BitmapUtils.decodeSampledBitmapFromFile( file.getStoragePath(), px, px); + Bitmap bitmap = ThumbnailUtils.extractThumbnail(temp, px, px); if (bitmap != null) { + // Handle PNG + if (file.getMimetype().equalsIgnoreCase("image/png")) { + bitmap = handlePNG(bitmap, px); + } + thumbnail = addThumbnailToCache(imageKey, bitmap, file.getStoragePath(), px); file.setNeedsUpdateThumbnail(false); @@ -289,6 +297,11 @@ public class ThumbnailsCacheManager { Bitmap bitmap = BitmapFactory.decodeStream(inputStream); thumbnail = ThumbnailUtils.extractThumbnail(bitmap, px, px); + // Handle PNG + if (file.getMimetype().equalsIgnoreCase("image/png")) { + thumbnail = handlePNG(thumbnail, px); + } + // Add thumbnail to cache if (thumbnail != null) { addBitmapToCache(imageKey, thumbnail); @@ -308,6 +321,26 @@ public class ThumbnailsCacheManager { } + private Bitmap handlePNG(Bitmap bitmap, int px){ + Bitmap resultBitmap = Bitmap.createBitmap(px, + px, + Bitmap.Config.ARGB_8888); + Canvas c = new Canvas(resultBitmap); + Bitmap checker = BitmapFactory.decodeResource(MainApp.getAppContext().getResources(), + R.drawable.checker_16_16); + + BitmapDrawable background; + background = new BitmapDrawable(MainApp.getAppContext().getResources(), checker); + + background.setBounds(0, 0, px, px); + background.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT); + background.draw(c); + + c.drawBitmap(bitmap, 0, 0, null); + + return resultBitmap; + } + private Bitmap doFileInBackground() { File file = (File)mFile;