com.android.volley.RequestQueue Java Examples
The following examples show how to use
com.android.volley.RequestQueue.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ImageLoaderTest.java From product-emm with Apache License 2.0 | 6 votes |
@Test public void publicMethods() throws Exception { // Catch API breaking changes. ImageLoader.getImageListener(null, -1, -1); mImageLoader.setBatchedResponseDelay(1000); assertNotNull(ImageLoader.class.getConstructor(RequestQueue.class, ImageLoader.ImageCache.class)); assertNotNull(ImageLoader.class.getMethod("getImageListener", ImageView.class, int.class, int.class)); assertNotNull(ImageLoader.class.getMethod("isCached", String.class, int.class, int.class)); assertNotNull(ImageLoader.class.getMethod("isCached", String.class, int.class, int.class, ImageView.ScaleType.class)); assertNotNull(ImageLoader.class.getMethod("get", String.class, ImageLoader.ImageListener.class)); assertNotNull(ImageLoader.class.getMethod("get", String.class, ImageLoader.ImageListener.class, int.class, int.class)); assertNotNull(ImageLoader.class.getMethod("get", String.class, ImageLoader.ImageListener.class, int.class, int.class, ImageView.ScaleType.class)); assertNotNull(ImageLoader.class.getMethod("setBatchedResponseDelay", int.class)); assertNotNull(ImageLoader.ImageListener.class.getMethod("onResponse", ImageLoader.ImageContainer.class, boolean.class)); }
Example #2
Source File: ImageLoaderTest.java From device-database with Apache License 2.0 | 6 votes |
@Test public void publicMethods() throws Exception { // Catch API breaking changes. ImageLoader.getImageListener(null, -1, -1); mImageLoader.setBatchedResponseDelay(1000); assertNotNull(ImageLoader.class.getConstructor(RequestQueue.class, ImageLoader.ImageCache.class)); assertNotNull(ImageLoader.class.getMethod("getImageListener", ImageView.class, int.class, int.class)); assertNotNull(ImageLoader.class.getMethod("isCached", String.class, int.class, int.class)); assertNotNull(ImageLoader.class.getMethod("isCached", String.class, int.class, int.class, ImageView.ScaleType.class)); assertNotNull(ImageLoader.class.getMethod("get", String.class, ImageLoader.ImageListener.class)); assertNotNull(ImageLoader.class.getMethod("get", String.class, ImageLoader.ImageListener.class, int.class, int.class)); assertNotNull(ImageLoader.class.getMethod("get", String.class, ImageLoader.ImageListener.class, int.class, int.class, ImageView.ScaleType.class)); assertNotNull(ImageLoader.class.getMethod("setBatchedResponseDelay", int.class)); assertNotNull(ImageLoader.ImageListener.class.getMethod("onResponse", ImageLoader.ImageContainer.class, boolean.class)); }
Example #3
Source File: RVNetwork.java From RestVolley with Apache License 2.0 | 6 votes |
static RequestQueue getRequestQueue(Request<?> request) { Field[] fields = request.getClass().getSuperclass().getDeclaredFields(); if (fields != null) { for (Field f : fields) { if (f.getType() == RequestQueue.class) { f.setAccessible(true); try { return (RequestQueue)(f.get(request)); } catch (IllegalAccessException e) { e.printStackTrace(); } } } } return null; }
Example #4
Source File: HaikuClient.java From gplus-haiku-client-android with Apache License 2.0 | 6 votes |
/** * End the user session with the server. * * @param listener and object to call when the request is complete. */ public void signOut(final HaikuServiceListener listener) { RequestQueue rq = mVolley.getRequestQueue(); HaikuApiRequest<Object> signoutPost = new HaikuApiRequest<Object>( (new TypeToken<Object>() { }), Request.Method.POST, Constants.SERVER_URL + USER_SIGNOUT, new Response.Listener<Object>() { @Override public void onResponse(Object data) { listener.onSignedOut(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError volleyError) { listener.onSignedOut(); } }, false ); signoutPost.setTag(USER_SIGNOUT); signoutPost.setSession(mHaikuSession); rq.add(signoutPost); }
Example #5
Source File: ImageLoaderTest.java From product-emm with Apache License 2.0 | 6 votes |
@Test public void publicMethods() throws Exception { // Catch API breaking changes. ImageLoader.getImageListener(null, -1, -1); mImageLoader.setBatchedResponseDelay(1000); assertNotNull(ImageLoader.class.getConstructor(RequestQueue.class, ImageLoader.ImageCache.class)); assertNotNull(ImageLoader.class.getMethod("getImageListener", ImageView.class, int.class, int.class)); assertNotNull(ImageLoader.class.getMethod("isCached", String.class, int.class, int.class)); assertNotNull(ImageLoader.class.getMethod("isCached", String.class, int.class, int.class, ImageView.ScaleType.class)); assertNotNull(ImageLoader.class.getMethod("get", String.class, ImageLoader.ImageListener.class)); assertNotNull(ImageLoader.class.getMethod("get", String.class, ImageLoader.ImageListener.class, int.class, int.class)); assertNotNull(ImageLoader.class.getMethod("get", String.class, ImageLoader.ImageListener.class, int.class, int.class, ImageView.ScaleType.class)); assertNotNull(ImageLoader.class.getMethod("setBatchedResponseDelay", int.class)); assertNotNull(ImageLoader.ImageListener.class.getMethod("onResponse", ImageLoader.ImageContainer.class, boolean.class)); }
Example #6
Source File: WeatherProxy.java From MaterialCalendar with Apache License 2.0 | 6 votes |
public static void fetchWeatherContent(String dateParam) { StringRequest stringRequest = new StringRequest(Method.GET, WE, new Response.Listener<String>() { @Override public void onResponse(String response) { try { Logger.json(response); JSONObject result = new JSONObject(response); insertWeather(result); } catch (JSONException e) { Logger.d(e.getMessage()); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { /* TODO Auto-generated method stub */ } }); RequestQueue requestQueue = RQManager.getInstance().getRequestQueue(); requestQueue.add(stringRequest); requestQueue.start(); }
Example #7
Source File: MainActivity.java From codeexamples-android with Eclipse Public License 1.0 | 6 votes |
public void onClick(View view) { final TextView mTextView = (TextView) findViewById(R.id.result); // Instantiate the RequestQueue. RequestQueue queue = Volley.newRequestQueue(this); String url = "http://www.vogella.com"; // Request a string response from the provided URL. StringRequest stringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() { @Override public void onResponse(String response) { mTextView.setText("Response is: " + response.substring(0, 500)); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { mTextView.setText("That didn't work!"); } }); // Add the request to the RequestQueue. queue.add(stringRequest); }
Example #8
Source File: Act_GsonRequest.java From android_volley_examples with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.act__gson_request); mTvResult = (TextView) findViewById(R.id.tv_result); Button btnSimpleRequest = (Button) findViewById(R.id.btn_gson_request); btnSimpleRequest.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { RequestQueue queue = MyVolley.getRequestQueue(); GsonRequest<MyClass> myReq = new GsonRequest<MyClass>(Method.GET, "http://validate.jsontest.com/?json={'key':'value'}", MyClass.class, createMyReqSuccessListener(), createMyReqErrorListener()); queue.add(myReq); } }); }
Example #9
Source File: Act_NetworkListView.java From android_volley_examples with Apache License 2.0 | 6 votes |
private void loadPage() { RequestQueue queue = MyVolley.getRequestQueue(); int startIndex = 1 + mEntries.size(); JsonObjectRequest myReq = new JsonObjectRequest(Method.GET, "https://picasaweb.google.com/data/feed/api/all?q=kitten&max-results=" + RESULTS_PAGE_SIZE + "&thumbsize=160&alt=json" + "&start-index=" + startIndex, null, createMyReqSuccessListener(), createMyReqErrorListener()); queue.add(myReq); }
Example #10
Source File: Act_SimpleRequest.java From android_volley_examples with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.act__simple_request); mTvResult = (TextView) findViewById(R.id.tv_result); Button btnSimpleRequest = (Button) findViewById(R.id.btn_simple_request); btnSimpleRequest.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { RequestQueue queue = MyVolley.getRequestQueue(); StringRequest myReq = new StringRequest(Method.GET, "http://www.google.com/", createMyReqSuccessListener(), createMyReqErrorListener()); queue.add(myReq); } }); }
Example #11
Source File: ImageLoaderTest.java From CrossBow with Apache License 2.0 | 6 votes |
@Test public void publicMethods() throws Exception { // Catch API breaking changes. ImageLoader.getImageListener(null, -1, -1); mImageLoader.setBatchedResponseDelay(1000); assertNotNull(ImageLoader.class.getConstructor(RequestQueue.class, ImageLoader.ImageCache.class)); assertNotNull(ImageLoader.class.getMethod("getImageListener", ImageView.class, int.class, int.class)); assertNotNull(ImageLoader.class.getMethod("isCached", String.class, int.class, int.class)); assertNotNull(ImageLoader.class.getMethod("isCached", String.class, int.class, int.class, ImageView.ScaleType.class)); assertNotNull(ImageLoader.class.getMethod("get", String.class, ImageLoader.ImageListener.class)); assertNotNull(ImageLoader.class.getMethod("get", String.class, ImageLoader.ImageListener.class, int.class, int.class)); assertNotNull(ImageLoader.class.getMethod("get", String.class, ImageLoader.ImageListener.class, int.class, int.class, ImageView.ScaleType.class)); assertNotNull(ImageLoader.class.getMethod("setBatchedResponseDelay", int.class)); assertNotNull(ImageLoader.ImageListener.class.getMethod("onResponse", ImageLoader.ImageContainer.class, boolean.class)); }
Example #12
Source File: VolleySingleton.java From LuxVilla with Apache License 2.0 | 5 votes |
public RequestQueue getRequestQueue() { if (mrequestQueue == null) { mrequestQueue = Volley.newRequestQueue(mContext.getApplicationContext()); } return mrequestQueue; }
Example #13
Source File: VolleyImageNetworkHandler.java From wasp with Apache License 2.0 | 5 votes |
@Override public void cancelRequest(final String tag) { Logger.w("CANCEL REQUEST -> url : " + tag); RequestQueue.RequestFilter filter = new RequestQueue.RequestFilter() { @Override public boolean apply(Request<?> request) { return tag.equals(request.getTag()); } }; requestQueue.cancelAll(filter); }
Example #14
Source File: VolleyUtil.java From android-open-project-demo with Apache License 2.0 | 5 votes |
/** 返回RequestQueue单例 **/ public static RequestQueue getQueue(Context context) { if (requestQueue == null) { synchronized (VolleyUtil.class) { if (requestQueue == null) { requestQueue = Volley.newRequestQueue(context.getApplicationContext()); } } } return requestQueue; }
Example #15
Source File: VolleyIdlingResource.java From soas with Apache License 2.0 | 5 votes |
public VolleyIdlingResource(Activity activity, String resourceName) throws SecurityException, NoSuchFieldException { mResourceName = Preconditions.checkNotNull(resourceName); mVolleyRequestQueue = SoasApplication.getRequestQueue(activity); mCurrentRequests = RequestQueue.class.getDeclaredField("mCurrentRequests"); mCurrentRequests.setAccessible(true); }
Example #16
Source File: SyncAdapter.java From attendee-checkin with Apache License 2.0 | 5 votes |
private void syncEvents(ContentProviderClient provider, String cookie) { try { RequestQueue requestQueue = GutenbergApplication.from(getContext()).getRequestQueue(); JSONArray events = getEvents(requestQueue, cookie); Pair<String[], ContentValues[]> pair = parseEvents(events); String[] eventIds = pair.first; provider.bulkInsert(Table.EVENT.getBaseUri(), pair.second); ArrayList<ContentProviderOperation> operations = new ArrayList<>(); operations.add(ContentProviderOperation.newDelete(Table.EVENT.getBaseUri()) .withSelection(Table.Event.ID + " NOT IN ('" + TextUtils.join("', '", eventIds) + "')", null) .build()); operations.add(ContentProviderOperation.newDelete(Table.ATTENDEE.getBaseUri()) .withSelection(Table.Attendee.EVENT_ID + " NOT IN ('" + TextUtils.join("', '", eventIds) + "')", null) .build()); provider.applyBatch(operations); for (String eventId : eventIds) { JSONArray attendees = getAttendees(requestQueue, eventId, cookie); provider.bulkInsert( Table.ATTENDEE.getBaseUri(), parseAttendees(eventId, attendees)); } Log.d(TAG, eventIds.length + " event(s) synced."); } catch (ExecutionException | InterruptedException | JSONException | RemoteException | OperationApplicationException e) { Log.e(TAG, "Error performing sync.", e); } }
Example #17
Source File: OkVolley.java From OkVolley with Apache License 2.0 | 5 votes |
/** * get the default request queue * * @return default {@link com.android.volley.RequestQueue} */ public RequestQueue getRequestQueue() { if (InstanceRequestQueue == null) { InstanceRequestQueue = newRequestQueue(mContext); } return InstanceRequestQueue; }
Example #18
Source File: VolleyXTest.java From VolleyX with Apache License 2.0 | 5 votes |
@Test public void testSetRequestQueue() throws Exception { RequestQueue requestQueue = Mockito.mock(RequestQueue.class); VolleyX.setRequestQueue(requestQueue); assertThat(VolleyX.sRequestQueue, is(requestQueue)); }
Example #19
Source File: RequestFragment.java From OkVolley with Apache License 2.0 | 5 votes |
@Override public void onDestroy() { OkVolley.getInstance().getRequestQueue().cancelAll(new RequestQueue.RequestFilter() { @Override public boolean apply(Request<?> request) { return request.getTag() != null && request.getTag().equals("request"); } }); super.onDestroy(); }
Example #20
Source File: NetworkHelper.java From IceNet with Apache License 2.0 | 5 votes |
public RequestQueue getRequestQueue() { if (mRequestQueue == null) { mRequestQueue = Volley.newRequestQueue(context, new OkHttpStack()); } return mRequestQueue; }
Example #21
Source File: Volley.java From SaveVolley with Apache License 2.0 | 5 votes |
/** * 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. */ /* * 默认 HttpStack = null */ public static RequestQueue newRequestQueue(Context context) { return newRequestQueue(context, null); }
Example #22
Source File: Volley.java From volley with Apache License 2.0 | 5 votes |
/** * 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 A {@link BaseHttpStack} to use for the network, or null for default. * @return A started {@link RequestQueue} instance. */ public static RequestQueue newRequestQueue(Context context, BaseHttpStack stack) { BasicNetwork network; if (stack == null) { if (Build.VERSION.SDK_INT >= 9) { network = new BasicNetwork(new HurlStack()); } else { // Prior to Gingerbread, HttpUrlConnection was unreliable. // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html // At some point in the future we'll move our minSdkVersion past Froyo and can // delete this fallback (along with all Apache HTTP code). String userAgent = "volley/0"; try { String packageName = context.getPackageName(); PackageInfo info = context.getPackageManager().getPackageInfo(packageName, /* flags= */ 0); userAgent = packageName + "/" + info.versionCode; } catch (NameNotFoundException e) { } network = new BasicNetwork( new HttpClientStack(AndroidHttpClient.newInstance(userAgent))); } } else { network = new BasicNetwork(stack); } return newRequestQueue(context, network); }
Example #23
Source File: VolleyHelper.java From SimplifyReader with Apache License 2.0 | 5 votes |
/** * get request queue * * @return */ public RequestQueue getRequestQueue() { if (null != requestQueue) { return requestQueue; } else { throw new IllegalArgumentException("RequestQueue is not initialized."); } }
Example #24
Source File: Volley.java From android-discourse with Apache License 2.0 | 5 votes |
/** * 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, HttpStack stack) { File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR); String userAgent = "volley/0"; try { String packageName = context.getPackageName(); PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0); userAgent = packageName + "/" + info.versionCode; } catch (NameNotFoundException e) { } 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); RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network); queue.start(); return queue; }
Example #25
Source File: HaikuClient.java From gplus-haiku-client-android with Apache License 2.0 | 5 votes |
/** * Retrieve an individual haiku from the API. * * @param haikuId the opaque identifier for a haiku * @param listener the object to be called when the call is complete */ public void fetchHaiku(final String haikuId, final HaikuRetrievedListener listener) { RequestQueue rq = mVolley.getRequestQueue(); String path = GET_HAIKU.replace("{haiku_id}", haikuId); HaikuApiRequest<Haiku> haikuGet = new HaikuApiRequest<Haiku>( (new TypeToken<Haiku>() { }), Request.Method.GET, Constants.SERVER_URL + path, new Response.Listener<Haiku>() { @Override public void onResponse(Haiku data) { listener.onHaikuRetrieved(data); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError volleyError) { Log.d(TAG, "Retrieve haiku error"); if (listener != null) { listener.onHaikuRetrieved(null); } } }, true ); haikuGet.setTag(GET_HAIKU); if (mHaikuSession != null) { haikuGet.setSession(mHaikuSession); } rq.add(haikuGet); }
Example #26
Source File: HomeFragment.java From QuickNews with MIT License | 5 votes |
public void showVideoNews(int position, RequestQueue requestQueue, ListView listView, SwipeRefreshLayout refreshLayout) { String url = null; switch (position) { case 0://全部 url = "http://toutiao.com/api/article/recent/?source=2&category=video" + "&as=A165472AB9D6F61"; break; case 1://逗比剧 url = "http://toutiao.com/api/article/recent/?source=2&category=subv_funny" + "&as=A1D507EA5937321"; break; case 2://好声音 url = "http://toutiao.com/api/article/recent/?source=2&category=subv_voice" + "&as=A17517DA89C7341"; break; case 3://看天下 url = "http://toutiao.com/api/article/recent/?source=2&category=subv_society" + "&as=A135F7CAF987379"; break; case 4://小品 url = "http://toutiao.com/api/article/recent/?source=2&category=subv_comedy" + "&as=A175777A09F73B7"; break; case 5://掠影 url = "http://toutiao.com/api/article/recent/?source=2&category=subv_movie" + "&as=A1D527BAD9973D2"; break; case 6://最娱乐 url = "http://toutiao.com/api/article/recent/?source=2&category=subv_entertainment" + "&as=A175D7CA09173E7"; break; } requestQueue.add(getNewsData(url, "", listView, refreshLayout)); }
Example #27
Source File: SendMail.java From ExamplesAndroid with Apache License 2.0 | 5 votes |
public void EnviarMail(final Email email) { final RequestQueue queue = Volley.newRequestQueue(context); StringRequest postRequest = new StringRequest(Request.Method.POST, SendMailPHP,new Response.Listener<String>() { @Override public void onResponse(String response) { Toast.makeText(context,"EMAIL Enviado",Toast.LENGTH_SHORT).show(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Toast.makeText(context, "Error al enviar el EMAIL " + error.getMessage(), Toast.LENGTH_LONG).show(); } }) { @Override protected Map<String, String> getParams() { Map<String, String> params = new HashMap<String, String>(); params.put("emisor", email.getEmisor()); params.put("receptor", email.getReceptor()); params.put("asunto", email.getAsunto()); params.put("mensaje", email.getMensaje()); return params; } }; queue.add(postRequest); }
Example #28
Source File: Pay.java From Anti-recall with GNU Affero General Public License v3.0 | 5 votes |
/** * 支付宝支付业务 */ public void pay(String type) { StringRequest request = new StringRequest(Request.Method.POST, "http://ar.qsboy.com/j/pay", response -> { Log.i(TAG, "sendMsg: " + response); Runnable payRunnable = () -> { PayTask alipay = new PayTask(activity); Map<String, String> result = alipay.payV2(response, true); Log.i("msp", result.toString()); Message msg = new Message(); msg.what = SDK_PAY_FLAG; msg.obj = result; mHandler.sendMessage(msg); }; Thread payThread = new Thread(payRunnable); payThread.start(); }, error -> Log.e(TAG, "sendMsg: " + error)) { @Override protected Map<String, String> getParams() { Map<String, String> map = new HashMap<>(); map.put("type", type); return map; } }; RequestQueue queue = Volley.newRequestQueue(activity); queue.add(request); }
Example #29
Source File: HaikuClient.java From gplus-haiku-client-android with Apache License 2.0 | 5 votes |
/** * Retrieve the currently signed in user from the API, or an error indicating which * type of authentication should be tried next. * * @param listener the object to be called when the call completes. */ public void fetchCurrentUser(final HaikuServiceListener listener) { RequestQueue rq = mVolley.getRequestQueue(); HaikuApiRequest<User> userGet = new HaikuApiRequest<User>( (new TypeToken<User>() { }), Request.Method.GET, Constants.SERVER_URL + GET_USER, new Response.Listener<User>() { @Override public void onResponse(User data) { listener.onUserRetrieved(data); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError volleyError) { Log.d(TAG, "Retrieve user error: " + volleyError.getMessage()); if (listener != null) { String err = getVolleyErrorCode(volleyError); listener.onUserRetrieved(null); } } }, true ); userGet.setSession(mHaikuSession); userGet.setTag(GET_USER); rq.add(userGet); }
Example #30
Source File: Volley.java From android_tv_metro with Apache License 2.0 | 5 votes |
public static RequestQueue newRequestQueue(Context context, HttpStack stack, String dir, int cacheSize) { File cacheDir = new File(context.getCacheDir(), dir); String userAgent = "volley/0"; try { String packageName = context.getPackageName(); PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0); userAgent = packageName + "/" + info.versionCode; } catch (NameNotFoundException e) { } 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); RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir, cacheSize), network); queue.start(); return queue; }