Browse Source

Merge pull request #5231 from nextcloud/roundedCorners

images: slightly rounded corners
Tobias Kaminsky 5 years ago
parent
commit
0c272ad1d7

+ 1 - 1
scripts/analysis/findbugs-results.txt

@@ -1 +1 @@
-413
+414

+ 16 - 1
src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java

@@ -410,12 +410,23 @@ public final class ThumbnailsCacheManager {
         private String mImageKey;
         private FileDataStorageManager mStorageManager;
         private GetMethod getMethod;
+        private boolean roundedCorners = false;
 
         public ThumbnailGenerationTask(ImageView imageView, FileDataStorageManager storageManager, Account account)
                 throws IllegalArgumentException {
             this(imageView, storageManager, account, null);
         }
 
+        public ThumbnailGenerationTask(ImageView imageView,
+                                       FileDataStorageManager storageManager,
+                                       Account account,
+                                       List<ThumbnailGenerationTask> asyncTasks,
+                                       boolean roundedCorners)
+            throws IllegalArgumentException {
+            this(imageView, storageManager, account, asyncTasks);
+            this.roundedCorners = roundedCorners;
+        }
+
         public ThumbnailGenerationTask(ImageView imageView, FileDataStorageManager storageManager,
                                        Account account, List<ThumbnailGenerationTask> asyncTasks)
                 throws IllegalArgumentException {
@@ -508,7 +519,11 @@ public final class ThumbnailsCacheManager {
                         tagId = String.valueOf(((TrashbinFile) mFile).getRemoteId());
                     }
                     if (String.valueOf(imageView.getTag()).equals(tagId)) {
-                        imageView.setImageBitmap(bitmap);
+                        if (roundedCorners) {
+                            BitmapUtils.setRoundedBitmap(bitmap, imageView);
+                        } else {
+                            imageView.setImageBitmap(bitmap);
+                        }
                     }
                 }
             }

+ 7 - 2
src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java

@@ -602,7 +602,11 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
                         Bitmap withOverlay = ThumbnailsCacheManager.addVideoOverlay(thumbnail);
                         thumbnailView.setImageBitmap(withOverlay);
                     } else {
-                        thumbnailView.setImageBitmap(thumbnail);
+                        if (gridView) {
+                            thumbnailView.setImageBitmap(thumbnail);
+                        } else {
+                            BitmapUtils.setRoundedBitmap(thumbnail, thumbnailView);
+                        }
                     }
                 } else {
                     // generate new thumbnail
@@ -612,7 +616,8 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
                                 new ThumbnailsCacheManager.ThumbnailGenerationTask(thumbnailView,
                                                                                    mStorageManager,
                                                                                    user.toPlatformAccount(),
-                                                                                   asyncTasks);
+                                                                                   asyncTasks,
+                                                                                   !gridView);
 
                             if (thumbnail == null) {
                                 thumbnail = BitmapUtils.drawableToBitmap(

+ 31 - 1
src/main/java/com/owncloud/android/utils/BitmapUtils.java

@@ -26,7 +26,10 @@ import android.graphics.Canvas;
 import android.graphics.Matrix;
 import android.graphics.drawable.BitmapDrawable;
 import android.graphics.drawable.Drawable;
+import android.widget.ImageView;
 
+import com.owncloud.android.MainApp;
+import com.owncloud.android.R;
 import com.owncloud.android.lib.common.utils.Log_OC;
 
 import org.apache.commons.codec.binary.Hex;
@@ -376,16 +379,34 @@ public final class BitmapUtils {
      * @param bitmap the original bitmap
      * @return the circular bitmap
      */
-    public static RoundedBitmapDrawable bitmapToCircularBitmapDrawable(Resources resources, Bitmap bitmap) {
+    public static RoundedBitmapDrawable bitmapToCircularBitmapDrawable(Resources resources,
+                                                                       Bitmap bitmap,
+                                                                       float radius) {
         if (bitmap == null) {
             return null;
         }
 
         RoundedBitmapDrawable roundedBitmap = RoundedBitmapDrawableFactory.create(resources, bitmap);
         roundedBitmap.setCircular(true);
+
+        if (radius != -1) {
+            roundedBitmap.setCornerRadius(radius);
+        }
+
         return roundedBitmap;
     }
 
+    public static RoundedBitmapDrawable bitmapToCircularBitmapDrawable(Resources resources, Bitmap bitmap) {
+        return bitmapToCircularBitmapDrawable(resources, bitmap, -1);
+    }
+
+    public static void setRoundedBitmap(Resources resources, Bitmap bitmap, float radius, ImageView imageView) {
+
+        imageView.setImageDrawable(BitmapUtils.bitmapToCircularBitmapDrawable(resources,
+                                                                              bitmap,
+                                                                              radius));
+    }
+
     public static Bitmap drawableToBitmap(Drawable drawable) {
         if (drawable instanceof BitmapDrawable) {
             BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
@@ -407,4 +428,13 @@ public final class BitmapUtils {
         drawable.draw(canvas);
         return bitmap;
     }
+
+    public static void setRoundedBitmap(Bitmap thumbnail, ImageView imageView) {
+        Resources resources = MainApp.getAppContext().getResources();
+
+        BitmapUtils.setRoundedBitmap(resources,
+                                     thumbnail,
+                                     resources.getDimension(R.dimen.file_icon_rounded_corner_radius),
+                                     imageView);
+    }
 }

+ 1 - 0
src/main/res/values/dims.xml

@@ -30,6 +30,7 @@
     <dimen name="list_item_avatar_icon_radius">20dp</dimen>
     <dimen name="file_icon_size">40dp</dimen>
     <dimen name="file_icon_size_grid">128dp</dimen>
+    <dimen name="file_icon_rounded_corner_radius">8dp</dimen>
     <dimen name="file_avatar_size">128dp</dimen>
     <dimen name="standard_padding">16dp</dimen>
     <dimen name="standard_double_padding">32dp</dimen>