Skip to content

Instantly share code, notes, and snippets.

@zeeshanaslam78
Created April 3, 2020 01:06
Show Gist options
  • Save zeeshanaslam78/0371d7c4f6e282d778ede3a0bc6a9b3d to your computer and use it in GitHub Desktop.
Save zeeshanaslam78/0371d7c4f6e282d778ede3a0bc6a9b3d to your computer and use it in GitHub Desktop.
public static void convertToCircularBitmapDrawable(final Context context, Object url, ImageView imageView, int placeHolderResourceId) {
Bitmap placeholder = BitmapFactory.decodeResource(context.getResources(), placeHolderResourceId);
RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(context.getResources(), placeholder);
circularBitmapDrawable.setCircular(true);
Glide
.with(context)
.load(url)
.apply(new RequestOptions()
.circleCrop(context)
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.centerCrop(context)
.error(circularBitmapDrawable)
.placeholder(circularBitmapDrawable)
)
.apply(RequestOptions.circleCropTransform(context))
.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
if (e != null)
L.e(e);
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
return false;
}
})
.into(imageView)
;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment