Created
March 1, 2014 13:57
-
-
Save vjdhama/9290080 to your computer and use it in GitHub Desktop.
Volley Singleton
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
import android.content.Context; | |
import android.graphics.Bitmap; | |
import android.support.v4.util.LruCache; | |
import com.android.volley.RequestQueue; | |
import com.android.volley.toolbox.ImageLoader; | |
import com.android.volley.toolbox.Volley; | |
public class VolleyRequest { | |
private static VolleyRequest mInstance = null; | |
private RequestQueue mRequestQueue; | |
private ImageLoader mImageLoader; | |
private VolleyRequest(Context context){ | |
mRequestQueue = Volley.newRequestQueue(context); | |
mImageLoader = new ImageLoader(this.mRequestQueue, new ImageLoader.ImageCache() { | |
private final LruCache<String, Bitmap> mCache = new LruCache<String, Bitmap>(10); | |
public void putBitmap(String url, Bitmap bitmap) { | |
mCache.put(url, bitmap); | |
} | |
public Bitmap getBitmap(String url) { | |
return mCache.get(url); | |
} | |
}); | |
} | |
public static VolleyRequest getInstance(Context context){ | |
if(mInstance == null){ | |
mInstance = new VolleyRequest(context); | |
} | |
return mInstance; | |
} | |
public RequestQueue getRequestQueue(){ | |
return this.mRequestQueue; | |
} | |
public ImageLoader getImageLoader(){ | |
return this.mImageLoader; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment