small improvements for MediaUtils

main
Conny Duck 6 years ago
parent d64658f1f8
commit f7b344f84b
  1. 14
      app/src/main/java/com/keylesspalace/tusky/util/MediaUtils.java

@ -65,7 +65,7 @@ public class MediaUtils {
* Fetches the size of the media represented by the given URI, assuming it is openable and * Fetches the size of the media represented by the given URI, assuming it is openable and
* the ContentResolver is able to resolve it. * the ContentResolver is able to resolve it.
* *
* @return the size of the media or {@link MediaUtils#MEDIA_SIZE_UNKNOWN} * @return the size of the media in bytes or {@link MediaUtils#MEDIA_SIZE_UNKNOWN}
*/ */
public static long getMediaSize(@NonNull ContentResolver contentResolver, @Nullable Uri uri) { public static long getMediaSize(@NonNull ContentResolver contentResolver, @Nullable Uri uri) {
if(uri == null) return MEDIA_SIZE_UNKNOWN; if(uri == null) return MEDIA_SIZE_UNKNOWN;
@ -125,14 +125,12 @@ public class MediaUtils {
} }
@Nullable @Nullable
public static Bitmap getImageThumbnail(ContentResolver contentResolver, Uri uri, public static Bitmap getImageThumbnail(ContentResolver contentResolver, Uri uri, @Px int thumbnailSize) {
@Px int thumbnailSize) {
Bitmap source = getSampledBitmap(contentResolver, uri, thumbnailSize, thumbnailSize); Bitmap source = getSampledBitmap(contentResolver, uri, thumbnailSize, thumbnailSize);
if(source != null) { if(source == null) {
return ThumbnailUtils.extractThumbnail(source, thumbnailSize, thumbnailSize, ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
} else {
return null; return null;
} }
return ThumbnailUtils.extractThumbnail(source, thumbnailSize, thumbnailSize, ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
} }
@Nullable @Nullable
@ -143,9 +141,7 @@ public class MediaUtils {
if (source == null) { if (source == null) {
return null; return null;
} }
Bitmap bitmap = ThumbnailUtils.extractThumbnail(source, thumbnailSize, thumbnailSize); return ThumbnailUtils.extractThumbnail(source, thumbnailSize, thumbnailSize, ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
source.recycle();
return bitmap;
} }
public static long getImageSquarePixels(ContentResolver contentResolver, Uri uri) throws FileNotFoundException { public static long getImageSquarePixels(ContentResolver contentResolver, Uri uri) throws FileNotFoundException {

Loading…
Cancel
Save