本文整理汇总了Java中com.android.volley.RequestQueue类的典型用法代码示例。如果您正苦于以下问题:Java RequestQueue类的具体用法?Java RequestQueue怎么用?Java RequestQueue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RequestQueue类属于com.android.volley包,在下文中一共展示了RequestQueue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: volleySyncRequest
import com.android.volley.RequestQueue; //导入依赖的package包/类
/**
* Effettua una web request sincrona tramite Volley API, restituendo in risposta
* l'oggetto JSON scaricato.
*/
public static JSONObject volleySyncRequest(Context c, String url) {
// configurazione della webRequest
RequestFuture<JSONObject> future = RequestFuture.newFuture();
JsonObjectRequest request = new JsonObjectRequest(url, null, future, future);
RequestQueue requestQueue = Volley.newRequestQueue(c);
requestQueue.add(request);
// esecuzione sincrona della webRequest
try {
// limita la richiesta bloccante a un massimo di 10 secondi, quindi restituisci
// la risposta.
return future.get(10, TimeUnit.SECONDS);
} catch (InterruptedException | TimeoutException | ExecutionException e) {
e.printStackTrace();
}
return null;
}
示例2: getData
import com.android.volley.RequestQueue; //导入依赖的package包/类
private void getData(String rollnumber) {
String url = DATA_URL+rollnumber;
loading = ProgressDialog.show(this,"Please wait...","Fetching...",false,false);
StringRequest stringRequest = new StringRequest(url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
loading.dismiss();
showJSON(response);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(Submit.this,error.getMessage().toString(),Toast.LENGTH_LONG).show();
}
});
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
示例3: volleySyncRequest
import com.android.volley.RequestQueue; //导入依赖的package包/类
/**
* Effettua una web request sincrona tramite Volley API, restituendo in risposta
* l'oggetto JSON scaricato.
*/
static JSONObject volleySyncRequest(Context c, String url) {
// configurazione della webRequest
RequestFuture<JSONObject> future = RequestFuture.newFuture();
JsonObjectRequest request = new JsonObjectRequest(url, null, future, future);
RequestQueue requestQueue = Volley.newRequestQueue(c);
requestQueue.add(request);
// esecuzione sincrona della webRequest
try {
// limita la richiesta bloccante a un massimo di 10 secondi, quindi restituisci
// la risposta.
return future.get(10, TimeUnit.SECONDS);
} catch (InterruptedException | TimeoutException | ExecutionException e) {
e.printStackTrace();
}
return null;
}
示例4: loadSearchSuggestions
import com.android.volley.RequestQueue; //导入依赖的package包/类
private void loadSearchSuggestions(final String query) {
String showName = query.replaceAll("\\s", "+");
RequestQueue requestQueue = VolleySingleton.getInstance().getRequestQueue();
JsonArrayRequest req = new JsonArrayRequest(
API.TV_MAZE_SEARCH + showName,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
List<SearchSuggestions> searchSuggestions = new ArrayList<>();
JSONObject object;
try {
for (int j = 0; j < response.length() && searchSuggestions.size() < 5; j++) {
object = response.getJSONObject(j).getJSONObject("show");
SearchSuggestions suggestion = new SearchSuggestions(object.getString("name"));
if (!searchSuggestions.contains(suggestion)) {
searchSuggestions.add(suggestion);
}
}
} catch (JSONException e) {
//Log.e("JSON exception", e.getMessage());
}
if (searchView.isSearchBarFocused()) {
searchView.swapSuggestions(searchSuggestions);
}
searchView.hideProgress();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
searchView.hideProgress();
}
});
req.setRetryPolicy(new DefaultRetryPolicy(
5000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
requestQueue.add(req);
}
示例5: getRequestQueue
import com.android.volley.RequestQueue; //导入依赖的package包/类
public RequestQueue getRequestQueue() {
if (mRequestQueue == null) {
mRequestQueue = Volley.newRequestQueue(getApplicationContext());
}
return mRequestQueue;
}
示例6: newVolleyRequestQueueForTest
import com.android.volley.RequestQueue; //导入依赖的package包/类
private RequestQueue newVolleyRequestQueueForTest(final Context context) {
File cacheDir = new File(context.getCacheDir(), "cache/volley");
Network network = new BasicNetwork(new HurlStack());
ResponseDelivery responseDelivery = new ExecutorDelivery(Executors.newSingleThreadExecutor());
RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network, 4, responseDelivery);
queue.start();
return queue;
}
示例7: publicMethods
import com.android.volley.RequestQueue; //导入依赖的package包/类
@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));
}
示例8: newRequestQueue
import com.android.volley.RequestQueue; //导入依赖的package包/类
/**
* 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;
}
示例9: getInternalQueue
import com.android.volley.RequestQueue; //导入依赖的package包/类
private static RequestQueue getInternalQueue(Context context) {
if (internalQueue == null) {
synchronized (Factory.class) {
if (internalQueue == null) {
internalQueue = Volley.newRequestQueue(context);
}
}
}
return internalQueue;
}
示例10: newOkHttpRequestQueue
import com.android.volley.RequestQueue; //导入依赖的package包/类
/**
* Creates a normal network request instance of the worker pool and calls
* which is based on OkHttpClient
* {@link com.android.volley.RequestQueue#start()} on it.
*/
public static RequestQueue newOkHttpRequestQueue(Context context) {
return newRequestQueue(context,
false,
new OkHttpStack(BaseSSLSocketFactory.getInstance("TLS")),
DEFAULT_NETWORK_THREAD_POOL_SIZE);
}
示例11: getRequestQueue
import com.android.volley.RequestQueue; //导入依赖的package包/类
public RequestQueue getRequestQueue() {
if (mRequestQueue == null) {
// getApplicationContext() is key, it keeps you from leaking the
// Activity or BroadcastReceiver if someone passes one in.
mRequestQueue = Volley.newRequestQueue(mCtx.getApplicationContext());
}
return mRequestQueue;
}
示例12: getRequestQueue
import com.android.volley.RequestQueue; //导入依赖的package包/类
public RequestQueue getRequestQueue()
{
if(requestQueue==null)
{
requestQueue= Volley.newRequestQueue(mContext);
}
return requestQueue;
}
示例13: RemoteDataSource
import com.android.volley.RequestQueue; //导入依赖的package包/类
public RemoteDataSource(String url) {
mUrl = url;
// TODO: context should be Application context + this should be a singleton
// mRequestQueue = Volley.newRequestQueue(context.getApplicationContext());
mRequestQueue = new RequestQueue(new NoCache(), new BasicNetwork(new HurlStack()));
//TODO: disable volley cache
mRequestQueue.start();
}
示例14: getImage
import com.android.volley.RequestQueue; //导入依赖的package包/类
void getImage() //profile pic
{
ImageRequest request = new ImageRequest("http://ec2-52-14-50-89.us-east-2.compute.amazonaws.com/static/userdata/"+email+"/thumb.png", ///"+email+" in btw userdata/ /thumb.png
new Response.Listener<Bitmap>() {
@Override
public void onResponse(Bitmap bitmap) {
pro=bitmap;
ByteArrayOutputStream baos=new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG,100, baos);
byte [] b=baos.toByteArray();
String temp= Base64.encodeToString(b, Base64.DEFAULT);
SharedPreferences.Editor editor=sharedPreferences.edit();
editor.putString("profile_pic",temp);
editor.commit();
// Log.e("mytag","Saved propic"+pro);
//count++;
}
}, 0, 0, null,
new Response.ErrorListener() {
public void onErrorResponse(VolleyError error) {
// mImageView.setImageResource(R.drawable.image_load_error);
Log.e("Home_Acitivity","No img found");
//count++;
}
});
// MySingleton.getMyInstance(getApplicationContext()).addToReqQue(request);
RequestQueue queue= Volley.newRequestQueue(TestLoginActivity.this);
queue.add(request);
}
示例15: cancelPendingRequests
import com.android.volley.RequestQueue; //导入依赖的package包/类
public void cancelPendingRequests(final Object tag) {
if (mRequestQueue != null && tag != null) {
mRequestQueue.cancelAll(new RequestQueue.RequestFilter() {
@Override
public boolean apply(Request<?> request) {
return request.getTag().equals(tag);
}
});
}
}