diff --git a/res/drawable/backrepeat.xml b/res/drawable/backrepeat.xml
new file mode 100644
index 0000000000..37105c7b6b
--- /dev/null
+++ b/res/drawable/backrepeat.xml
@@ -0,0 +1,4 @@
+
+
\ No newline at end of file
diff --git a/res/drawable/checker_16_16.png b/res/drawable/checker_16_16.png
new file mode 100644
index 0000000000..3e9e3d0969
Binary files /dev/null and b/res/drawable/checker_16_16.png differ
diff --git a/res/layout/preview_image_fragment.xml b/res/layout/preview_image_fragment.xml
index d584b4457f..11f88ba9a4 100644
--- a/res/layout/preview_image_fragment.xml
+++ b/res/layout/preview_image_fragment.xml
@@ -42,7 +42,7 @@
android:indeterminateOnly="true"
android:layout_centerInParent="true"
/>
-
+
-
+
\ No newline at end of file
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;
diff --git a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java
index 33fa57fd91..0c72052a92 100644
--- a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java
+++ b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java
@@ -30,6 +30,7 @@ import android.accounts.Account;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
+import android.graphics.drawable.Drawable;
import android.os.Build;
import android.preference.PreferenceManager;
import android.text.format.DateUtils;
@@ -320,6 +321,13 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
task.execute(file);
}
}
+
+ if (file.getMimetype().equalsIgnoreCase("image/png")){
+ Drawable backrepeat = mContext.getResources().
+ getDrawable(R.drawable.backrepeat);
+ fileIcon.setBackground(backrepeat);
+ }
+
} else {
fileIcon.setImageResource(DisplayUtils.getFileTypeIconId(file.getMimetype(),
file.getFileName()));
diff --git a/src/com/owncloud/android/ui/preview/PreviewImageFragment.java b/src/com/owncloud/android/ui/preview/PreviewImageFragment.java
index 7ca1cfbb56..6ce592a7de 100644
--- a/src/com/owncloud/android/ui/preview/PreviewImageFragment.java
+++ b/src/com/owncloud/android/ui/preview/PreviewImageFragment.java
@@ -26,6 +26,7 @@ import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Point;
+import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.FragmentStatePagerAdapter;
@@ -200,7 +201,8 @@ public class PreviewImageFragment extends FileFragment {
if (getFile() != null) {
mLoadBitmapTask = new LoadBitmapTask(mImageView, mMessageView, mProgressWheel);
//mLoadBitmapTask.execute(new String[]{getFile().getStoragePath()});
- mLoadBitmapTask.execute(getFile().getStoragePath());
+// mLoadBitmapTask.execute(getFile().getStoragePath());
+ mLoadBitmapTask.execute(getFile());
}
}
@@ -358,7 +360,7 @@ public class PreviewImageFragment extends FileFragment {
}
- private class LoadBitmapTask extends AsyncTask {
+ private class LoadBitmapTask extends AsyncTask {
/**
* Weak reference to the target {@link ImageView} where the bitmap will be loaded into.
@@ -404,12 +406,12 @@ public class PreviewImageFragment extends FileFragment {
mProgressWheelRef = new WeakReference(progressWheel);
}
-
@Override
- protected Bitmap doInBackground(String... params) {
+ protected LoadImage doInBackground(OCFile... params) {
Bitmap result = null;
if (params.length != 1) return null;
- String storagePath = params[0];
+ OCFile ocFile = params[0];
+ String storagePath = ocFile.getStoragePath();
try {
int maxDownScale = 3; // could be a parameter passed to doInBackground(...)
@@ -422,7 +424,7 @@ public class PreviewImageFragment extends FileFragment {
result = BitmapUtils.decodeSampledBitmapFromFile(storagePath, minWidth,
minHeight);
- if (isCancelled()) return result;
+ if (isCancelled()) return new LoadImage(result, ocFile);
if (result == null) {
mErrorMessageId = R.string.preview_image_error_unknown_format;
@@ -462,40 +464,46 @@ public class PreviewImageFragment extends FileFragment {
Log_OC.e(TAG, "Unexpected error loading " + getFile().getStoragePath(), t);
}
-
- return result;
+ return new LoadImage(result, ocFile);
}
@Override
- protected void onCancelled(Bitmap result) {
- if (result != null) {
- result.recycle();
+ protected void onCancelled(LoadImage result) {
+ if (result.bitmap != null) {
+ result.bitmap.recycle();
}
}
@Override
- protected void onPostExecute(Bitmap result) {
+ protected void onPostExecute(LoadImage result) {
hideProgressWheel();
- if (result != null) {
+ if (result.bitmap != null) {
showLoadedImage(result);
} else {
showErrorMessage();
}
- if (result != null && mBitmap != result) {
+ if (result.bitmap != null && mBitmap != result.bitmap) {
// unused bitmap, release it! (just in case)
- result.recycle();
+ result.bitmap.recycle();
}
}
@SuppressLint("InlinedApi")
- private void showLoadedImage(Bitmap result) {
+ private void showLoadedImage(LoadImage result) {
final ImageViewCustom imageView = mImageViewRef.get();
+ Bitmap bitmap = result.bitmap;
if (imageView != null) {
- Log_OC.d(TAG, "Showing image with resolution " + result.getWidth() + "x" +
- result.getHeight());
- imageView.setImageBitmap(result);
+ Log_OC.d(TAG, "Showing image with resolution " + bitmap.getWidth() + "x" +
+ bitmap.getHeight());
+
+ if (result.ocFile.getMimetype().equalsIgnoreCase("image/png")){
+ Drawable backrepeat = getResources().getDrawable(R.drawable.backrepeat);
+ imageView.setBackground(backrepeat);
+ }
+
+ imageView.setImageBitmap(bitmap);
imageView.setVisibility(View.VISIBLE);
- mBitmap = result; // needs to be kept for recycling when not useful
+ mBitmap = bitmap; // needs to be kept for recycling when not useful
}
final TextView messageView = mMessageViewRef.get();
@@ -551,4 +559,15 @@ public class PreviewImageFragment extends FileFragment {
return mImageView;
}
+ private class LoadImage {
+ private Bitmap bitmap;
+ private OCFile ocFile;
+
+ public LoadImage(Bitmap bitmap, OCFile ocFile){
+ this.bitmap = bitmap;
+ this.ocFile = ocFile;
+ }
+
+ }
+
}