Преглед изворни кода

Merge pull request #9466 from nextcloud/enhancePlayIcon

Play button as overlay on videos is now more sharpe on large displays
Álvaro Brey пре 3 година
родитељ
комит
739364dd63

+ 10 - 4
src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java

@@ -23,7 +23,6 @@
 
 package com.owncloud.android.datamodel;
 
-import android.accounts.Account;
 import android.content.Context;
 import android.content.res.Resources;
 import android.graphics.Bitmap;
@@ -1074,14 +1073,21 @@ public final class ThumbnailsCacheManager {
     }
 
     public static Bitmap addVideoOverlay(Bitmap thumbnail) {
+        int playButtonWidth = (int) (thumbnail.getWidth() * 0.3);
+        int playButtonHeight = (int) (thumbnail.getHeight() * 0.3);
+
         Drawable playButtonDrawable = ResourcesCompat.getDrawable(MainApp.getAppContext().getResources(),
                                                                   R.drawable.view_play,
                                                                   null);
-        Bitmap playButton = BitmapUtils.drawableToBitmap(playButtonDrawable);
+
+        Bitmap playButton = BitmapUtils.drawableToBitmap(playButtonDrawable,
+                                                         playButtonWidth,
+                                                         playButtonHeight);
 
         Bitmap resizedPlayButton = Bitmap.createScaledBitmap(playButton,
-                                                             (int) (thumbnail.getWidth() * 0.3),
-                                                             (int) (thumbnail.getHeight() * 0.3), true);
+                                                             playButtonWidth,
+                                                             playButtonHeight,
+                                                             true);
 
         Bitmap resultBitmap = Bitmap.createBitmap(thumbnail.getWidth(),
                                                   thumbnail.getHeight(),

+ 25 - 10
src/main/java/com/owncloud/android/utils/BitmapUtils.java

@@ -372,6 +372,10 @@ public final class BitmapUtils {
     }
 
     public static Bitmap drawableToBitmap(Drawable drawable) {
+        return drawableToBitmap(drawable, -1, -1);
+    }
+
+    public static Bitmap drawableToBitmap(Drawable drawable, int desiredWidth, int desiredHeight) {
         if (drawable instanceof BitmapDrawable) {
             BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
             if (bitmapDrawable.getBitmap() != null) {
@@ -380,20 +384,31 @@ public final class BitmapUtils {
         }
 
         Bitmap bitmap;
-        if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
-            if (drawable.getBounds().width() > 0 && drawable.getBounds().height() > 0) {
-                bitmap = Bitmap.createBitmap(drawable.getBounds().width(),
-                                             drawable.getBounds().height(),
-                                             Bitmap.Config.ARGB_8888);
+        int width;
+        int height;
+
+        if (desiredWidth > 0 && desiredHeight > 0) {
+            width = desiredWidth;
+            height = desiredHeight;
+        } else {
+            if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
+                if (drawable.getBounds().width() > 0 && drawable.getBounds().height() > 0) {
+                    width = drawable.getBounds().width();
+                    height = drawable.getBounds().height();
+                } else {
+                    width = 1;
+                    height = 1;
+                }
             } else {
-                bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
+                width = drawable.getIntrinsicWidth();
+                height = drawable.getIntrinsicHeight();
             }
-        } else {
-            bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
-                                         drawable.getIntrinsicHeight(),
-                                         Bitmap.Config.ARGB_8888);
         }
 
+        bitmap = Bitmap.createBitmap(width,
+                                     height,
+                                     Bitmap.Config.ARGB_8888);
+
         Canvas canvas = new Canvas(bitmap);
         drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
         drawable.draw(canvas);