use of com.bumptech.glide.BitmapTypeRequest 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());
}
Rect rect = null;
if (config.cacheType >= CacheType.LAYOUT) {
rect = loadCache(holder.getSource());
if (rect != null) {
drawableWrapper.setBounds(rect);
}
} else {
drawableWrapper.setBounds(0, 0, holder.getWidth(), holder.getHeight());
}
if (holder.isGif()) {
target = new ImageTargetGif(textView, drawableWrapper, holder, config, this, rect);
load = dtr.asGif();
} else {
target = new ImageTargetBitmap(textView, drawableWrapper, holder, config, this, rect);
load = dtr.asBitmap().atMost();
}
checkTag(textView);
targets.add(target);
if (!config.resetSize && holder.isInvalidateSize()) {
load.override(holder.getWidth(), holder.getHeight());
}
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