From 0d6320aa792b7e49b410f5582b84acbce2fc362a Mon Sep 17 00:00:00 2001 From: jabarros Date: Mon, 29 Dec 2014 09:26:44 +0100 Subject: [PATCH] Move isImage method to BitmapUtils class --- .../ui/adapter/LocalFileListAdapter.java | 11 ++--------- .../owncloud/android/utils/BitmapUtils.java | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/com/owncloud/android/ui/adapter/LocalFileListAdapter.java b/src/com/owncloud/android/ui/adapter/LocalFileListAdapter.java index 3d47d0d34e..f4cf73a889 100644 --- a/src/com/owncloud/android/ui/adapter/LocalFileListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/LocalFileListAdapter.java @@ -37,6 +37,7 @@ import android.widget.TextView; import com.owncloud.android.R; import com.owncloud.android.datamodel.ThumbnailsCacheManager; import com.owncloud.android.datamodel.ThumbnailsCacheManager.AsyncLocalDrawable; +import com.owncloud.android.utils.BitmapUtils; import com.owncloud.android.utils.DisplayUtils; /** @@ -133,7 +134,7 @@ public class LocalFileListAdapter extends BaseAdapter implements ListAdapter { } // get Thumbnail if file is image - if (isImage(file)){ + if (BitmapUtils.isImage(file)){ // Thumbnail in Cache? Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache( String.valueOf(file.hashCode()) @@ -222,12 +223,4 @@ public class LocalFileListAdapter extends BaseAdapter implements ListAdapter { } notifyDataSetChanged(); } - - private boolean isImage(File file) { - Uri selectedUri = Uri.fromFile(file); - String fileExtension = MimeTypeMap.getFileExtensionFromUrl(selectedUri.toString()); - String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtension); - - return (mimeType != null && mimeType.startsWith("image/")); - } } diff --git a/src/com/owncloud/android/utils/BitmapUtils.java b/src/com/owncloud/android/utils/BitmapUtils.java index 70367278a1..df04a41088 100644 --- a/src/com/owncloud/android/utils/BitmapUtils.java +++ b/src/com/owncloud/android/utils/BitmapUtils.java @@ -23,6 +23,10 @@ import android.graphics.BitmapFactory; import android.graphics.Matrix; import android.graphics.BitmapFactory.Options; import android.media.ExifInterface; +import android.net.Uri; +import android.webkit.MimeTypeMap; + +import java.io.File; /** * Utility class with methods for decoding Bitmaps. @@ -169,6 +173,18 @@ public class BitmapUtils { } return resultBitmap; } - + + /** + * Checks if file passed is an image + * @param file + * @return true/false + */ + public static boolean isImage(File file) { + Uri selectedUri = Uri.fromFile(file); + String fileExtension = MimeTypeMap.getFileExtensionFromUrl(selectedUri.toString()); + String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtension); + + return (mimeType != null && mimeType.startsWith("image/")); + } }