Java Code Examples for com.bumptech.glide.load.resource.gif.GifDrawable#setCallback()

The following examples show how to use com.bumptech.glide.load.resource.gif.GifDrawable#setCallback() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GlideImageGeter.java    From NewFastFrame with Apache License 2.0 6 votes vote down vote up
@Override
public void onResourceReady(@NonNull GifDrawable resource, @Nullable Transition<? super GifDrawable> transition) {
    int w = DensityUtil.getScreenWidth(mContext);
    int hh = resource.getIntrinsicHeight();
    int ww = resource.getIntrinsicWidth();
    int high = hh * (w - 50) / ww;
    Rect rect = new Rect(20, 20, w - 30, high);
    resource.setBounds(rect);
    urlDrawable.setBounds(rect);
    urlDrawable.setDrawable(resource);
    gifDrawables.add(resource);
    resource.setCallback(mTextView);
    resource.start();
    resource.setLoopCount(GifDrawable.LOOP_FOREVER);
    mTextView.setText(mTextView.getText());
    mTextView.invalidate();
}
 
Example 2
Source File: GlideImageGeter.java    From NewFastFrame with Apache License 2.0 5 votes vote down vote up
public void recycle() {
    targets.clear();
    for (GifDrawable gifDrawable : gifDrawables) {
        gifDrawable.setCallback(null);
        gifDrawable.recycle();
    }
    gifDrawables.clear();
}
 
Example 3
Source File: ImageTargetGif.java    From RichText with MIT License 5 votes vote down vote up
@Override
public void recycle() {
    Glide.clear(this);
    if (gifDrawableSoftReference != null) {
        GifDrawable gifDrawable = gifDrawableSoftReference.get();
        if (gifDrawable != null) {
            gifDrawable.setCallback(null);
            gifDrawable.stop();
        }
    }
}
 
Example 4
Source File: ImageTargetGif.java    From RichText with MIT License 5 votes vote down vote up
@Override
public void onResourceReady(GifDrawable resource, GlideAnimation<? super GifDrawable> glideAnimation) {
    if (!activityIsAlive()) {
        return;
    }
    DrawableWrapper drawableWrapper = urlDrawableWeakReference.get();
    if (drawableWrapper == null) {
        return;
    }
    holder.setImageState(ImageHolder.ImageState.READY);
    gifDrawableSoftReference = new SoftReference<>(resource);
    Bitmap first = resource.getFirstFrame();
    holder.setSize(first.getWidth(), first.getHeight());
    drawableWrapper.setDrawable(resource);
    if (rect != null) {
        drawableWrapper.setBounds(rect);
    } else {
        if (!config.autoFix && config.imageFixCallback != null) {
            config.imageFixCallback.onImageReady(holder, first.getWidth(), first.getHeight());
        }
        if (config.autoFix || holder.isAutoFix() || !holder.isInvalidateSize()) {
            int width = getRealWidth();
            int height = (int) ((float) first.getHeight() * width / first.getWidth());
            drawableWrapper.setBounds(0, 0, width, height);
        } else {
            drawableWrapper.setBounds(0, 0, holder.getWidth(), holder.getHeight());
        }
        if (holder.isAutoPlay()) {
            resource.setCallback(this);
            resource.start();
            resource.setLoopCount(GlideDrawable.LOOP_FOREVER);
        }
    }
    resetText();
    loadDone();
}