Imageloder for image loading and caching in Android development _android

Source: Internet
Author: User

Picture Processing class:

Package com.longfei.admin.imageloder_text;
Import android.app.Application;
Import Android.graphics.Bitmap;
 
Import android.os.Environment;
Import Com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache;
Import Com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
Import Com.nostra13.universalimageloader.cache.memory.impl.UsingFreqLimitedMemoryCache;
Import com.nostra13.universalimageloader.core.DisplayImageOptions;
Import Com.nostra13.universalimageloader.core.ImageLoader;
Import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
Import Com.nostra13.universalimageloader.core.assist.ImageScaleType;
Import Com.nostra13.universalimageloader.core.assist.QueueProcessingType;
Import Com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
Import Com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
 
Import Com.nostra13.universalimageloader.core.download.BaseImageDownloader;
 
Import Java.io.File; /** * Created by admin on 2016/4/9. */public class Imageloading extends application {@Override public void onCreate () {//TODO auto-generated Metho
    D stub super.oncreate (); imageloaderconfiguration config = new Imageloaderconfiguration.builder (this). Memorycacheextraoptions (480 /Max width, max height, that is, the maximum length of each cached file saved. disccacheextraoptions (i, A, null)
            Can slow imageloader, use it carefully (Better don ' t use//IT)/set cache details, preferably not set this. ThreadPoolSize (3)
        Number of lines Cheng Chinega loaded. ThreadPriority (thread.norm_priority-2). Denycacheimagemultiplesizesinmemory ()
            . MemoryCache (New Usingfreqlimitedmemorycache (2 * 1024 * 1024))//You can pass your own memory cache implementation/you can implement it through your own memory cache. Memorycachesize (2 * 1024 * 1024). Disccachesize (50 * 1024 * 1 024). Disccachefilenamegenerator (New Md5filenamegenerator ())//when will be savedThe URI name you designate is encrypted with MD5. Tasksprocessingorder (Queueprocessingtype.lifo). Disccachefilecount (100)//Cached Number of files. Disccache (new Unlimiteddisccache (environment. Getexternalstoragedirect Ory () + "/myapp/imgcache"))//Custom cache path. Defaultdisplayimageoptions (Getdisplayoptions ( ). Imagedownloader (New Baseimagedownloader (this, 5 * 1000, * 1000)). Writedebuglogs ()//
  Start building Imageloader.getinstance (). init (config) with the Remove for release app. build ();
    Private Displayimageoptions getdisplayoptions () {displayimageoptions options;
        options = new Displayimageoptions.builder (). showimageonloading (R.drawable.ic_launcher)//Set picture displayed during download  . Showimageforemptyuri (R.drawable.ic_launcher)//sets the picture that appears when the picture URI is empty or wrong. Showimageonfail (R.drawable.ic_launcher)// Sets the picture to be displayed when the picture is loaded/decoded during the error. Cacheinmemory (TRUE)/sets whether the downloaded picture is slow to exist in memory. CACHeondisc (TRUE)/set whether the downloaded picture is slow to exist in the SD card. Considerexifparams (TRUE)/whether to consider the JPEG image exif parameter (rotate, flip). Imagescaletype (Ima gescaletype.exactly_stretched)//sets how the picture is displayed in the encoded manner. Bitmapconfig (Bitmap.Config.RGB_565)//Set the decoding type of the picture//// 
            . delaybeforeloading (int delayinmillis)//int//Delayinmillis set up before downloading the delay time/set picture before adding the cache to the bitmap
        . Preprocessor (Bitmapprocessor preprocessor). Resetviewbeforeloading (TRUE)//Set whether the picture is reset before downloading, reset . Displayer (New Roundedbitmapdisplayer (20))//is set to rounded, radian is how much. Displayer (new Fadeinbitmapdisplayer (100))/whether the picture is loaded well
  The animation time of the Fade. Build ();//construct complete return options;
 
}} package Com.longfei.admin.imageloder_text;
Import android.app.Activity;
Import Android.graphics.Bitmap;
Import Android.os.Bundle;
Import Android.util.Log;
Import Android.view.View;
 
Import Android.widget.ImageView;
Import Com.nostra13.universalimageloader.core.ImageLoader; Import Com.nostra13.universalimageloader.core.assiSt.
Failreason;
 
 
 
Import Com.nostra13.universalimageloader.core.listener.ImageLoadingListener; /** * 1, universal-imageloader configuration * * 2, with universal-imageloader load network pictures and local pictures * * @author Administrator/Public cl
  Ass Mainactivity extends Activity {private Imageloader loader;
 
  Private ImageView iv_img;
    @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
 
    Setcontentview (R.layout.activity_main);
 
    Loader=imageloader.getinstance (),//instantiated Imageloder iv_img= (ImageView) Findviewbyid (r.id.iv_img);
 
    String url= "file:///" + "load local picture";
 
    Load network picture, the first parameter is path//Loader.displayimage ("yun_qi_img/logo.gif?t=1419303093000", iv_img); Loader.displayimage ("yun_qi_img/logo.gif?t=1419303093000", Iv_img, New Imageloadinglistener () {@Override Publ
 
      IC void onloadingstarted (String s, view view) {log.i ("info", "load Start"); @Override public void onloadingfailed (String s, view view, FAILREason Failreason) {log.i ("info", "Load Failed"); @Override public void Onloadingcomplete (String s, view view, Bitmap Bitmap) {log.i ("info", "loaded")
 
      ;
 
      @Override public void onloadingcancelled (String s, view view) {log.i ("info", "load cancellation");
  }
    });
 }
}

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.