aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFicus Kirkpatrick <ficus@android.com>2013-05-22 03:36:27 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2013-05-22 03:36:28 +0000
commit4af455a438f7cd25a6064fadaa545be0c8fc1c73 (patch)
treedd2357afd32e7bc6fdd9e0477c9e47e854e8421d /src
parentcf14c3b3a10c82cc30d2008d30c09fcb9a4ed7a1 (diff)
parentf5bea0d0871b65cb63149f2f8d1231345b1a13f2 (diff)
downloadvolley-4af455a438f7cd25a6064fadaa545be0c8fc1c73.tar.gz
Merge "Allow custom HttpStack in Volley.newRequestQueue."
Diffstat (limited to 'src')
-rw-r--r--src/com/android/volley/toolbox/Volley.java28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/com/android/volley/toolbox/Volley.java b/src/com/android/volley/toolbox/Volley.java
index bba1153..1304045 100644
--- a/src/com/android/volley/toolbox/Volley.java
+++ b/src/com/android/volley/toolbox/Volley.java
@@ -36,9 +36,10 @@ public class Volley {
* Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it.
*
* @param context A {@link Context} to use for creating the cache dir.
+ * @param stack An {@link HttpStack} to use for the network, or null for default.
* @return A started {@link RequestQueue} instance.
*/
- public static RequestQueue newRequestQueue(Context context) {
+ public static RequestQueue newRequestQueue(Context context, HttpStack stack) {
File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);
String userAgent = "volley/0";
@@ -50,13 +51,14 @@ public class Volley {
} catch (NameNotFoundException e) {
}
- HttpStack stack;
- if (Build.VERSION.SDK_INT >= 9) {
- stack = new HurlStack();
- } else {
- // Prior to Gingerbread, HttpUrlConnection was unreliable.
- // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html
- stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent));
+ if (stack == null) {
+ if (Build.VERSION.SDK_INT >= 9) {
+ stack = new HurlStack();
+ } else {
+ // Prior to Gingerbread, HttpUrlConnection was unreliable.
+ // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html
+ stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent));
+ }
}
Network network = new BasicNetwork(stack);
@@ -66,4 +68,14 @@ public class Volley {
return queue;
}
+
+ /**
+ * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it.
+ *
+ * @param context A {@link Context} to use for creating the cache dir.
+ * @return A started {@link RequestQueue} instance.
+ */
+ public static RequestQueue newRequestQueue(Context context) {
+ return newRequestQueue(context, null);
+ }
}