下面列出了怎么用com.bumptech.glide.request.target.CustomViewTarget的API类实例代码及写法,或者点击链接到github查看源代码。
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);
}
});
}