import android.content.Context;
import android.text.TextUtils;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.youth.banner.loader.ImageLoader;
/**
* Created by leslie on 18/6/11.
*/
public class GlideImageLoader extends ImageLoader {
public static void showImage(String url, ImageView tarImg) {
Context context = ContextManager.getInstance().getApplication();
if (url != null && url.endsWith(".gif")) {
Glide.with(context).asGif().load(url).into(tarImg);
} else {
showImage(context, url, tarImg, -1);
}
}
public static void showImage(String url, ImageView tarImg, int redId) {//能处理服务器中的对gif图片处理后的
Context context = ContextManager.getInstance().getApplication();
tarImg.setBackgroundResource(redId);
if (url != null && url.contains(".gif")) {
url = url.substring(0, url.indexOf(".gif") + 4);
Glide.with(context).asGif().load(url).into(tarImg);
} else {
showImage(context, url, tarImg, redId);
}
}
public static void showImage(Context context, String url, ImageView tarImg) {
if (url != null && url.endsWith(".gif")) {
Glide.with(context).asGif().load(url).into(tarImg);
} else {
showImage(context, url, tarImg, -1);
}
}
public static void showImage(Context context, String url, ImageView tarImg, int redId) {
if (redId == -1) {
if (!TextUtils.isEmpty(url)) {
Glide.with(context).load(url).into(tarImg);
}
} else {
if (TextUtils.isEmpty(url)) {
tarImg.setBackgroundResource(redId);
} else {
RequestOptions options = new RequestOptions().error(redId);
Glide.with(context).load(url).apply(options).into(tarImg);
}
}
}
//用于banner框架加载图片
@Override
public void displayImage(Context context, Object path, ImageView imageView) {
if (path != null && !TextUtils.isEmpty(path.toString()))
Glide.with(context).load(path.toString()).into(imageView);
}
}