Created
April 7, 2020 20:51
-
-
Save japharr/38b9d7e25c5b954dc38627ad8ae6069c to your computer and use it in GitHub Desktop.
Creating thumbnail for video, image, folder or other file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void bind(FileItem item) { | |
this.item = item; | |
if (item.isVideo()) { | |
Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail( | |
item.path, MediaStore.Video.Thumbnails.MINI_KIND); | |
image.setImageBitmap(thumbnail); | |
} else if (item.isImage()) { | |
BitmapFactory.Options bmOptions = new BitmapFactory.Options(); | |
Bitmap bitmap = BitmapFactory.decodeFile(item.path, bmOptions); | |
bitmap = Bitmap.createScaledBitmap(bitmap, itemView.getWidth(), itemView.getHeight(), true); | |
image.setImageBitmap(bitmap); | |
} else if (item.isDirectory) { | |
image.setImageResource(R.drawable.hd_ic_folder); | |
} else { | |
image.setImageResource(R.drawable.hd_ic_file); | |
} | |
text.setText(item.name); | |
date.setText(item.lastModified); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment