Merge branch 'dev_Memory' into dev_test
# Conflicts: # app/src/main/java/com/shayu/phonelive/AppContext.java # common/src/main/java/com/yunbao/common/glide/ImgLoader.java # dependencies.gradle # live/src/main/java/com/yunbao/live/adapter/UserMoreInfoAdapter.java # live/src/main/java/com/yunbao/live/views/LiveAudienceViewHolder.java # main/src/main/java/com/yunbao/main/activity/ZhuangBanActivity.java # main/src/main/java/com/yunbao/main/adapter/MainListAdapter.java
This commit is contained in:
@@ -104,7 +104,9 @@ dependencies {
|
||||
api rootProject.ext.dependencies["gif-drawable"]
|
||||
|
||||
//svga播放器
|
||||
api rootProject.ext.dependencies["SVGAPlayer"]
|
||||
//api rootProject.ext.dependencies["SVGAPlayer"]
|
||||
implementation 'com.squareup.wire:wire-runtime:4.4.1'
|
||||
api files('libs/library-release.aar')
|
||||
|
||||
//七牛云存储
|
||||
api rootProject.ext.dependencies["qiniu-sdk"]
|
||||
|
||||
BIN
common/libs/library-release.aar
Normal file
BIN
common/libs/library-release.aar
Normal file
Binary file not shown.
@@ -2,7 +2,9 @@ package com.yunbao.common.glide;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.media.ThumbnailUtils;
|
||||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.ImageView;
|
||||
@@ -13,6 +15,7 @@ import androidx.annotation.Nullable;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.bumptech.glide.request.target.CustomTarget;
|
||||
import com.bumptech.glide.request.target.SimpleTarget;
|
||||
import com.bumptech.glide.request.transition.Transition;
|
||||
import com.yunbao.common.R;
|
||||
|
||||
@@ -33,36 +36,120 @@ public class ImgLoader {
|
||||
sBlurTransformation = new BlurTransformation(25);
|
||||
}
|
||||
|
||||
|
||||
public static void display(Context context, String url, ImageView imageView) {
|
||||
display(context, url, imageView, -1, -1);
|
||||
}
|
||||
|
||||
public static void display(Context context, String url, ImageView imageView, int width, int height) {
|
||||
if (!contextIsExist(context)) {
|
||||
return;
|
||||
}
|
||||
Glide.with(context).asDrawable().load(url).skipMemoryCache(SKIP_MEMORY_CACHE).into(imageView);
|
||||
Glide.with(context)
|
||||
.asBitmap()
|
||||
.load(url)
|
||||
.skipMemoryCache(SKIP_MEMORY_CACHE)
|
||||
.into(new CustomTarget<Bitmap>() {
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
|
||||
if (width == -1 || height == -1) {
|
||||
imageView.setImageBitmap(resource);
|
||||
} else {
|
||||
Bitmap bitmap = ThumbnailUtils.extractThumbnail(resource, width, height);
|
||||
imageView.setImageBitmap(bitmap);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadCleared(@Nullable Drawable placeholder) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void display2(Context context, String url, ImageView imageView) {
|
||||
display2(context, url, imageView, -1, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 手动清空内存
|
||||
*/
|
||||
public static void clearMemory(Context context){
|
||||
Glide.get(context)
|
||||
.clearMemory();
|
||||
}
|
||||
public static void display2(Context context, String url, ImageView imageView, int width, int height) {
|
||||
if (!contextIsExist(context)) {
|
||||
return;
|
||||
}
|
||||
Glide.with(context).asDrawable().load(url).placeholder(imageView.getDrawable()).dontAnimate().skipMemoryCache(SKIP_MEMORY_CACHE).into(imageView);
|
||||
Glide.with(context)
|
||||
.asBitmap()
|
||||
.load(url)
|
||||
.placeholder(imageView.getDrawable())
|
||||
.dontAnimate()
|
||||
.skipMemoryCache(SKIP_MEMORY_CACHE)
|
||||
.into(new CustomTarget<Bitmap>() {
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
|
||||
if (width == -1 || height == -1) {
|
||||
imageView.setImageBitmap(resource);
|
||||
} else {
|
||||
Bitmap bitmap = ThumbnailUtils.extractThumbnail(resource, width, height);
|
||||
imageView.setImageBitmap(bitmap);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadCleared(@Nullable Drawable placeholder) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void display2(Context context, int url, ImageView imageView) {
|
||||
if (!contextIsExist(context)) {
|
||||
return;
|
||||
}
|
||||
Glide.with(context).asDrawable().load(url).placeholder(imageView.getDrawable()).dontAnimate().skipMemoryCache(SKIP_MEMORY_CACHE).into(imageView);
|
||||
Glide.with(context)
|
||||
.asDrawable()
|
||||
.load(url)
|
||||
.placeholder(imageView.getDrawable())
|
||||
.dontAnimate()
|
||||
.skipMemoryCache(SKIP_MEMORY_CACHE)
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
public static void displayWithError(Context context, String url, ImageView imageView, int errorRes) {
|
||||
displayWithError(context, url, imageView, errorRes, -1, -1);
|
||||
}
|
||||
|
||||
public static void displayWithError(Context context, String url, ImageView imageView, int errorRes, int width, int height) {
|
||||
if (!contextIsExist(context)) {
|
||||
return;
|
||||
}
|
||||
if (imageView == null) {
|
||||
return;
|
||||
}
|
||||
Glide.with(context).asDrawable().load(url).error(errorRes).skipMemoryCache(SKIP_MEMORY_CACHE).into(imageView);
|
||||
Glide.with(context)
|
||||
.asBitmap()
|
||||
.load(url)
|
||||
.error(errorRes)
|
||||
.skipMemoryCache(SKIP_MEMORY_CACHE)
|
||||
.into(new CustomTarget<Bitmap>() {
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
|
||||
if (width == -1 || height == -1) {
|
||||
imageView.setImageBitmap(resource);
|
||||
} else {
|
||||
Bitmap bitmap = ThumbnailUtils.extractThumbnail(resource, width, height);
|
||||
imageView.setImageBitmap(bitmap);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadCleared(@Nullable Drawable placeholder) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void displayWithError(Context context, int url, ImageView imageView, int errorRes) {
|
||||
@@ -79,8 +166,34 @@ public class ImgLoader {
|
||||
if (!contextIsExist(context)) {
|
||||
return;
|
||||
}
|
||||
displayWithError(context, url, imageView, R.mipmap.icon_avatar_placeholder);
|
||||
displayAvatar(context, url, imageView, -1, -1);
|
||||
}
|
||||
|
||||
public static void displayAvatar(Context context, String url, ImageView imageView, int width, int height) {
|
||||
if (!contextIsExist(context)) {
|
||||
return;
|
||||
}
|
||||
Glide.with(context)
|
||||
.asBitmap()
|
||||
.load(url)
|
||||
.error(R.mipmap.icon_avatar_placeholder)
|
||||
.skipMemoryCache(SKIP_MEMORY_CACHE)
|
||||
.into(new CustomTarget<Bitmap>() {
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
|
||||
if (width == -1 || height == -1) {
|
||||
imageView.setImageBitmap(resource);
|
||||
} else {
|
||||
Bitmap bitmap = ThumbnailUtils.extractThumbnail(resource, width, height);
|
||||
imageView.setImageBitmap(bitmap);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadCleared(@Nullable Drawable placeholder) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void displayAvatar(Context context, int url, ImageView imageView) {
|
||||
@@ -95,14 +208,22 @@ public class ImgLoader {
|
||||
if (!contextIsExist(context)) {
|
||||
return;
|
||||
}
|
||||
Glide.with(context).asDrawable().load(file).skipMemoryCache(SKIP_MEMORY_CACHE).into(imageView);
|
||||
Glide.with(context)
|
||||
.asDrawable()
|
||||
.load(file)
|
||||
.skipMemoryCache(SKIP_MEMORY_CACHE)
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
public static void display(Context context, int res, ImageView imageView) {
|
||||
if (!contextIsExist(context)) {
|
||||
return;
|
||||
}
|
||||
Glide.with(context).asDrawable().load(res).skipMemoryCache(SKIP_MEMORY_CACHE).into(imageView);
|
||||
Glide.with(context)
|
||||
.asDrawable()
|
||||
.load(res)
|
||||
.skipMemoryCache(SKIP_MEMORY_CACHE)
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,7 +233,11 @@ public class ImgLoader {
|
||||
if (!contextIsExist(context)) {
|
||||
return;
|
||||
}
|
||||
Glide.with(context).asDrawable().load(Uri.fromFile(new File(videoPath))).skipMemoryCache(SKIP_MEMORY_CACHE).into(imageView);
|
||||
Glide.with(context)
|
||||
.asDrawable()
|
||||
.load(Uri.fromFile(new File(videoPath)))
|
||||
.skipMemoryCache(SKIP_MEMORY_CACHE)
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,7 +247,11 @@ public class ImgLoader {
|
||||
if (!contextIsExist(context)) {
|
||||
return;
|
||||
}
|
||||
Glide.with(context).asGif().load(videoPath).skipMemoryCache(SKIP_MEMORY_CACHE).into(imageView);
|
||||
Glide.with(context)
|
||||
.asGif()
|
||||
.load(videoPath)
|
||||
.skipMemoryCache(SKIP_MEMORY_CACHE)
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
public static void displayDrawable(Context context, String url, final DrawableCallback callback) {
|
||||
@@ -190,27 +319,67 @@ public class ImgLoader {
|
||||
* 显示模糊的毛玻璃图片
|
||||
*/
|
||||
public static void displayBlur(Context context, String url, ImageView imageView) {
|
||||
displayBlur(context, url, imageView, -1, -1);
|
||||
}
|
||||
|
||||
public static void displayBlur(Context context, String url, ImageView imageView, int width, int height) {
|
||||
if (!contextIsExist(context)) {
|
||||
return;
|
||||
}
|
||||
Glide.with(context).asDrawable().load(url)
|
||||
Glide.with(context)
|
||||
.asBitmap()
|
||||
.load(url)
|
||||
.skipMemoryCache(SKIP_MEMORY_CACHE)
|
||||
.apply(RequestOptions.bitmapTransform(sBlurTransformation))
|
||||
.into(imageView);
|
||||
.into(new CustomTarget<Bitmap>() {
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
|
||||
if (width == -1 || height == -1) {
|
||||
imageView.setImageBitmap(resource);
|
||||
} else {
|
||||
Bitmap bitmap = ThumbnailUtils.extractThumbnail(resource, width, height);
|
||||
imageView.setImageBitmap(bitmap);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadCleared(@Nullable Drawable placeholder) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示模糊的毛玻璃图片
|
||||
*/
|
||||
public static void displayBlurLive(Context context, String url, ImageView imageView) {
|
||||
displayBlurLive(context, url, imageView, -1, -1);
|
||||
}
|
||||
|
||||
public static void displayBlurLive(Context context, String url, ImageView imageView, int width, int height) {
|
||||
if (!contextIsExist(context)) {
|
||||
return;
|
||||
}
|
||||
Glide.with(context).asDrawable().load(url)
|
||||
Glide.with(context).asBitmap().load(url)
|
||||
.skipMemoryCache(SKIP_MEMORY_CACHE)
|
||||
.apply(RequestOptions.bitmapTransform(new BlurTransformation(100)))
|
||||
.apply(RequestOptions.bitmapTransform(new BlurTransformation(20)))
|
||||
.placeholder(R.mipmap.live_bg)
|
||||
.into(imageView);
|
||||
.into(new CustomTarget<Bitmap>() {
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
|
||||
if (width == -1 || height == -1) {
|
||||
imageView.setImageBitmap(resource);
|
||||
} else {
|
||||
Bitmap bitmap = ThumbnailUtils.extractThumbnail(resource, width, height);
|
||||
imageView.setImageBitmap(bitmap);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadCleared(@Nullable Drawable placeholder) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static boolean contextIsExist(Context context) {
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.yunbao.common.utils;
|
||||
|
||||
import com.opensource.svgaplayer.SVGACallback;
|
||||
import com.opensource.svgaplayer.SVGAImageView;
|
||||
|
||||
public class SVGAViewUtils {
|
||||
public static void playEndClear(SVGAImageView svga){
|
||||
svga.setCallback(new SVGACallback() {
|
||||
@Override
|
||||
public void onPause() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinished() {
|
||||
//动画结束后调用clear释放资源
|
||||
svga.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRepeat() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStep(int i, double v) {
|
||||
|
||||
}
|
||||
});
|
||||
svga.startAnimation();
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import android.widget.ImageView;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.ms.banner.holder.BannerViewHolder;
|
||||
import com.yunbao.common.bean.BannerBean;
|
||||
import com.yunbao.common.glide.ImgLoader;
|
||||
|
||||
public class CustomViewHolder implements BannerViewHolder<BannerBean> {
|
||||
|
||||
@@ -20,7 +21,8 @@ public class CustomViewHolder implements BannerViewHolder<BannerBean> {
|
||||
);
|
||||
imageView.setLayoutParams(params);
|
||||
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
|
||||
Glide.with(context).load(data.getImageUrl()).into(imageView);
|
||||
//Glide.with(context).load(data.getImageUrl()).into(imageView);
|
||||
ImgLoader.display(context,data.getImageUrl(),imageView,600,170);
|
||||
|
||||
return imageView;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user