public static FileCategory getCategoryFromPath(String path) { MediaFileType type = MediaFile.getFileType(path); if (type != null) { if (MediaFile.isAudioFileType(type.fileType)) return FileCategory.Music; if (MediaFile.isVideoFileType(type.fileType)) return FileCategory.Video; if (MediaFile.isImageFileType(type.fileType)) return FileCategory.Picture; if (Util.sDocMimeTypesSet.contains(type.mimeType)) return FileCategory.Doc; } int dotPosition = path.lastIndexOf('.'); if (dotPosition < 0) { return FileCategory.Other; } String ext = path.substring(dotPosition + 1); if (ext.equalsIgnoreCase(APK_EXT)) { return FileCategory.Apk; } if (ext.equalsIgnoreCase(THEME_EXT)) { return FileCategory.Theme; } if (matchExts(ext, ZIP_EXTS)) { return FileCategory.Zip; } return FileCategory.Other; }
@Override public Future<BitmapInfo> loadBitmap(Ion ion, String uri, int resizeWidth, int resizeHeight) { if (!uri.startsWith(ContentResolver.SCHEME_FILE)) return null; final File file = new File(URI.create(uri)); MediaFile.MediaFileType type = MediaFile.getFileType(file.getAbsolutePath()); if (type == null || !MediaFile.isVideoFileType(type.fileType)) return null; final SimpleFuture<BitmapInfo> ret = new SimpleFuture<BitmapInfo>(); Ion.getBitmapLoadExecutorService() .execute( new Runnable() { @Override public void run() { if (ret.isCancelled()) { // Log.d("VideoLoader", "Bitmap load cancelled (no longer // needed)"); return; } try { Bitmap bmp = createVideoThumbnail(file.getAbsolutePath()); if (bmp == null) throw new Exception("video bitmap failed to load"); BitmapInfo info = new BitmapInfo(); info.bitmaps = new Bitmap[] {bmp}; info.loadedFrom = LoaderEmitter.LOADED_FROM_CACHE; ret.setComplete(info); } catch (Exception e) { ret.setComplete(e); } } }); return ret; }