Created
April 7, 2015 16:25
-
-
Save buneme/10ffb5ede0b4ad8b47db 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
public class MyApplication extends Application { | |
public static final String TAG = MyApplication.class.getSimpleName(); | |
private RequestQueue mRequestQueue; | |
private ImageLoader mImageLoader; | |
private static MyApplication mInstance; | |
@Override | |
public void onCreate() { | |
super.onCreate(); | |
mInstance = this; | |
// Example: single kit | |
TwitterAuthConfig authConfig = | |
new TwitterAuthConfig("0fN3MULoGe6tK7LIhpukKnVq4", | |
"8aiRxaPoxjIC1aaaibwG3ciL616QbYTx9eT0C7dGxit87lOIwn"); | |
// Example: multiple kits | |
Fabric.with(this, new Twitter(authConfig), | |
new MoPub()); | |
} | |
public static synchronized MyApplication getInstance() { | |
return mInstance; | |
} | |
public RequestQueue getRequestQueue() { | |
if (mRequestQueue == null) { | |
mRequestQueue = Volley.newRequestQueue(getApplicationContext()); | |
} | |
return mRequestQueue; | |
} | |
public ImageLoader getImageLoader() { | |
getRequestQueue(); | |
if (mImageLoader == null) { | |
mImageLoader = new ImageLoader(this.mRequestQueue, | |
new BitmapLruCache()); | |
} | |
return this.mImageLoader; | |
} | |
public <T> void addToRequestQueue(Request<T> req, String tag) { | |
// set the default tag if tag is empty | |
req.setTag(TextUtils.isEmpty(tag) ? TAG : tag); | |
getRequestQueue().add(req); | |
} | |
public <T> void addToRequestQueue(Request<T> req) { | |
req.setTag(TAG); | |
getRequestQueue().add(req); | |
} | |
public void cancelPendingRequests(Object tag) { | |
if (mRequestQueue != null) { | |
mRequestQueue.cancelAll(tag); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment