コード例 #1
0
ファイル: BaseFragment.java プロジェクト: antrromet/We-Care
  public void requestVolley(
      final Constants.VolleyTags tag,
      String url,
      String alertMsgDisplay,
      boolean showProgressDialog) {
    Logger.d(TAG, url);
    hideKeyboard();

    if (isNetworkAvailable() && !Application.containsRequest(tag)) {
      final ProgressDialog pDialog = new ProgressDialog(getActivity());
      pDialog.setCancelable(false);
      pDialog.setMessage(alertMsgDisplay);
      if (showProgressDialog && !TextUtils.isEmpty(alertMsgDisplay)) {
        pDialog.show();
      }
      if (!showProgressDialog) {
        showActionBarProgress();
      }

      JsonArrayRequest jsonObjRequest =
          new JsonArrayRequest(
              url,
              new Listener<JSONArray>() {

                @Override
                public void onResponse(JSONArray response) {
                  hideActionBarProgress(tag);
                  pDialog.dismiss();
                  Logger.d(TAG, response.toString());
                  mVolleyListener.OnSuccess(tag, response);
                }
              },
              new ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError error) {
                  hideActionBarProgress(tag);
                  Logger.e(TAG, "Error: " + error.getMessage());
                  if (error instanceof NoConnectionError || error instanceof TimeoutError) {
                    showToast(getString(R.string.internet_problem));
                  } else {
                    showToast(error.getMessage());
                  }
                  pDialog.dismiss();
                  mVolleyListener.OnError(tag, error);
                }
              });
      // Wait for 20s because this can be a long request
      jsonObjRequest.setRetryPolicy(
          new DefaultRetryPolicy(
              20000,
              DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
              DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
      // Adding request to request queue
      Application.addToRequestQueue(jsonObjRequest, tag);
    }
  }
コード例 #2
0
ファイル: BaseFragment.java プロジェクト: antrromet/We-Care
  public void requestVolley(
      final Constants.VolleyTags tag,
      String url,
      int method,
      JSONObject requestObject,
      String alertMsgDisplay,
      boolean showProgressDialog) {
    Logger.d(TAG, url);
    hideKeyboard();

    if (isNetworkAvailable() && !Application.containsRequest(tag)) {
      final ProgressDialog pDialog = new ProgressDialog(getActivity());
      pDialog.setCancelable(false);
      pDialog.setMessage(alertMsgDisplay);
      if (showProgressDialog && !TextUtils.isEmpty(alertMsgDisplay)) {
        pDialog.show();
      }
      if (!showProgressDialog) {
        showActionBarProgress();
      }

      JsonObjectRequest jsonObjRequest =
          new JsonObjectRequest(
              method,
              url,
              requestObject,
              new Response.Listener<JSONObject>() {

                @Override
                public void onResponse(JSONObject response) {
                  hideActionBarProgress(tag);
                  pDialog.dismiss();
                  mVolleyListener.OnSuccess(tag, response);
                }
              },
              new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError error) {
                  hideActionBarProgress(tag);
                  Logger.e(TAG, "Error: " + error.getMessage());
                  if (error instanceof NoConnectionError || error instanceof TimeoutError) {
                    showToast(getString(R.string.internet_problem));
                  } else {
                    showToast(error.getMessage());
                  }
                  pDialog.dismiss();
                  mVolleyListener.OnError(tag, error);
                }
              });
      // Adding request to request queue
      Application.addToRequestQueue(jsonObjRequest, tag);
    }
  }