use of com.bumptech.glide.GifTypeRequest in project RichText by zzhoujay.
the class GlideImageGetter method getDrawable.
@Override
public Drawable getDrawable(ImageHolder holder, final RichTextConfig config, TextView textView) {
final ImageTarget target;
final GenericRequestBuilder load;
DrawableTypeRequest dtr;
DrawableWrapper drawableWrapper = new DrawableWrapper();
byte[] src = Base64.decode(holder.getSource());
if (src != null) {
dtr = Glide.with(textView.getContext()).load(src);
} else {
dtr = Glide.with(textView.getContext()).load(holder.getSource());
}
if (holder.isGif()) {
target = new ImageTargetGif(textView, drawableWrapper, holder, config, this);
load = dtr.asGif();
} else {
target = new ImageTargetBitmap(textView, drawableWrapper, holder, config, this);
load = dtr.asBitmap().atMost();
}
checkTag(textView);
targets.add(target);
if (!config.resetSize && holder.isInvalidateSize()) {
load.override((int) holder.getScaleWidth(), (int) holder.getScaleHeight());
}
if (config.cacheType >= CacheType.LAYOUT) {
Rect rect = loadCache(holder.getSource());
if (rect != null) {
holder.setCachedBound(rect);
drawableWrapper.setBounds(rect);
}
} else {
drawableWrapper.setBounds(0, 0, (int) holder.getScaleWidth(), (int) holder.getScaleHeight());
}
if (holder.getScaleType() == ImageHolder.ScaleType.CENTER_CROP) {
if (holder.isGif()) {
//noinspection ConstantConditions
((GifTypeRequest) load).centerCrop();
} else {
//noinspection ConstantConditions
((BitmapTypeRequest) load).centerCrop();
}
} else if (holder.getScaleType() == ImageHolder.ScaleType.FIT_CENTER) {
if (holder.isGif()) {
//noinspection ConstantConditions
((GifTypeRequest) load).fitCenter();
} else {
//noinspection ConstantConditions
((BitmapTypeRequest) load).fitCenter();
}
}
textView.post(new Runnable() {
@Override
public void run() {
load.placeholder(config.placeHolder).error(config.errorImage).into(target);
}
});
drawableWrapper.setCallback(textView);
return drawableWrapper;
}
Aggregations