android - How To Use universal image loader offline caching? -
is possible catch offline using universal image loader? if possible, how use it? using configs? how set download directory manually?
out of memory erroron load huge images :
my codes :
displayimageoptions defaultoptions = new displayimageoptions.builder() .cacheondisc(true).cacheinmemory(true) .imagescaletype(imagescaletype.in_sample_int) .displayer(new fadeinbitmapdisplayer(300)).build(); imageloaderconfiguration config = new imageloaderconfiguration.builder(g.appconfigs.context) .defaultdisplayimageoptions(defaultoptions) .memorycacheextraoptions(480, 800) // default = device screen dimensions .diskcacheextraoptions(480, 800, null) .memorycache(new weakmemorycache()) .memorycache(new lrumemorycache(2 * 1024 * 1024)) .memorycachesize(2 * 1024 * 1024) .disccachesize(300 * 1024 * 1024) .build(); imageloader.getinstance().init(config); // end - universal image loader setup imageloader imageloader = imageloader.getinstance(); displayimageoptions options = new displayimageoptions.builder().cacheinmemory(true) .cacheondisc(true).resetviewbeforeloading(true) .showimageforemptyuri(r.drawable.no_pic) .showimageonfail(r.drawable.load_failed) .showimageonloading(r.drawable.img_thumb).build(); //download , display image url imageloader.displayimage(imgurl, img, options);
how resolve ?
you can use imageloaderconfiguration.builder
class customize disk caching. includes methods:
diskcacheextraoptions()
diskcachesize()
(in bytes).diskcachefilecount()
diskcachefilenamegenerator()
- and others.
or can use diskcache(diskcache)
provide custom class implementing offline caching.
from example in configuration section of wiki:
file cachedir = storageutils.getcachedirectory(context); imageloaderconfiguration config = new imageloaderconfiguration.builder(context) .memorycacheextraoptions(480, 800) // default = device screen dimensions .diskcacheextraoptions(480, 800, null) .taskexecutor(...) .taskexecutorforcachedimages(...) .threadpoolsize(3) // default .threadpriority(thread.norm_priority - 1) // default .tasksprocessingorder(queueprocessingtype.fifo) // default .denycacheimagemultiplesizesinmemory() .memorycache(new lrumemorycache(2 * 1024 * 1024)) .memorycachesize(2 * 1024 * 1024) .memorycachesizepercentage(13) // default .diskcache(new unlimiteddisccache(cachedir)) // default .diskcachesize(50 * 1024 * 1024) .diskcachefilecount(100) .diskcachefilenamegenerator(new hashcodefilenamegenerator()) // default .imagedownloader(new baseimagedownloader(context)) // default .imagedecoder(new baseimagedecoder()) // default .defaultdisplayimageoptions(displayimageoptions.createsimple()) // default .writedebuglogs() .build();
Comments
Post a Comment