Move isImage method to BitmapUtils class

This commit is contained in:
jabarros 2014-12-29 09:26:44 +01:00
parent 6e3d3cd016
commit 0d6320aa79
2 changed files with 19 additions and 10 deletions

View file

@ -37,6 +37,7 @@ import android.widget.TextView;
import com.owncloud.android.R; import com.owncloud.android.R;
import com.owncloud.android.datamodel.ThumbnailsCacheManager; import com.owncloud.android.datamodel.ThumbnailsCacheManager;
import com.owncloud.android.datamodel.ThumbnailsCacheManager.AsyncLocalDrawable; import com.owncloud.android.datamodel.ThumbnailsCacheManager.AsyncLocalDrawable;
import com.owncloud.android.utils.BitmapUtils;
import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.DisplayUtils;
/** /**
@ -133,7 +134,7 @@ public class LocalFileListAdapter extends BaseAdapter implements ListAdapter {
} }
// get Thumbnail if file is image // get Thumbnail if file is image
if (isImage(file)){ if (BitmapUtils.isImage(file)){
// Thumbnail in Cache? // Thumbnail in Cache?
Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache( Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(
String.valueOf(file.hashCode()) String.valueOf(file.hashCode())
@ -222,12 +223,4 @@ public class LocalFileListAdapter extends BaseAdapter implements ListAdapter {
} }
notifyDataSetChanged(); 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/"));
}
} }

View file

@ -23,6 +23,10 @@ import android.graphics.BitmapFactory;
import android.graphics.Matrix; import android.graphics.Matrix;
import android.graphics.BitmapFactory.Options; import android.graphics.BitmapFactory.Options;
import android.media.ExifInterface; import android.media.ExifInterface;
import android.net.Uri;
import android.webkit.MimeTypeMap;
import java.io.File;
/** /**
* Utility class with methods for decoding Bitmaps. * Utility class with methods for decoding Bitmaps.
@ -169,6 +173,18 @@ public class BitmapUtils {
} }
return resultBitmap; 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/"));
}
} }