开源图片加载框架二次封装(Glide为例)
此DEMO为Glide图片框架二次封装,为了实现项目中更简单的更新替换图片加载框架
1、使用okhttp请求图片
2、图片加载进度显示
3、查看大图以及保存图片到相册
dependencies {
compile project(':imageloadlib')
}
如果需要对图片进行修剪处理请加上如下两个库
//裁剪库
compile 'jp.wasabeef:glide-transformations:3.0.1'
// If you want to use the GPU Filters
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.4.1'
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
#glide imageload start
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.AppGlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
**[] $VALUES;
public *;
}
-dontwarn com.bumptech.glide.load.resource.bitmap.VideoDecoder
# for DexGuard only
-keepresourcexmlelements manifest/application/meta-data@value=GlideModule
#glide imageload end
ImageLoaderOptions options = new ImageLoaderOptions.Builder()
.errorId(R.mipmap.ic_launcher)
.placeholderId(R.mipmap.ic_launcher)
.diskCacheStrategy(ImageLoaderOptions.DiskCache.SOURCE)
.animator(android.R.anim.slide_in_left)
.isFitCenter(true)
.transform(new GlideRotateTransformation(getActivity(), 60))
.skipMemoryCache(false)
.build();
ImageLoader.getInstance().showImage(context, path, imageView, options);
maven { url 'https://maven.google.com' }
ImgLoadUtil.setTagId();
<meta-data
android:name="com.zony.imageloadlib.CustomGlideModule"
android:value="GlideModule" />
遇到该错误 报错原因大致是因为Glide加载的iamgeView调用了setTag()方法导致的错误,因为Glide已经默认为ImageView设置的Tag 相关解决方案已经在Glide 3.6.0(issue #370)被引进,实测可行
<application
android:name=".App">
public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
ViewTarget.setTagId(R.id.glide_tag);
}
}
<resources>
<item type="id" name="glide_tag" />
</resources>