changed back to latest owncloud-android-library
[pub/Android/ownCloud.git] / src / com / owncloud / android / datamodel / ThumbnailsCacheManager.java
index ce60cfe..5806a40 100644 (file)
@@ -55,6 +55,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.
@@ -188,8 +189,7 @@ public class ThumbnailsCacheManager {
                     thumbnail = doFileInBackground();
 
                     String url = ((File) mFile).getAbsolutePath();
-                    FileNameMap fileNameMap = URLConnection.getFileNameMap();
-                    String mMimeType = fileNameMap.getContentTypeFor("file://" + url);
+                    String mMimeType = FileStorageUtils.getMimeTypeFromName(url);
 
                     if (mMimeType != null && mMimeType.startsWith("video/")){
                         thumbnail = addVideoOverlay(thumbnail);
@@ -379,12 +379,12 @@ public class ThumbnailsCacheManager {
     }
 
     public static Bitmap addVideoOverlay(Bitmap thumbnail){
-        Bitmap bitmap2 = BitmapFactory.decodeResource(MainApp.getAppContext().getResources(),
-                                                          R.drawable.view_play);
+        Bitmap playButton = BitmapFactory.decodeResource(MainApp.getAppContext().getResources(),
+                R.drawable.view_play);
 
-        Bitmap resized = Bitmap.createScaledBitmap(bitmap2,
-                (int) (thumbnail.getWidth() * 0.6),
-                (int) (thumbnail.getHeight() * 0.6), true);
+        Bitmap resizedPlayButton = Bitmap.createScaledBitmap(playButton,
+                (int) (thumbnail.getWidth() * 0.3),
+                (int) (thumbnail.getHeight() * 0.3), true);
 
         Bitmap resultBitmap = Bitmap.createBitmap(thumbnail.getWidth(),
                 thumbnail.getHeight(),
@@ -392,13 +392,33 @@ public class ThumbnailsCacheManager {
 
         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(resized, (thumbnail.getWidth() - resized.getWidth()) / 2,
-                (thumbnail.getHeight() - resized.getHeight()) / 2, p);
+        c.drawBitmap(resizedPlayButton, (float) ((thumbnail.getWidth() / 2) + ox),
+                                        (float) ((thumbnail.getHeight() / 2) - ym), p);
 
         return resultBitmap;
     }