Last active
February 24, 2017 22:54
-
-
Save v3n3/6f417a7fdc6bdc2c83bbc077cec8d8d6 to your computer and use it in GitHub Desktop.
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
| /** | |
| * Bind Glide with an ImageView. | |
| * | |
| * @param view the ImageView to bind to Glide. | |
| * @param src The URL of the image to load. | |
| * @param placeholder The placeholder icon. | |
| * @param error The error icon. | |
| * @param blurValue The blur radius value between 1 and 25. | |
| * @param cropCircle Crop the image in a circle of not. | |
| */ | |
| @SuppressWarnings("unchecked") | |
| @BindingAdapter(value = {"src", "placeholder", "error", "blur", "cropCircle"}, | |
| requireAll = false) | |
| public static void setGlideAdapter(ImageView view, String src, Drawable placeholder, | |
| Drawable error, int blurValue, boolean cropCircle) { | |
| if (view != null) { | |
| Context ctx = view.getContext(); | |
| DrawableTypeRequest<String> glideBuilder = Glide.with(ctx).load(src); | |
| List<Transformation<Bitmap>> filters = new ArrayList<>(); | |
| if (placeholder != null) { | |
| glideBuilder.placeholder(placeholder); | |
| } | |
| if (error != null) { | |
| glideBuilder.error(error); | |
| } | |
| if (blurValue > 0) { | |
| filters.add(new BlurTransformation(ctx, blurValue)); | |
| } | |
| if (cropCircle) { | |
| filters.add(new CropCircleTransformation(ctx)); | |
| } | |
| if (filters.size() > 0) { | |
| Transformation<Bitmap>[] filtersArr = new Transformation[filters.size()]; | |
| filtersArr = filters.toArray(filtersArr); | |
| glideBuilder.bitmapTransform(filtersArr); | |
| } | |
| glideBuilder.into(view); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment