Created
October 8, 2014 16:49
-
-
Save vibin/6aac5ceda47c76463d95 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RequestQueue req; | |
ImageLoader.ImageCache imageCache; | |
ImageLoader imageLoader; | |
final int DEFAULT_CACHE_SIZE = 16 * 1024 * 1024; // for DiskBasedCache | |
private static final String DEFAULT_CACHE_DIR = "volley"; | |
private void createImageLoader() { | |
if (imageCache == null) { | |
imageCache = new BitmapLruCache(); | |
imageLoader = new ImageLoader(Volley.newRequestQueue(this), imageCache); | |
} | |
} | |
public ImageLoader getImageLoader() { | |
return imageLoader; | |
} | |
/** | |
* If RequestQueue is null, create one with {@code cacheSize} amount of cache | |
*/ | |
public RequestQueue getRequestQueue() { | |
if (req == null) { | |
req = Volley.newRequestQueue(this); | |
File cacheDir = new File(this.getCacheDir(), DEFAULT_CACHE_DIR); | |
DiskBasedCache cache = new DiskBasedCache(cacheDir, DEFAULT_CACHE_SIZE); | |
req = new RequestQueue(cache, new BasicNetwork(new HurlStack())); | |
req.start(); | |
} | |
return req; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment