本文整理汇总了Java中com.android.volley.toolbox.JsonArrayRequest.setRetryPolicy方法的典型用法代码示例。如果您正苦于以下问题:Java JsonArrayRequest.setRetryPolicy方法的具体用法?Java JsonArrayRequest.setRetryPolicy怎么用?Java JsonArrayRequest.setRetryPolicy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.android.volley.toolbox.JsonArrayRequest
的用法示例。
在下文中一共展示了JsonArrayRequest.setRetryPolicy方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadSearchSuggestions
import com.android.volley.toolbox.JsonArrayRequest; //导入方法依赖的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);
}
示例2: getStories
import com.android.volley.toolbox.JsonArrayRequest; //导入方法依赖的package包/类
public List<Story> getStories(Collection collection) {
String apiUrl = getUrlForCollection(collection);
RequestFuture<JSONArray> future = RequestFuture.newFuture();
JsonArrayRequest request = new JsonArrayRequest(mApiBaseUrl + apiUrl, future, future);
request.setRetryPolicy(RetryPolicyFactory.build());
mRequestQueue.add(request);
try {
JSONArray response = future.get();
return FrontPageMarshaller.marshall(response);
} catch (Exception e) {
return null;
}
}
示例3: getCategories
import com.android.volley.toolbox.JsonArrayRequest; //导入方法依赖的package包/类
private void getCategories()
{
final RequestQueue requestQueue = new RequestQueue(new DiskBasedCache(getCacheDir(), 0), new BasicNetwork(new HurlStack()));
requestQueue.start();
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(mTools.getApiUri()+"api/1/lvh/", new Response.Listener<JSONArray>()
{
@Override
public void onResponse(JSONArray response)
{
requestQueue.stop();
mProgressBar.setVisibility(View.GONE);
mSwipeRefreshLayout.setRefreshing(false);
if(mTools.isTablet())
{
int spanCount = (response.length() == 1) ? 1 : 2;
mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(spanCount, StaggeredGridLayoutManager.VERTICAL));
}
mRecyclerView.setAdapter(new LvhAdapter(response));
}
}, new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error)
{
requestQueue.stop();
Log.e("LvhActivity", error.toString());
}
});
jsonArrayRequest.setRetryPolicy(new DefaultRetryPolicy(10000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
requestQueue.add(jsonArrayRequest);
}
示例4: getNearbyProducts
import com.android.volley.toolbox.JsonArrayRequest; //导入方法依赖的package包/类
private ArrayList<Product> getNearbyProducts() {
mProgressDialog = ProgressDialog.show(getContext(), "", getString(R.string.all_dialog_loading), true);
nearbyProductArrayList.clear();
// {host}/users/{user_id}/products/nearby
String url = QuireAPI.BASE_URL + QuireAPI.USERS_ENDPOINT + "/" + Quire.userID + QuireAPI.PRODUCTS_ENDPOINT + QuireAPI.NEARBY_ENDPOINT;
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, url, null, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
mProgressDialog.dismiss();
Log.d(LOG_TAG, "res: " + response);
if (response.length() == 0) {
noProductsLayout.setVisibility(View.VISIBLE);
refreshImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
nearbyProductArrayList.clear();
getActivity().startActivity(new Intent(getActivity(), NearbyProductsActivity.class));
getActivity().overridePendingTransition(R.anim.left_out, R.anim.right_in);
}
});
} else {
Product[] products = new Gson().fromJson(response.toString(), Product[].class);
Collections.addAll(nearbyProductArrayList, products);
nearbyProductsAdapter.notifyDataSetChanged();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
mProgressDialog.dismiss();
handleErrors(error);
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json; charset=utf-8");
headers.put("Authorization", Quire.access_token);
return headers;
}
};
jsonArrayRequest.setRetryPolicy(new DefaultRetryPolicy(
30000,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
RequestQueue queue = Volley.newRequestQueue(getContext());
queue.add(jsonArrayRequest);
return nearbyProductArrayList;
}
示例5: userListingsData
import com.android.volley.toolbox.JsonArrayRequest; //导入方法依赖的package包/类
private ArrayList<Product> userListingsData() {
String url = QuireAPI.BASE_URL + QuireAPI.USERS_ENDPOINT + "/" + Quire.userID + "/products";
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, url, null,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
Product product;
Log.d(LOG_TAG, "Res: " + response);
if (response.length() == 0) {
mButtonListNewItem.setVisibility(View.VISIBLE);
mRecyclerView.setVisibility(View.GONE);
mImageUpload.setVisibility(View.GONE);
} else {
mButtonListNewItem.setVisibility(View.GONE);
mRecyclerView.setVisibility(View.VISIBLE);
mImageUpload.setVisibility(View.VISIBLE);
Product[] products = new Gson().fromJson(response.toString(), Product[].class);
Collections.addAll(productListingArrayList, products);
Collections.reverse(productListingArrayList);
userListingsAdapter.notifyDataSetChanged();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toasty.error(mContext, "Error: " + error, Toast.LENGTH_SHORT).show();
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Authorization", Quire.access_token);
return headers;
}
};
jsonArrayRequest.setRetryPolicy(new DefaultRetryPolicy(
0,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
RequestQueue queue = Volley.newRequestQueue(mContext);
queue.add(jsonArrayRequest);
return productListingArrayList;
}
示例6: getNotifications
import com.android.volley.toolbox.JsonArrayRequest; //导入方法依赖的package包/类
private void getNotifications()
{
final RequestQueue requestQueue = new RequestQueue(new DiskBasedCache(getCacheDir(), 0), new BasicNetwork(new HurlStack()));
requestQueue.start();
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(mTools.getApiUri()+"api/1/notifications-from-slv/", new Response.Listener<JSONArray>()
{
@Override
public void onResponse(JSONArray response)
{
requestQueue.stop();
if(response.length() == 0)
{
mProgressBar.setVisibility(View.GONE);
mSwipeRefreshLayout.setRefreshing(false);
mTools.showToast(getString(R.string.notifications_from_slv_could_not_get_notifications), 1);
finish();
}
else
{
mProgressBar.setVisibility(View.GONE);
mSwipeRefreshLayout.setRefreshing(false);
if(mTools.isTablet())
{
int spanCount = (response.length() == 1) ? 1 : 2;
mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(spanCount, StaggeredGridLayoutManager.VERTICAL));
}
mRecyclerView.setAdapter(new NotificationsFromSlvAdapter(response));
}
}
}, new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error)
{
requestQueue.stop();
mProgressBar.setVisibility(View.GONE);
mSwipeRefreshLayout.setRefreshing(false);
mTools.showToast(getString(R.string.notifications_from_slv_could_not_get_notifications), 1);
Log.e("NotificationsFromSlv", error.toString());
finish();
}
});
jsonArrayRequest.setRetryPolicy(new DefaultRetryPolicy(10000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
requestQueue.add(jsonArrayRequest);
}