下面列出了com.bumptech.glide.load.resource.gif.GifDrawable#setCallback ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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();
}
public void recycle() {
targets.clear();
for (GifDrawable gifDrawable : gifDrawables) {
gifDrawable.setCallback(null);
gifDrawable.recycle();
}
gifDrawables.clear();
}
@Override
public void recycle() {
Glide.clear(this);
if (gifDrawableSoftReference != null) {
GifDrawable gifDrawable = gifDrawableSoftReference.get();
if (gifDrawable != null) {
gifDrawable.setCallback(null);
gifDrawable.stop();
}
}
}
@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();
}