Last active
December 21, 2015 18:29
-
-
Save pwittchen/6347915 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
package com.github.volley.example.toolbox; | |
import android.content.Context; | |
import com.android.volley.RequestQueue; | |
import com.android.volley.toolbox.ImageLoader; | |
import com.android.volley.toolbox.Volley; | |
import com.github.volley.example.toolbox.BitmapLruCache; | |
/** | |
* Helper class that is used to provide references to initialized RequestQueue(s) and ImageLoader(s) | |
*/ | |
public class VolleyHelper { | |
private static final int MAX_IMAGE_CACHE_ENTIRES = 100; | |
private static RequestQueue mRequestQueue; | |
private static ImageLoader mImageLoader; | |
private VolleyHelper() { | |
} | |
static void init(Context context) { | |
mRequestQueue = Volley.newRequestQueue(context); | |
mImageLoader = new ImageLoader(mRequestQueue, new BitmapLruCache(MAX_IMAGE_CACHE_ENTIRES)); | |
} | |
public static RequestQueue getRequestQueue() { | |
if (mRequestQueue != null) { | |
return mRequestQueue; | |
} else { | |
throw new IllegalStateException("RequestQueue not initialized"); | |
} | |
} | |
/** | |
* Returns instance of ImageLoader initialized with {@see FakeImageCache} which effectively means | |
* that no memory caching is used. This is useful for images that you know that will be show | |
* only once. | |
*/ | |
public static ImageLoader getImageLoader() { | |
if (mImageLoader != null) { | |
return mImageLoader; | |
} else { | |
throw new IllegalStateException("ImageLoader not initialized"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment