当前位置: 首页>>代码示例>>Java>>正文


Java JsonArrayRequest.setRetryPolicy方法代码示例

本文整理汇总了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);
}
 
开发者ID:chashmeetsingh,项目名称:TrackIt-Android,代码行数:39,代码来源:SearchActivity.java

示例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;
    }
}
 
开发者ID:longdivision,项目名称:hex,代码行数:17,代码来源:StoryCollectionService.java

示例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);
}
 
开发者ID:olejon,项目名称:mdapp,代码行数:40,代码来源:LvhActivity.java

示例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;
    }
 
开发者ID:narenkukreja,项目名称:quire,代码行数:66,代码来源:NearbyProductsFragment.java

示例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;

    }
 
开发者ID:narenkukreja,项目名称:quire,代码行数:60,代码来源:ProfileFragment.java

示例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);
}
 
开发者ID:olejon,项目名称:mdapp,代码行数:59,代码来源:NotificationsFromSlvActivity.java


注:本文中的com.android.volley.toolbox.JsonArrayRequest.setRetryPolicy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。