77 签约房开始webp动画,练歌房右侧麦上用户刷新。
This commit is contained in:
@@ -26,13 +26,18 @@ import android.widget.LinearLayout;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.vectordrawable.graphics.drawable.Animatable2Compat;
|
||||
|
||||
import com.blankj.utilcode.util.ConvertUtils;
|
||||
import com.blankj.utilcode.util.Utils;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.integration.webp.decoder.WebpDrawable;
|
||||
import com.bumptech.glide.integration.webp.decoder.WebpDrawableTransformation;
|
||||
import com.bumptech.glide.load.DataSource;
|
||||
import com.bumptech.glide.load.Transformation;
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
import com.bumptech.glide.load.engine.GlideException;
|
||||
import com.bumptech.glide.load.resource.bitmap.CenterInside;
|
||||
import com.bumptech.glide.load.resource.gif.GifDrawable;
|
||||
import com.bumptech.glide.request.FutureTarget;
|
||||
import com.bumptech.glide.request.RequestListener;
|
||||
@@ -655,6 +660,54 @@ public class ImageUtils {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void loadWebpOneStart(int webp_anim, ImageView mAnimView){
|
||||
|
||||
if (mAnimView == null) {
|
||||
return;
|
||||
}
|
||||
// 1. 本地资源专属优化配置
|
||||
RequestOptions options = new RequestOptions()
|
||||
// 强制限制解码尺寸为ImageView显示尺寸(核心优化)
|
||||
.override(800, 800); // 本地图用原尺寸,或指定固定尺寸
|
||||
|
||||
//webp动图
|
||||
CenterInside transformation = new CenterInside();
|
||||
Glide.with(mAnimView)
|
||||
.load(webp_anim)//不是本地资源就改为url即可
|
||||
.apply(options)
|
||||
.optionalTransform(transformation)
|
||||
.optionalTransform(WebpDrawable.class, new WebpDrawableTransformation(transformation))
|
||||
.addListener(new RequestListener<Drawable>() {
|
||||
@Override
|
||||
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
|
||||
WebpDrawable webpDrawable = (WebpDrawable) resource;
|
||||
//需要设置为循环1次才会有onAnimationEnd回调
|
||||
webpDrawable.setLoopCount(1);
|
||||
webpDrawable.registerAnimationCallback(new Animatable2Compat.AnimationCallback() {
|
||||
@Override
|
||||
public void onAnimationStart(Drawable drawable) {
|
||||
super.onAnimationStart(drawable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Drawable drawable) {
|
||||
super.onAnimationEnd(drawable);
|
||||
webpDrawable.unregisterAnimationCallback(this);
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.into(mAnimView);
|
||||
}
|
||||
|
||||
public static void clearDiskCache(Context context){
|
||||
Glide.get(context).clearDiskCache();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user