mirror of
https://github.com/nextcloud/android.git
synced 2024-11-28 18:28:59 +03:00
Merge pull request #5231 from nextcloud/roundedCorners
images: slightly rounded corners
This commit is contained in:
commit
0c272ad1d7
5 changed files with 56 additions and 5 deletions
|
@ -1 +1 @@
|
|||
413
|
||||
414
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue