Merge pull request #5231 from nextcloud/roundedCorners

images: slightly rounded corners
This commit is contained in:
Tobias Kaminsky 2020-02-03 13:47:15 +01:00 committed by GitHub
commit 0c272ad1d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 56 additions and 5 deletions

View file

@ -1 +1 @@
413
414

View file

@ -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,10 +519,14 @@ public final class ThumbnailsCacheManager {
tagId = String.valueOf(((TrashbinFile) mFile).getRemoteId());
}
if (String.valueOf(imageView.getTag()).equals(tagId)) {
if (roundedCorners) {
BitmapUtils.setRoundedBitmap(bitmap, imageView);
} else {
imageView.setImageBitmap(bitmap);
}
}
}
}
if (mAsyncTasks != null) {
mAsyncTasks.remove(this);

View file

@ -602,7 +602,11 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
Bitmap withOverlay = ThumbnailsCacheManager.addVideoOverlay(thumbnail);
thumbnailView.setImageBitmap(withOverlay);
} else {
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(

View file

@ -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);
}
}

View file

@ -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>