import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory;
import android.graphics.Point;
+import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.media.ThumbnailUtils;
import android.net.Uri;
public static Bitmap mDefaultImg =
BitmapFactory.decodeResource(
- MainApp.getAppContext().getResources(),
- DisplayUtils.getFileTypeIconId("image/png", "default.png")
+ MainApp.getAppContext().getResources(),
+ R.drawable.file_image
);
}
protected void onPostExecute(Bitmap bitmap){
- if (isCancelled()) {
- bitmap = null;
- }
-
if (bitmap != null) {
final ImageView imageView = mImageViewReference.get();
final ThumbnailGenerationTask bitmapWorkerTask = getBitmapWorkerTask(imageView);
}
}
imageView.setImageBitmap(bitmap);
- imageView.setVisibility(View.VISIBLE);
+ // imageView.setVisibility(View.VISIBLE);
}
}
}
file.getStoragePath(), pxW, pxH);
if (bitmap != null) {
+ // Handle PNG
+ if (file.getMimetype().equalsIgnoreCase("image/png")) {
+ bitmap = handlePNG(bitmap, pxW);
+ }
+
thumbnail = addThumbnailToCache(imageKey, bitmap, file.getStoragePath(), pxW, pxH);
file.setNeedsUpdateThumbnail(false);
GetMethod get = new GetMethod(uri);
int status = mClient.executeMethod(get);
if (status == HttpStatus.SC_OK) {
-// byte[] bytes = get.getResponseBody();
-// Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0,
-// bytes.length);
InputStream inputStream = get.getResponseBodyAsStream();
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
thumbnail = ThumbnailUtils.extractThumbnail(bitmap, pxW, pxH);
byte[] bytes = get.getResponseBody();
- String type = "";
- if (mIsThumbnail){
- type = "Thumbnail";
- } else {
- type = "Resized image";
- }
- Log_OC.d("Thumbnail",
- type + " size of " + file.getRemotePath()
- + ": " + bytes.length);
-
- // bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
-
if (mIsThumbnail) {
thumbnail = ThumbnailUtils.extractThumbnail(bitmap, pxW, pxH);
} else {
thumbnail = bitmap;
}
+ // Handle PNG
+ if (file.getMimetype().equalsIgnoreCase("image/png")) {
+ thumbnail = handlePNG(thumbnail, pxW);
+ }
+
// Add thumbnail to cache
if (thumbnail != null) {
addBitmapToCache(imageKey, thumbnail);
}
+ private Bitmap handlePNG(Bitmap bitmap, int px){
+ Bitmap resultBitmap = Bitmap.createBitmap(px,
+ px,
+ Bitmap.Config.ARGB_8888);
+ Canvas c = new Canvas(resultBitmap);
+
+ c.drawColor(MainApp.getAppContext().getResources().
+ getColor(R.color.background_color));
+ c.drawBitmap(bitmap, 0, 0, null);
+
+ return resultBitmap;
+ }
+
private Bitmap doFileInBackground(Boolean mIsThumbnail) {
- Bitmap thumbnail = null;
File file = (File)mFile;
- final String imageKey = String.valueOf(file.hashCode());
+ // distinguish between thumbnail and resized image
+ String temp = String.valueOf(file.hashCode());
+ if (mIsThumbnail){
+ temp = "t" + temp;
+ } else {
+ temp = "r" + temp;
+ }
+
+ final String imageKey = temp;
// Check disk cache in background thread
- thumbnail = getBitmapFromDiskCache(imageKey);
+ Bitmap thumbnail = getBitmapFromDiskCache(imageKey);
// Not found in disk cache
if (thumbnail == null) {
if (bitmapData == null || bitmapData != file) {
// Cancel previous task
bitmapWorkerTask.cancel(true);
+ Log_OC.v(TAG, "Cancelled generation of thumbnail for a reused imageView");
} else {
// The same work is already in progress
return false;