當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。