|
|
@@ -37,23 +37,35 @@ import rx.functions.Action1;
|
|
|
public class GlideImageLoader {
|
|
|
|
|
|
public static void setBlur(ImageView imageView, Object url) {
|
|
|
+ if(imageView == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
Glide.with(SheepApp.getInstance())
|
|
|
.load(url)
|
|
|
.apply(new RequestOptions().transform(new BlurTransformation()))
|
|
|
.into(imageView);
|
|
|
}
|
|
|
public static void setImage(ImageView imageView, Object url) {
|
|
|
+ if(imageView == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
Glide.with(SheepApp.getInstance())
|
|
|
.load(url)
|
|
|
.into(imageView);
|
|
|
}
|
|
|
public static void setImage(ImageView imageView, Object url, int id) {
|
|
|
+ if(imageView == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
Glide.with(SheepApp.getInstance())
|
|
|
.load(url)
|
|
|
.apply(new RequestOptions().placeholder(id))
|
|
|
.into(imageView);
|
|
|
}
|
|
|
public static void setImageDisHardConfig(ImageView imageView, Object url) {
|
|
|
+ if(imageView == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
Glide.with(SheepApp.getInstance())
|
|
|
.load(url)
|
|
|
.apply(new RequestOptions().disallowHardwareConfig())
|
|
|
@@ -61,6 +73,9 @@ public class GlideImageLoader {
|
|
|
}
|
|
|
|
|
|
public static void centerImage(ImageView imageView, Object url, int id) {
|
|
|
+ if(imageView == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
Glide.with(SheepApp.getInstance())
|
|
|
.load(url)
|
|
|
.apply(new RequestOptions().centerCrop().placeholder(id))
|
|
|
@@ -68,6 +83,9 @@ public class GlideImageLoader {
|
|
|
}
|
|
|
|
|
|
public static void centerImage(ImageView imageView, Object path) {
|
|
|
+ if(imageView == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
Glide.with(SheepApp.getInstance())
|
|
|
.load(path)
|
|
|
.apply(new RequestOptions().centerCrop().placeholder(R.drawable.loading_01))
|
|
|
@@ -75,6 +93,9 @@ public class GlideImageLoader {
|
|
|
}
|
|
|
|
|
|
public static void circleImage(ImageView imageView, Object url, int id) {
|
|
|
+ if(imageView == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
Glide.with(SheepApp.getInstance())
|
|
|
.load(url)
|
|
|
.apply(new RequestOptions().circleCrop().placeholder(id))
|
|
|
@@ -82,6 +103,9 @@ public class GlideImageLoader {
|
|
|
}
|
|
|
|
|
|
public static void circleImage(ImageView imageView, Object url) {
|
|
|
+ if(imageView == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
Glide.with(SheepApp.getInstance())
|
|
|
.load(url)
|
|
|
.apply(new RequestOptions().circleCrop().placeholder(R.drawable.loading_01))
|
|
|
@@ -89,6 +113,9 @@ public class GlideImageLoader {
|
|
|
}
|
|
|
|
|
|
public static void roundedCornersImage(ImageView imageView, Object url, int radius, int id) {
|
|
|
+ if(imageView == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
Glide.with(SheepApp.getInstance())
|
|
|
.load(url)
|
|
|
.apply(new RequestOptions().transform(new RoundedCornersTransformation(radius, 0)).placeholder(id))
|
|
|
@@ -96,18 +123,27 @@ public class GlideImageLoader {
|
|
|
}
|
|
|
|
|
|
public static void roundedCornersImage(ImageView imageView, Object url, int radius) {
|
|
|
+ if(imageView == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
Glide.with(SheepApp.getInstance())
|
|
|
.load(url)
|
|
|
.apply(new RequestOptions().transform(new RoundedCornersTransformation(radius, 0)).placeholder(R.drawable.loading_01))
|
|
|
.into(imageView);
|
|
|
}
|
|
|
public static void roundedCornersImage1(ImageView imageView, Object url, int radius) {
|
|
|
+ if(imageView == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
Glide.with(SheepApp.getInstance())
|
|
|
.load(url)
|
|
|
.apply(new RequestOptions().centerCrop().transform(new RoundedCorners(radius)))
|
|
|
.into(imageView);
|
|
|
}
|
|
|
public static void setGameImage(ImageView imageView, String url) {
|
|
|
+ if(imageView == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
if(url.endsWith(".gif")){//gif图片不做任务处理
|
|
|
Glide.with(SheepApp.getInstance())
|
|
|
.load(url)
|
|
|
@@ -121,6 +157,9 @@ public class GlideImageLoader {
|
|
|
}
|
|
|
}
|
|
|
public static void setGameImage(ImageView imageView, String url, int radius) {
|
|
|
+ if(imageView == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
Glide.with(SheepApp.getInstance())
|
|
|
.load(url)
|
|
|
.apply(new RequestOptions().centerCrop().transform(new RoundedCorners(radius)).placeholder(R.drawable.loading_01))
|
|
|
@@ -176,23 +215,20 @@ public class GlideImageLoader {
|
|
|
|
|
|
|
|
|
public static void downloadAndSetImage(final ImageView imageView, final String link, final int w) {
|
|
|
- downLoadImage(String.format(Locale.CHINA, "%d", link.hashCode()), link, new Action1<File>() {
|
|
|
- @Override
|
|
|
- public void call(File file) {
|
|
|
- if(imageView != null) {
|
|
|
- if (file == null)
|
|
|
- Glide.with(SheepApp.getInstance())
|
|
|
- .load(link)
|
|
|
- .apply(new RequestOptions().override(w, w))
|
|
|
- .into(imageView);
|
|
|
- else
|
|
|
- Glide.with(SheepApp.getInstance())
|
|
|
- .load(file)
|
|
|
- .apply(new RequestOptions().override(w, w))
|
|
|
- .into(imageView);
|
|
|
- }
|
|
|
-
|
|
|
+ downLoadImage(String.format(Locale.CHINA, "%d", link.hashCode()), link, file -> {
|
|
|
+ if(imageView != null) {
|
|
|
+ if (file == null)
|
|
|
+ Glide.with(SheepApp.getInstance())
|
|
|
+ .load(link)
|
|
|
+ .apply(new RequestOptions().override(w, w))
|
|
|
+ .into(imageView);
|
|
|
+ else
|
|
|
+ Glide.with(SheepApp.getInstance())
|
|
|
+ .load(file)
|
|
|
+ .apply(new RequestOptions().override(w, w))
|
|
|
+ .into(imageView);
|
|
|
}
|
|
|
+
|
|
|
});
|
|
|
|
|
|
}
|
|
|
@@ -230,46 +266,52 @@ public class GlideImageLoader {
|
|
|
|
|
|
/**
|
|
|
* 设置头像
|
|
|
- * @param iconImgIv
|
|
|
+ * @param imageView
|
|
|
* @param avatar
|
|
|
*/
|
|
|
- public static void setAvatar(ImageView iconImgIv, String avatar) {
|
|
|
+ public static void setAvatar(ImageView imageView, String avatar) {
|
|
|
+ if(imageView == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
if(TextUtils.isEmpty(avatar)){
|
|
|
Glide.with(SheepApp.getInstance())
|
|
|
.load(R.drawable.avatar)
|
|
|
- .into(iconImgIv);
|
|
|
+ .into(imageView);
|
|
|
} else {
|
|
|
Glide.with(SheepApp.getInstance())
|
|
|
.load(avatar)
|
|
|
.apply(new RequestOptions().circleCrop().placeholder(R.drawable.avatar))
|
|
|
- .into(iconImgIv);
|
|
|
+ .into(imageView);
|
|
|
}
|
|
|
}
|
|
|
/**
|
|
|
* 设置头像有外面的圆环
|
|
|
- * @param iconImgIv
|
|
|
+ * @param imageView
|
|
|
* @param avatar
|
|
|
*/
|
|
|
- public static void setAvatar(ImageView iconImgIv, String avatar, int color) {
|
|
|
- Object tag = iconImgIv.getTag(R.drawable.avatar);
|
|
|
+ public static void setAvatar(ImageView imageView, String avatar, int color) {
|
|
|
+ if(imageView == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Object tag = imageView.getTag(R.drawable.avatar);
|
|
|
if(TextUtils.isEmpty(avatar)){
|
|
|
if(tag instanceof String && tag.toString().isEmpty()){//防止重复加载
|
|
|
return;
|
|
|
}
|
|
|
- iconImgIv.setTag(R.drawable.avatar, "");
|
|
|
+ imageView.setTag(R.drawable.avatar, "");
|
|
|
Glide.with(SheepApp.getInstance())
|
|
|
.load(R.drawable.avatar)
|
|
|
- .apply(new RequestOptions().override(iconImgIv.getMeasuredWidth()).transform(new GlideCircleTransformWithBorder(color)))
|
|
|
- .into(iconImgIv);
|
|
|
+ .apply(new RequestOptions().override(imageView.getMeasuredWidth()).transform(new GlideCircleTransformWithBorder(color)))
|
|
|
+ .into(imageView);
|
|
|
} else {
|
|
|
if(tag instanceof String && tag.toString().equals(avatar)){//防止重复加载
|
|
|
return;
|
|
|
}
|
|
|
- iconImgIv.setTag(R.drawable.avatar, avatar);
|
|
|
+ imageView.setTag(R.drawable.avatar, avatar);
|
|
|
Glide.with(SheepApp.getInstance())
|
|
|
.load(avatar)
|
|
|
.apply(new RequestOptions().transform(new GlideCircleTransformWithBorder(color)).placeholder(R.drawable.avatar))
|
|
|
- .into(iconImgIv);
|
|
|
+ .into(imageView);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -282,26 +324,26 @@ public class GlideImageLoader {
|
|
|
* @param radius
|
|
|
*/
|
|
|
public static void downloadAndRoundedImage(String name, final String link, final ImageView imageView, final int width, final int radius) {
|
|
|
- GlideImageLoader.downLoadImage(name, link, new Action1<File>() {
|
|
|
- @Override
|
|
|
- public void call(File file) {
|
|
|
- if(file == null){
|
|
|
- return;
|
|
|
- }
|
|
|
- BitmapFactory.Options options = FileUtil.getImageOptions(file);
|
|
|
- int w = options.outWidth;
|
|
|
- int h = options.outHeight;
|
|
|
+ if(imageView == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ GlideImageLoader.downLoadImage(name, link, file -> {
|
|
|
+ if(file == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ BitmapFactory.Options options = FileUtil.getImageOptions(file);
|
|
|
+ int w = options.outWidth;
|
|
|
+ int h = options.outHeight;
|
|
|
// int w = width;
|
|
|
// int h = width * options.outHeight / options.outWidth;
|
|
|
- if(Math.abs(w-h) < Math.min(w, h)){
|
|
|
- setImage(imageView, link);
|
|
|
- return;
|
|
|
- }
|
|
|
- Glide.with(SheepApp.getInstance())
|
|
|
- .load(file)
|
|
|
- .apply(new RequestOptions().override(w, h).fitCenter().transform(new RoundedCorners(radius)))
|
|
|
- .into(imageView);
|
|
|
+ if(Math.abs(w-h) < Math.min(w, h)){
|
|
|
+ setImage(imageView, link);
|
|
|
+ return;
|
|
|
}
|
|
|
+ Glide.with(SheepApp.getInstance())
|
|
|
+ .load(file)
|
|
|
+ .apply(new RequestOptions().override(w, h).fitCenter().transform(new RoundedCorners(radius)))
|
|
|
+ .into(imageView);
|
|
|
});
|
|
|
}
|
|
|
/**
|
|
|
@@ -312,23 +354,23 @@ public class GlideImageLoader {
|
|
|
* @param radius
|
|
|
*/
|
|
|
public static void downloadAndRoundedImage(String name, String link, final ImageView imageView, final int radius, final RequestListener<Drawable> listener) {
|
|
|
- GlideImageLoader.downLoadImage(name, link, new Action1<File>() {
|
|
|
- @Override
|
|
|
- public void call(File file) {
|
|
|
- if(file == null){
|
|
|
- return;
|
|
|
- }
|
|
|
- BitmapFactory.Options options = FileUtil.getImageOptions(file);
|
|
|
- int w = options.outWidth;
|
|
|
- int h = options.outHeight;
|
|
|
+ if(imageView == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ GlideImageLoader.downLoadImage(name, link, file -> {
|
|
|
+ if(file == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ BitmapFactory.Options options = FileUtil.getImageOptions(file);
|
|
|
+ int w = options.outWidth;
|
|
|
+ int h = options.outHeight;
|
|
|
// int w = width;
|
|
|
// int h = width * options.outHeight / options.outWidth;
|
|
|
- Glide.with(SheepApp.getInstance())
|
|
|
- .load(file)
|
|
|
- .listener(listener)
|
|
|
- .apply(new RequestOptions().override(w, h).transform(new RoundedCorners(radius)))
|
|
|
- .into(imageView);
|
|
|
- }
|
|
|
+ Glide.with(SheepApp.getInstance())
|
|
|
+ .load(file)
|
|
|
+ .listener(listener)
|
|
|
+ .apply(new RequestOptions().override(w, h).transform(new RoundedCorners(radius)))
|
|
|
+ .into(imageView);
|
|
|
});
|
|
|
}
|
|
|
}
|