Code Monkey home page Code Monkey logo

imageloaderframework's Introduction

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);

imageloaderframework's People

Contributors

ladingwu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.