X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/ee25589d707182cdf280cf7730f3c4c94a41d664..0bd47a3fb5629f49bbcb72f7860a7fefcf17c9c0:/src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java diff --git a/src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java b/src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java index 3586fd58..8c36fa2e 100644 --- a/src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java +++ b/src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java @@ -24,6 +24,8 @@ package com.owncloud.android.datamodel; import java.io.File; import java.io.InputStream; import java.lang.ref.WeakReference; +import java.net.FileNameMap; +import java.net.URLConnection; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.GetMethod; @@ -37,6 +39,8 @@ import android.graphics.Bitmap.CompressFormat; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Point; +import android.graphics.Canvas; +import android.graphics.Paint; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; @@ -60,6 +64,7 @@ import com.owncloud.android.lib.resources.status.OwnCloudVersion; import com.owncloud.android.ui.adapter.DiskLruImageCache; import com.owncloud.android.utils.BitmapUtils; import com.owncloud.android.utils.DisplayUtils; +import com.owncloud.android.utils.FileStorageUtils; /** * Manager for concurrent access to thumbnails cache. @@ -161,9 +166,13 @@ public class ThumbnailsCacheManager { } } + /** + * Shows max cache size + * @return max cache size in MB. + */ public static long getMaxSize(){ if (mThumbnailCache != null) { - return mThumbnailCache.getMaxSize(); + return mThumbnailCache.getMaxSize() / 1024 / 1024; } else { return -1l; } @@ -216,10 +225,20 @@ public class ThumbnailsCacheManager { if (mFile instanceof OCFile) { thumbnail = doOCFileInBackground(mIsThumbnail); + + if (((OCFile) mFile).isVideo()){ + thumbnail = addVideoOverlay(thumbnail); + } } else if (mFile instanceof File) { thumbnail = doFileInBackground(mIsThumbnail); - } else { - // do nothing + + String url = ((File) mFile).getAbsolutePath(); + String mMimeType = FileStorageUtils.getMimeTypeFromName(url); + + if (mMimeType != null && mMimeType.startsWith("video/")){ + thumbnail = addVideoOverlay(thumbnail); + } + //} else { do nothing } }catch(Throwable t){ @@ -252,7 +271,7 @@ public class ThumbnailsCacheManager { } } imageView.setImageBitmap(bitmap); - imageView.setVisibility(View.VISIBLE); + // imageView.setVisibility(View.VISIBLE); } } } @@ -424,13 +443,20 @@ public class ThumbnailsCacheManager { } 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) { @@ -486,6 +512,51 @@ public class ThumbnailsCacheManager { return null; } + public static Bitmap addVideoOverlay(Bitmap thumbnail){ + Bitmap playButton = BitmapFactory.decodeResource(MainApp.getAppContext().getResources(), + R.drawable.view_play); + + Bitmap resizedPlayButton = Bitmap.createScaledBitmap(playButton, + (int) (thumbnail.getWidth() * 0.3), + (int) (thumbnail.getHeight() * 0.3), true); + + Bitmap resultBitmap = Bitmap.createBitmap(thumbnail.getWidth(), + thumbnail.getHeight(), + Bitmap.Config.ARGB_8888); + + Canvas c = new Canvas(resultBitmap); + + // compute visual center of play button, according to resized image + int x1 = resizedPlayButton.getWidth(); + int y1 = resizedPlayButton.getHeight() / 2; + int x2 = 0; + int y2 = resizedPlayButton.getWidth(); + int x3 = 0; + int y3 = 0; + + double ym = ( ((Math.pow(x3,2) - Math.pow(x1,2) + Math.pow(y3,2) - Math.pow(y1,2)) * + (x2 - x1)) - (Math.pow(x2,2) - Math.pow(x1,2) + Math.pow(y2,2) - + Math.pow(y1,2)) * (x3 - x1) ) / (2 * ( ((y3 - y1) * (x2 - x1)) - + ((y2 - y1) * (x3 - x1)) )); + double xm = ( (Math.pow(x2,2) - Math.pow(x1,2)) + (Math.pow(y2,2) - Math.pow(y1,2)) - + (2*ym*(y2 - y1)) ) / (2*(x2 - x1)); + + // offset to top left + double ox = - xm; + double oy = thumbnail.getHeight() - ym; + + + c.drawBitmap(thumbnail, 0, 0, null); + + Paint p = new Paint(); + p.setAlpha(230); + + c.drawBitmap(resizedPlayButton, (float) ((thumbnail.getWidth() / 2) + ox), + (float) ((thumbnail.getHeight() / 2) - ym), p); + + return resultBitmap; + } + public static class AsyncDrawable extends BitmapDrawable { private final WeakReference bitmapWorkerTaskReference;