Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ public final class ThumbnailsCacheManager {
public static final int THUMBNAIL_SIZE_IN_KB = 512;
private static final int RESIZED_IMAGE_SIZE_IN_KB = 10240;

public static final Bitmap mDefaultImg = BitmapFactory.decodeResource(MainApp.getAppContext().getResources(),
R.drawable.file_image);
public static final Bitmap mDefaultImg = BitmapUtils.rasterizeDrawable(R.drawable.file_image,
getThumbnailDimension());

public static final Bitmap mDefaultVideo = BitmapFactory.decodeResource(MainApp.getAppContext().getResources(),
R.drawable.file_movie);
public static final Bitmap mDefaultVideo = BitmapUtils.rasterizeDrawable(R.drawable.file_movie,
getThumbnailDimension());

private ThumbnailsCacheManager() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
Expand Down Expand Up @@ -453,14 +452,7 @@ public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? s
Bitmap bitmap;

if (resource instanceof PictureDrawable pictureDrawable) {
bitmap = Bitmap.createBitmap(
pictureDrawable.getIntrinsicWidth(),
pictureDrawable.getIntrinsicHeight(),
Bitmap.Config.ARGB_8888);

Canvas canvas = new Canvas(bitmap);
canvas.drawPicture(pictureDrawable.getPicture());

bitmap = BitmapUtils.rasterizePictureDrawable(pictureDrawable, MAX_LOGO_SIZE_PX);
} else if (resource instanceof BitmapDrawable bitmapDrawable) {
bitmap = bitmapDrawable.getBitmap();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ class UnifiedSearchItemViewHolder(

if (entry.thumbnailUrl.isNotBlank()) {
filesAction.loadFileThumbnail(entry) { client ->
ImageViewCompat.setImageTintList(binding.thumbnail, null)

if (entryType == SearchResultEntryType.Avatar) {
GlideHelper.loadCircularBitmapIntoImageView(
context,
Expand Down
22 changes: 22 additions & 0 deletions app/src/main/java/com/owncloud/android/utils/BitmapUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ import android.graphics.Rect
import android.graphics.RectF
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.graphics.drawable.PictureDrawable
import android.widget.ImageView
import androidx.annotation.DimenRes
import androidx.annotation.DrawableRes
import androidx.core.content.res.ResourcesCompat
import androidx.core.graphics.applyCanvas
import androidx.core.graphics.blue
import androidx.core.graphics.createBitmap
Expand All @@ -43,6 +46,7 @@ import com.owncloud.android.lib.resources.users.StatusType
import com.owncloud.android.ui.StatusDrawable
import java.security.MessageDigest
import java.security.NoSuchAlgorithmException
import kotlin.math.max
import kotlin.math.min
import kotlin.math.roundToInt
import com.nextcloud.utils.decodeSampledBitmapFromFile as decodeSampledBitmap
Expand Down Expand Up @@ -124,6 +128,24 @@ object BitmapUtils {
return bitmap.scale((scale * width).roundToInt(), (scale * height).roundToInt())
}

@JvmStatic
fun rasterizeDrawable(@DrawableRes drawableId: Int, size: Int): Bitmap {
val drawable = checkNotNull(ResourcesCompat.getDrawable(resources, drawableId, null))
return drawableToBitmap(drawable, size, size)
}

@JvmStatic
fun rasterizePictureDrawable(pictureDrawable: PictureDrawable, maxSize: Int): Bitmap {
val width = pictureDrawable.intrinsicWidth
val height = pictureDrawable.intrinsicHeight
val factor = min(1f, maxSize.toFloat() / max(width, height))

return createBitmap((width * factor).roundToInt(), (height * factor).roundToInt()).applyCanvas {
scale(factor, factor)
drawPicture(pictureDrawable.picture)
}
}

@Suppress("TooGenericExceptionCaught")
private fun readExifOrientation(storagePath: String): Int = try {
ExifInterface(storagePath).getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL)
Expand Down
Loading