Search in sources :

Example 1 with DrawableTypeRequest

use of com.bumptech.glide.DrawableTypeRequest 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;
}
Also used : BitmapTypeRequest(com.bumptech.glide.BitmapTypeRequest) Rect(android.graphics.Rect) GenericRequestBuilder(com.bumptech.glide.GenericRequestBuilder) DrawableWrapper(com.zzhoujay.richtext.drawable.DrawableWrapper) GifTypeRequest(com.bumptech.glide.GifTypeRequest) DrawableTypeRequest(com.bumptech.glide.DrawableTypeRequest)

Aggregations

Rect (android.graphics.Rect)1 BitmapTypeRequest (com.bumptech.glide.BitmapTypeRequest)1 DrawableTypeRequest (com.bumptech.glide.DrawableTypeRequest)1 GenericRequestBuilder (com.bumptech.glide.GenericRequestBuilder)1 GifTypeRequest (com.bumptech.glide.GifTypeRequest)1 DrawableWrapper (com.zzhoujay.richtext.drawable.DrawableWrapper)1