com.bumptech.glide.request.target.CustomViewTarget Java Examples

The following examples show how to use com.bumptech.glide.request.target.CustomViewTarget. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AvatarUtil.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public static void loadBlurredIconIntoViewBackground(@NonNull Recipient recipient, @NonNull View target) {
  Context context = target.getContext();

  if (recipient.getContactPhoto() == null) {
    target.setBackgroundColor(ContextCompat.getColor(target.getContext(), R.color.black));
    return;
  }

  GlideApp.with(target)
          .load(recipient.getContactPhoto())
          .transform(new CenterCrop(), new BlurTransformation(context, 0.25f, BlurTransformation.MAX_RADIUS))
          .into(new CustomViewTarget<View, Drawable>(target) {
            @Override
            public void onLoadFailed(@Nullable Drawable errorDrawable) {
              target.setBackgroundColor(ContextCompat.getColor(target.getContext(), R.color.black));
            }

            @Override
            public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
              target.setBackground(resource);
            }

            @Override
            protected void onResourceCleared(@Nullable Drawable placeholder) {
              target.setBackground(placeholder);
            }
          });
}