Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

打造统一的图片加载框架,融合Glide(4.x),Fresco,不侵入业务代码,一套API兼容两种加载库

Notifications You must be signed in to change notification settings

ladingwu/ImageLoaderFramework

Repository files navigation

ImageLoaderFramework

  • 打造统一的图片加载框架,融合Glide,Fresco,一套API兼容两种加载方式

  • 两个底层包Glide,Fresco可随时相互替换,而无需大幅修改业务代码

  • 图片加载模块作为手机常用的一个重要模块,我们需要保证对它有完全的控制力,以适应产品随时变化的需求,因此我们就需要整合自己的图片加载框架,将它和业务代码分离,不过分依赖哪一个包,保证必要时可以替换。

  • 具体如何打造统一加载框架请参考这两篇文章《封装并实现统一的图片加载架构》,《项目重构之路——Fresco非入侵式替换Glide

  • 使用方式:

  // 下面两个依赖包可选,根据需求二选一即可,
  compile 'com.ladingwu.library:fresco:0.0.9'
  compile 'com.ladingwu.library:glide:0.0.9'
  // 这个是必须的
 compile "com.ladingwu.library:imageloader-framework:0.0.9"
 
  • 初始化
 // 初始化代码需要在Application中完成。
 ImageLoaderConfig config = new ImageLoaderConfig.Builder(LoaderEnum.GLIDE,new GlideImageLocader())
 .maxMemory(40*1024*1024L) // 配置内存缓存,单位为Byte
 .build();
 ImageLoaderManager.getInstance().init(this,config);
 
  • 图片加载统一调用接口
 //该接口的具体实现Glide和Fresco各有不同
 showImage(@NonNull ImageLoaderOptions options);
 show() // 0.0.9版本之后新增的API
  • 使用范例:

0.0.9之后优化了调用方式 ,可一步完成图片加载(对老的API是兼容的):

 ImageLoader.createImageOptions(img2,url)
 .blurImage(true)
 .blurValue(35)
 .isCircle()
 .placeholder(R.mipmap.ic_launcher).build().show();

之前的API调用方式(新版本仍然可以用):

    // 加载圆角图片
 ImageLoaderOptions op=new ImageLoaderOptions.Builder(img1,url).imageRadiusDp(12).build();
 ImageLoaderManager.getInstance().showImage(op);
 
 
 ImageLoaderOptions options=new ImageLoaderOptions.Builder(img2,url)
                          .blurImage(true)  // 高斯模糊  
 .blurValue(35)  //高斯模糊程度
                          .isCircle()  // 圆图 
                           .placeholder(R.mipmap.ic_launcher)// 占位图
 .build(); 
 
    // 如果项目同时使用了Fresco和Glide,可以指定特定的加载框架加载图片                   
 ImageLoaderManager.getInstance().showImage(options, LoaderEnum.GLIDE); // 选择通过Glide加载图片
 
         

2018年11月28日 更新

  • 优化了图片加载的调用方式,通过链式API一气呵成
  • 增加了图片加载的实时加载进度回调(该功能还没经过非常详细的测试)

实时加载进度回调:

 
 // 0.0.9之后增加的新的API调用方式
 ImageLoader.createImageOptions(img1,url).setOnLoaderProgressCallback(new OnLoaderProgressCallback() {
 @Override
 public void onProgress(int progress) {
 Log.w("progress",""+progress);
 }
 }).imageRadiusDp(12).build().show();
// 老的API调用方式
ImageLoaderOptions op=new ImageLoaderOptions.Builder(img1,url).setOnLoaderProgressCallback(new OnLoaderProgressCallback() {
 @Override
 public void onProgress(int progress) {
 Log.w("progress",""+progress);
 }
 }).imageRadiusDp(12).build();
 ImageLoaderManager.getInstance().showImage(op);

2018年03月04日 更新

  • 添加了对Fresco内存缓存的配置功能(Glide暂时采用默认配置)。

2018年02月01日 更新

  • 添加了对于Glide4.x版本的支持
  • 添加了圆图,圆角,高斯模糊的支持,并且保证Glide和Fresco的效果大体相同

2017年8月12日 更新

  • 添加图片暂停加载和恢复功能,方便优化处理
 // 暂停加载
 void pause(Context context);
 // 恢复加载
 void resume(Context context);

About

打造统一的图片加载框架,融合Glide(4.x),Fresco,不侵入业务代码,一套API兼容两种加载库

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

AltStyle によって変換されたページ (->オリジナル) /