Skip to content

Instantly share code, notes, and snippets.

@pwittchen
Last active December 21, 2015 18:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pwittchen/6347915 to your computer and use it in GitHub Desktop.
Save pwittchen/6347915 to your computer and use it in GitHub Desktop.
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