Android Universalimageloader Source Analysis

Source: Internet
Author: User

"" A single-instance mode with thread safety.

"" Thread-safe function notation

Asynchronous thread Download Library source code Analysis:

"" DisplayImage

 public void displayimage (string uri, imageaware imageaware,  displayimageoptions options,   imageloadinglistener listener,  Imageloadingprogresslistener progresslistener)  {  checkconfiguration ();   if   (imageaware == null)  {   throw new illegalargumentexception ( error_wrong_arguments);  }  if  (listener == null)  {    listener = emptylistener;  }  if  (options == null)  {    options = configuration.defaultDisplayImageOptions;  }  if  ( Textutils.isempty (URI))  {   engine.canceldisplaytaskfor (Imageaware);    Listener.onloadingstarted (Uri, imageaware.getwrappedview ());   if  ( Options.shouldshowimageforemptyuri ())  {    imageaware.Setimagedrawable (Options.getimageforemptyuri (configuration.resources));    } else {     imageaware.setimagedrawable (NULL);   }    Listener.onloadingcomplete (Uri, imageaware.getwrappedview (),  null);   return;   }  imagesize targetsize = imagesizeutils.definetargetsizeforview (ImageAware,  configuration.getmaximagesize ());  string memorycachekey =  Memorycacheutils.generatekey (uri, targetsize);   engine.preparedisplaytaskfor (imageAware,  Memorycachekey);   listener.onloadingstarted (Uri, imageaware.getwrappedview ());   Bitmap bmp = configuration.memorycache.get (Memorycachekey);  if  (bmp !=  null && !bmp.isrecycled ())  {   L.D (LOG_LOAD_IMAGE_FROM_MEMORY_ Cache, memorycachekey);   if  (Options.shouLdpostprocess ())  {    ImageLoadingInfo imageLoadingInfo = new  Imageloadinginfo (uri, imageaware, targetsize, memorycachekey,       options, listener, progresslistener, engine.getlockforuri (URI));     Processanddisplayimagetask displaytask = new processanddisplayimagetask (Engine, bmp,  imageloadinginfo,      definehandler (options));     if   (options.issyncloading ())  {     displaytask.run ();     } else {     engine.submit (Displaytask);    }    } else {    options.getdisplayer (). Display (Bmp, imageaware,  loadedfrom.memory_cache);     listener.onloadingcomplete (uri,  Imageaware.getwrappedview (),  bmp);    }  } else {   if  (Options.shouldshowimageonloading ())   {    imageaware.setimagedrawable (options.getimageonloading (configuration.resources));    } else if  (Options.isresetviewbeforeloading ())  {     Imageaware.setimagedrawable (null);    }   imageloadinginfo imageloadinginfo  = new imageloadinginfo (uri, imageaware, targetsize, memorycachekey,      options, listener, progresslistener, engine.getlockforuri (URI));    loadanddisplayimagetask displaytask = new loadanddisplayimagetask (engine,  Imageloadinginfo,     definehandler (options));   if  ( Options.issyncloading ())  {    displaytask.run ();    } else {     engine.submIt (displaytask);    }  } } 

"" LoadImage

public void LoadImage (String uri, ImageSize targetimagesize, displayimageoptions options, Imageloadinglistener Listener  , Imageloadingprogresslistener Progresslistener) {checkconfiguration ();  if (targetimagesize = = null) {targetimagesize = Configuration.getmaximagesize ();  } if (options = = null) {options = configuration.defaultdisplayimageoptions;  } nonviewaware Imageaware = new Nonviewaware (URI, Targetimagesize, Viewscaletype.crop); DisplayImage (URI, Imageaware, options, Listener, Progresslistener); }

"" Loadimagesync

Public Bitmap Loadimagesync (String uri, ImageSize targetimagesize, displayimageoptions options) {if (options = = null) {  options = configuration.defaultdisplayimageoptions;  } options = new Displayimageoptions.builder (). Clonefrom (Options). Syncloading (True). Build ();  Syncimageloadinglistener listener = new Syncimageloadinglistener ();  LoadImage (URI, targetimagesize, options, listener); return Listener.getloadedbitmap (); }

"" Thread pool Executorservice

Fdfdf

Android Universalimageloader Source Analysis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.