- final String imageKey = String.valueOf(mFile.getRemoteId());
-
- // Check disk cache in background thread
- thumbnail = getBitmapFromDiskCache(imageKey);
-
- // Not found in disk cache
- if (thumbnail == null || mFile.needsUpdateThumbnail()) {
- // Converts dp to pixel
- Resources r = MainApp.getAppContext().getResources();
-
- int px = (int) Math.round(r.getDimension(R.dimen.file_icon_size));
-
- if (mFile.isDown()){
- Bitmap bitmap = BitmapUtils.decodeSampledBitmapFromFile(
- mFile.getStoragePath(), px, px);
-
- if (bitmap != null) {
- thumbnail = ThumbnailUtils.extractThumbnail(bitmap, px, px);
-
- // Rotate image, obeying exif tag
- thumbnail = BitmapUtils.rotateImage(thumbnail, mFile.getStoragePath());
-
- // Add thumbnail to cache
- addBitmapToCache(imageKey, thumbnail);
+
+ if (mFile instanceof OCFile) {
+ thumbnail = doOCFileInBackground();
+ } else if (mFile instanceof File) {
+ thumbnail = doFileInBackground();
+ //} else { do nothing
+ }
+
+ }catch(Throwable t){
+ // the app should never break due to a problem with thumbnails
+ Log_OC.e(TAG, "Generation of thumbnail for " + mFile + " failed", t);
+ if (t instanceof OutOfMemoryError) {
+ System.gc();
+ }
+ }
+
+ return thumbnail;
+ }
+
+ protected void onPostExecute(Bitmap bitmap){
+ if (bitmap != null) {
+ final ImageView imageView = mImageViewReference.get();
+ final ThumbnailGenerationTask bitmapWorkerTask = getBitmapWorkerTask(imageView);
+ if (this == bitmapWorkerTask) {
+ String tagId = "";
+ if (mFile instanceof OCFile){
+ tagId = String.valueOf(((OCFile)mFile).getFileId());
+ } else if (mFile instanceof File){
+ tagId = String.valueOf(mFile.hashCode());
+ }
+ if (String.valueOf(imageView.getTag()).equals(tagId)) {
+ imageView.setImageBitmap(bitmap);
+ }
+ }
+ }
+ }
+
+ /**
+ * Add thumbnail to cache
+ * @param imageKey: thumb key
+ * @param bitmap: image for extracting thumbnail
+ * @param path: image path
+ * @param px: thumbnail dp
+ * @return Bitmap
+ */
+ private Bitmap addThumbnailToCache(String imageKey, Bitmap bitmap, String path, int px){
+
+ Bitmap thumbnail = ThumbnailUtils.extractThumbnail(bitmap, px, px);
+
+ // Rotate image, obeying exif tag
+ thumbnail = BitmapUtils.rotateImage(thumbnail,path);
+
+ // Add thumbnail to cache
+ addBitmapToCache(imageKey, thumbnail);
+
+ return thumbnail;
+ }
+
+ /**
+ * Converts size of file icon from dp to pixel
+ * @return int
+ */
+ private int getThumbnailDimension(){
+ // Converts dp to pixel
+ Resources r = MainApp.getAppContext().getResources();
+ return Math.round(r.getDimension(R.dimen.file_icon_size_grid));
+ }
+
+ private Bitmap doOCFileInBackground() {
+ OCFile file = (OCFile)mFile;
+
+ final String imageKey = String.valueOf(file.getRemoteId());