Universal Imageloader code is not complicated. Focus on caching, thread pool tasks
The following are plotted with UML diagrams
The basic usage process is to initialize the configuration, set the options parameters, and finally dispaly submit the download
Public Static voidInitimageloader (Context context) {Imageloaderconfiguration.builder config =NewImageloaderconfiguration.builder (context); Config.threadpriority (thread.norm_priority-2); Config.denycacheimagemultiplesizesinmemory (); Config.diskcachefilenamegenerator (Newmd5filenamegenerator ()); Config.diskcachesize (50 * 1024 * 1024);//MiBConfig.tasksprocessingorder (QUEUEPROCESSINGTYPE.LIFO); Config.writedebuglogs ();//Initialize imageloader with configuration.imageloader.getinstance (). Init (Config.build ()); }
New Displayimageoptions.builder () . showimageonloading (r.drawable.ic_stub) . Showimageforemptyuri ( R.drawable.ic_empty) . Showimageonfail (R.drawable.ic_error) . Cacheinmemory (true) . Cacheondisk (True). Considerexifparams (true) . Bitmapconfig (Bitmap.Config.RGB_565) . Build ();
imageloader.getinstance (). DisplayImage (Image_urls[0], Holder.imageview, options,NewSimpleimageloadinglistener () {@Override Public voidonloadingstarted (String imageuri, view view) {} @Override Public voidonloadingfailed (String imageuri, view view, Failreason Failreason) { } @Override Public voidOnloadingcomplete (String imageuri, view view, Bitmap loadedimage) { } }, NewImageloadingprogresslistener () {@Override Public voidOnprogressupdate (String Imageuri, view view,intCurrentintTotal ) { } });
Imageloader is the entrance, and other classes include config and option. Imageloaderengine for engines, others including wrappers, network downloads and decoding
Disk caching and memory caching, including several classic algorithm implementations.
Imageloader callback There is no bitmap data provided just bitmap set to ImageView object directly
Bitmapprocessor can be handled via interface
Options =NewDisplayimageoptions.builder (). Preprocessor (preprocessor). Postprocessor (postprocessor);//before entering the cacheBitmapprocessor preprocessor =Newbitmapprocessor () {@Override PublicBitmap Process (Bitmap Bitmap) {return NULL; } }; //processed before showing to ImageViewBitmapprocessor postprocessor =Newbitmapprocessor () {@Override PublicBitmap Process (Bitmap Bitmap) {return NULL; } };
Android Open source project Universal Imageloader Source research project Framework