Search in sources :

Example 11 with DrawableWrapper

use of com.zzhoujay.richtext.drawable.DrawableWrapper in project RichText by zzhoujay.

the class ImageTargetBitmap method onResourceReady.

@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
    if (!activityIsAlive()) {
        return;
    }
    DrawableWrapper drawableWrapper = urlDrawableWeakReference.get();
    if (drawableWrapper == null) {
        return;
    }
    TextView textView = textViewWeakReference.get();
    holder.setImageState(ImageHolder.ImageState.READY);
    holder.setSize(resource.getWidth(), resource.getHeight());
    Drawable drawable = new BitmapDrawable(textView.getContext().getResources(), resource);
    drawableWrapper.setDrawable(drawable);
    if (holder.getCachedBound() != null) {
        drawableWrapper.setBounds(holder.getCachedBound());
    } else {
        if (!config.autoFix && config.imageFixCallback != null) {
            config.imageFixCallback.onImageReady(holder, resource.getWidth(), resource.getHeight());
        }
        if (config.autoFix || holder.isAutoFix() || !holder.isInvalidateSize()) {
            int width = getRealWidth();
            int height = (int) ((float) resource.getHeight() * width / resource.getWidth());
            drawableWrapper.setBounds(0, 0, width, height);
        } else {
            drawableWrapper.setBounds(0, 0, (int) holder.getScaleWidth(), (int) holder.getScaleHeight());
        }
    }
    resetText();
    loadDone();
}
Also used : DrawableWrapper(com.zzhoujay.richtext.drawable.DrawableWrapper) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) TextView(android.widget.TextView) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Aggregations

DrawableWrapper (com.zzhoujay.richtext.drawable.DrawableWrapper)11 Bitmap (android.graphics.Bitmap)3 BitmapDrawable (android.graphics.drawable.BitmapDrawable)3 Rect (android.graphics.Rect)2 Drawable (android.graphics.drawable.Drawable)2 TextView (android.widget.TextView)2 BitmapTypeRequest (com.bumptech.glide.BitmapTypeRequest)1 DrawableTypeRequest (com.bumptech.glide.DrawableTypeRequest)1 GenericRequestBuilder (com.bumptech.glide.GenericRequestBuilder)1 GifTypeRequest (com.bumptech.glide.GifTypeRequest)1 Call (okhttp3.Call)1 Request (okhttp3.Request)1