Skip to content

Instantly share code, notes, and snippets.

@japharr
Created April 7, 2020 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save japharr/38b9d7e25c5b954dc38627ad8ae6069c to your computer and use it in GitHub Desktop.
Save japharr/38b9d7e25c5b954dc38627ad8ae6069c to your computer and use it in GitHub Desktop.
Creating thumbnail for video, image, folder or other file
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