public class GlideUtils {
public static void load(Context context,
String url,
ImageView imageView,
RequestOptions options) {
if (isValidContextForGlide(context)) {
Glide.with(context)
.asBitmap()
.load(url)
.apply(options)
.into(imageView);
}
}
public static void loadGif(Context context,
String url,
ImageView imageView,
RequestOptions options) {
Glide.with(context)
.asGif()
.load(url)
.apply(options)
.into(imageView);
}
public static boolean isValidContextForGlide(final Context context) {
if (context == null) {
return false;
}
if (context instanceof Activity) {
final Activity activity = (Activity) context;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
if (activity.isDestroyed() || activity.isFinishing()) {
return false;
}
} else {
if (activity.isFinishing()) {
return false;
}
}
}
return true;
}
}
网友评论