Back to project page filemanager.
The source code is released under:
MIT License
If you think the Android project filemanager listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/** * The MIT License (MIT)//w w w . j av a 2 s.c om * * Copyright 2014 Binkery Huang <binkery@gmail.com> * * Oct 31, 2014 */ package com.binkery.app.filemanager.fragments; import java.io.File; import com.binkery.app.filemanager.utils.Logs; import android.content.Context; import android.database.Cursor; import android.graphics.Bitmap; import android.media.ThumbnailUtils; import android.os.Environment; import android.provider.MediaStore; import android.provider.MediaStore.Images; public class ThumbnailLoaderHelper { private static final String TAG = ThumbnailLoaderHelper.class .getSimpleName(); private static String getUserID() { String path = Environment.getExternalStorageDirectory() .getAbsolutePath(); Logs.i(TAG, "path = " + path); int index = path.lastIndexOf(File.separator); String num = path.substring(index + 1); return num; } public static Bitmap getImageThumbnail(File file, Context context) { if (file == null || !file.exists()) { return null; } String finalPath = file.getAbsolutePath(); try { finalPath = file.getCanonicalPath(); Logs.i(TAG, "canonical path = " + finalPath); if (finalPath.indexOf("legacy") != -1) { String id = getUserID(); finalPath = finalPath.replace("legacy", id); } } catch (Exception e) { } // if (MimeTypeUtils.isImage(file.getName())) { // return loadImageThumbnail(finalPath, context); // } else if (MimeTypeUtils.isVideo(file.getName())) { // return loadVideThumbnail(finalPath, context); // } return null; } private static final Bitmap loadVideThumbnail(String path, Context context) { return ThumbnailUtils.createVideoThumbnail(path, Images.Thumbnails.MINI_KIND); } private static final Bitmap loadImageThumbnail(String path, Context context) { Cursor cursor = context.getContentResolver().query( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new String[] { MediaStore.Images.Media._ID }, MediaStore.Images.Media.DATA + " = ? ", new String[] { path }, null); if (cursor == null) { Logs.i(TAG, "cursor is null 1"); return null; } if (!cursor.moveToFirst()) { cursor.close(); Logs.i(TAG, "cursor is empty 1"); return null; } int imageId = cursor.getInt(cursor .getColumnIndex(MediaStore.Images.Media._ID)); Logs.i(TAG, "image id = " + imageId); cursor.close(); Bitmap bitmap = MediaStore.Images.Thumbnails.getThumbnail( context.getContentResolver(), imageId, MediaStore.Images.Thumbnails.MINI_KIND, null); bitmap = ThumbnailUtils.extractThumbnail(bitmap, 96, 96, ThumbnailUtils.OPTIONS_RECYCLE_INPUT); return bitmap; } }