Java 类com.android.volley.NoConnectionError 实例源码

项目:LnkShortener    文件:SetupActivity.java   
@Override
public void onErrorResponse(VolleyError error) {

    if (error instanceof TimeoutError || error instanceof NoConnectionError) {
        // Is thrown if there's no network connection or server is down
        Toast.makeText(context, getString(R.string.error_network_timeout),
                Toast.LENGTH_LONG).show();
        // We return to the last fragment
        if (getFragmentManager().getBackStackEntryCount() != 0) {
            getFragmentManager().popBackStack();
        }

    } else {
            // Is thrown if there's no network connection or server is down
            Toast.makeText(context, getString(R.string.error_network),
                    Toast.LENGTH_LONG).show();
            // We return to the last fragment
            if (getFragmentManager().getBackStackEntryCount() != 0) {
                getFragmentManager().popBackStack();
            }
    }
}
项目:Keep-HODLing    文件:GdaxApi.java   
private Response.ErrorListener getErrorListener(final Listener l) {
    return new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if (error instanceof NoConnectionError) {
                l.onFailure("Network is unreachable. Please check your internet connection.");
            } else if (error.networkResponse.statusCode == 401 || error.networkResponse.statusCode == 403) {
                l.onFailure("Invalid credentials or not enough permissions");
            } else if (error.networkResponse.statusCode == 400) {
                ObjectMapper mapper = new ObjectMapper();
                try {
                    JsonNode json = mapper.readTree(new String(error.networkResponse.data));
                    l.onFailure("Error: " + json.get("message").asText());
                } catch (IOException e) {
                    l.onFailure(new String(error.networkResponse.data));
                }
            } else {
                l.onFailure(error.getMessage());
            }
        }
    };
}
项目:hyperrail-for-android    文件:ErrorDialogFactory.java   
/**
 * Show an error dialog based on the exception
 *
 * @param exception The exception which occurred
 * @param context   The current context
 * @param finish    Whether or not to finish this activity
 * @return The dialog which is shown
 */
public static void showErrorDialog(final Exception exception, final Activity context, final boolean finish) {
    if (exception instanceof ServerError) {
        if (((ServerError) exception).networkResponse != null) {
            if (((ServerError) exception).networkResponse.statusCode == 404) {
                showNotFoundErrorDialog(context, finish);
            } else if (((ServerError) exception).networkResponse.statusCode == 500) {
                showServerErrorDialog(context, finish);
            } else {
                showServerErrorDialog(context, finish);
            }
        } else {
            showGeneralErrorDialog(context, finish);
        }
    } else if (exception instanceof NoConnectionError){
        showNetworkErrorDialog(context, finish);
    } else {
        showGeneralErrorDialog(context, finish);
    }
}
项目:dolores-android    文件:HttpUtil.java   
public static String checkErrorType(VolleyError error) {
    String str = "";
    if (error instanceof NoConnectionError) {
        str = ErrorCode.IS_NOT_NETWORK;
    } else if (error instanceof AuthFailureError) {
        str = ErrorCode.AUTH_FAILED;
    } else if (error instanceof TimeoutError) {
        str = ErrorCode.CONNECTION_TIMEOUT;
    } else if (error instanceof ParseError) {
        str = ErrorCode.PARSE_DATA_ERROR;
    } else if (error instanceof ServerError) {
        str = ErrorCode.SERVER_ERROR;
    } else if (error instanceof HttpError) {
        HttpError httpError = (HttpError) error;
        str = httpError.getMessage();
        if (TextUtils.isEmpty(str)) {
            str = ErrorCode.REQUEST_ERROR;
        }
    } else {
        str = ErrorCode.REQUEST_ERROR;
    }
    return str;
}
项目:minhaeiro    文件:MinhaeiroErrorHelper.java   
public static String getMessage(VolleyError error){
    if (error instanceof TimeoutError) {
        return TIME_OUT;
    } else if(error instanceof NoConnectionError) {
        return NO_CONNECTION;
    } else if (error instanceof AuthFailureError) {
        return AUTH_FAILURE;
    } else if (error instanceof ServerError) {
        return SERVER;
    } else if (error instanceof NetworkError) {
        return NETWORK;
    } else if (error instanceof ParseError) {
        return PARSE;
    } else{
        return DEFAULT;
    }
}
项目:HappyVolley    文件:BaseRequest.java   
/**
 * 判断是否有网络 或者 server无响应等非Client端请求参数异常
 *
 * @param error VolleyError
 * @return isConnectionError
 */
public boolean isConnectionError(VolleyError error) {
    if (error == null) {
        return false;
    }
    if (error instanceof TimeoutError) {
        return true;
    }
    if (error instanceof NoConnectionError) {
        return true;
    }
    if (error instanceof NetworkError) {
        return true;
    }
    if (error instanceof ServerError) {
        return true;
    }
    if (error instanceof RedirectError) {
        return true;
    }
    if (error instanceof AuthFailureError) {
        return true;
    }
    return false;
}
项目:stately    文件:ZombieControlActivity.java   
/**
 * Queries the user's superweapon progress.
 */
private void queryZSuperweaponProgress() {
    NSStringRequest stringRequest = new NSStringRequest(getApplicationContext(), Request.Method.GET, ZSuperweaponProgress.ZOMBIE_CONTROL_QUERY,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    processZSuperweaponProgress(response);
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            SparkleHelper.logError(error.toString());
            mSwipeRefreshLayout.setRefreshing(false);
            if (error instanceof TimeoutError || error instanceof NoConnectionError || error instanceof NetworkError) {
                SparkleHelper.makeSnackbar(mView, getString(R.string.login_error_no_internet));
            } else {
                SparkleHelper.makeSnackbar(mView, getString(R.string.login_error_generic));
            }
        }
    });

    if (!DashHelper.getInstance(this).addRequest(stringRequest)) {
        mSwipeRefreshLayout.setRefreshing(false);
        SparkleHelper.makeSnackbar(mView, getString(R.string.rate_limit_error));
    }
}
项目:lunzi    文件:CustomRequest.java   
@Override
public void deliverError(VolleyError error) {
    Log.i("CustomRequest", "deliverError----" + error.getMessage());
    if (error instanceof NoConnectionError && mRequestBody == null) {
        Cache.Entry entry = this.getCacheEntry();
        if (entry != null) {
            Log.d("CustomRequest", " deliverError--------:  " + new String(entry.data));
            if (entry.data != null && entry.responseHeaders != null) {
                Response<T> response = parseNetworkResponse(new NetworkResponse(entry.data, entry.responseHeaders));
                if (response.result != null) {
                    deliverResponse(response.result);
                    return;
                }
            }
        }
    }
    super.deliverError(error);
}
项目:android-project-template    文件:VolleyResponseUtils.java   
public static boolean isNetworkingError(VolleyError volleyError)
{
    if (volleyError.networkResponse == null) {
        if (volleyError instanceof TimeoutError) {
           return true;
        }

        if (volleyError instanceof NoConnectionError) {
            return true;
        }

        if (volleyError instanceof NetworkError) {
            return true;
        }

    }
    return false;
}
项目:AndroidBlog    文件:ErrorTrans.java   
public static OsaException transToOsaException(Throwable a) {
    if (a == null) {
        return new OsaException("未知错误");
    }
    if (a instanceof ParseError) {
        return new OsaException("数据解析错误", a);
    }
    if (a instanceof TimeoutError) {
        return new OsaException("请求超时", a);
    }
    if (a instanceof ServerError) {
        return new OsaException("服务器错误", a);
    }
    if (a instanceof AuthFailureError) {
        return new OsaException("请求认证错误", a);
    }
    if (a instanceof NoConnectionError) {
        return new OsaException("网络未连接,请检查网络状态", a);
    }
    if (a instanceof NetworkError) {
        return new OsaException("网络连接异常", a);
    }
    return new OsaException("未知错误");
}
项目:Netease    文件:RequestSingletonFactory.java   
@Override
public void onErrorResponse(VolleyError error) {
    error.printStackTrace();
    Log.d("RVA", "error:" + error);

    int errorCode = 0;
    if (error instanceof TimeoutError) {
        errorCode = -7;
    } else if (error instanceof NoConnectionError) {
        errorCode = -1;
    } else if (error instanceof AuthFailureError) {
        errorCode = -6;
    } else if (error instanceof ServerError) {
        errorCode = 0;
    } else if (error instanceof NetworkError) {
        errorCode = -1;
    } else if (error instanceof ParseError) {
        errorCode = -8;
    }
    Toast.makeText(contextHold, ErrorCode.errorCodeMap.get(errorCode), Toast.LENGTH_SHORT).show();
}
项目:social-api    文件:ServerRequest.java   
private void showError(VolleyError error) {
    //In your extended request class
    dismissProgressBar();
    if (error.networkResponse != null && error.networkResponse.data != null) {
        VolleyError volleyError = new VolleyError(new String(error.networkResponse.data));
        volleyError.printStackTrace();
    }
    if (error instanceof NetworkError) {
        showToast(NETWORK_ERROR);
    } else if (error instanceof ServerError) {
        showToast(SERVER_ERROR);
    } else if (error instanceof NoConnectionError) {
        showToast(NO_INTERNET_CONNECTION);
    } else if (error instanceof TimeoutError) {
        showToast(CONNECTION_TIME_OUT);
    } else {
        showToast(UNKNOWN_ERROR);
    }

}
项目:Jiemian    文件:BasePresenter.java   
public String handlerException(VolleyError error) {

        if (error instanceof TimeoutError || error instanceof NoConnectionError) {
            return "连接服务器失败";
        } else if (error instanceof AuthFailureError) {
            return "服务器验证失败";
        } else if (error instanceof ServerError) {
            return "服务器出错了";
        } else if (error instanceof NetworkError) {
            return "网络异常";
        } else if (error instanceof ParseError) {
            return "数据解析异常";
        } else {
            Log.d("error", error.toString());
            return "其他错误";
        }
    }
项目:recurly-client-android    文件:RecurlyError.java   
/**
 * Helper method to create a RecurlyError from a VolleyError
 *
 * @param volleyError The underlying error causing the exception
 * @return An instance of RecurlyError
 */
public static RecurlyError errorFromVolley(VolleyError volleyError) {
    if (volleyError instanceof NetworkResponseError) {
        return new RecurlyError((NetworkResponseError) volleyError);
    }

    RecurlyError error = new RecurlyError();

    String responseBody = null;
    if (volleyError.networkResponse != null && volleyError.networkResponse.data != null) {
        responseBody = new String(volleyError.networkResponse.data);
    }
    if (!(volleyError instanceof NoConnectionError)) {
        volleyError.printStackTrace();
    }

    if (volleyError.networkResponse != null) {
        error.mStatusCode = volleyError.networkResponse.statusCode;
    }
    error.mErrorMessage = volleyError.getLocalizedMessage();
    error.mErrorCode = volleyError.getMessage();

    return error;
}
项目:d8androidsdk    文件:VolleyResponseUtils.java   
public static boolean isNetworkingError(VolleyError volleyError)
{
    if (volleyError.networkResponse == null) {
        if (volleyError instanceof TimeoutError) {
           return true;
        }

        if (volleyError instanceof NoConnectionError) {
            return true;
        }

        if (volleyError instanceof NetworkError) {
            return true;
        }

    }
    return false;
}
项目:podio-android    文件:ImageLoader.java   
/**
 * Parses any given errors from the underlying Volley mechanism into SDK defined error types.
 *
 * @param volleyError
 *         The Volley error to parse.
 *
 * @return The corresponding SDK defined error object.
 */
private PodioError parseVolleyError(VolleyError volleyError) {
    PodioError error;

    if (volleyError instanceof NoConnectionError && volleyError.getCause() instanceof UnknownHostException) {
        error = new ConnectionError(volleyError);
    } else if (volleyError instanceof TimeoutError) {
        error = new NoResponseError(volleyError);
    } else {
        String errorJson = getResponseBody(volleyError.networkResponse);
        int responseCode = getResponseCode(volleyError.networkResponse);

        if (Utils.notEmpty(errorJson) && responseCode > 0) {
            error = new ApiError(errorJson, responseCode, volleyError);
        } else {
            error = new PodioError(volleyError);
        }
    }

    return error;
}
项目:AgilefantAndroid    文件:HomeActivity.java   
private ErrorListener getErrorListener(final ProgressDialog progressDialog) {
    return new ErrorListener() {

        @Override
        public void onErrorResponse(final VolleyError arg0) {
            if (progressDialog != null && progressDialog.isShowing()) {
                progressDialog.dismiss();
            }

            String error = getResources().getString(R.string.login_error);
            if (arg0 instanceof NoConnectionError) {
                error = getResources().getString(R.string.connection_error);
            }

            Toast.makeText(
                HomeActivity.this, error, Toast.LENGTH_LONG).show();
        }
    };
}
项目:CrossBow    文件:PlayNetwork.java   
private String getBestNode(long timeOut) throws VolleyError {
    final String nodeCompatibilty = context.getString(R.string.crossbow_compatibility);
    CapabilityApi.GetCapabilityResult nodes = Wearable.CapabilityApi.getCapability(googleApiClient, nodeCompatibilty, CapabilityApi.FILTER_REACHABLE).await(timeOut, TimeUnit.MILLISECONDS);
    String nodeID = null;
    Set<Node> nodeList = nodes.getCapability().getNodes();
    if(nodeList.isEmpty()) {
        throw new NoConnectionError(new VolleyError("No nodes found to handle the request"));
    }

    //get the nearest node
    for(Node node : nodeList) {
        if(node.isNearby()) {
            return node.getId();
        }
        nodeID = node.getId();
    }
    return nodeID;
}
项目:Rando-android    文件:ErrorResponseListener.java   
@Override
public void onErrorResponse(VolleyError e) {
    if (e.networkResponse != null)
        Log.d(ErrorResponseListener.class, "Network Error", "" + e.networkResponse.statusCode + " " + String.valueOf(e.networkResponse.data));
    // Handle your error types accordingly.For Timeout & No connection error, you can show 'retry' button.
    // For AuthFailure, you can re login with user credentials.
    // For ClientError, 400 & 401, Errors happening on client side when sending api request.
    // In this case you can check how client is forming the api and debug accordingly.
    // For ServerError 5xx, you can do retry or handle accordingly.
    if (e instanceof AuthFailureError) {
        Intent intent = new Intent(Constants.AUTH_FAILURE_BROADCAST_EVENT);
        context.sendBroadcast(intent);
        Log.d(ErrorResponseListener.class, "AuthFailureError: ", e.getStackTrace().toString());
    } else if (e instanceof NetworkError) {
    } else if (e instanceof ServerError) {
    } else if (e instanceof ParseError) {
    } else if (e instanceof NoConnectionError) {
    } else if (e instanceof TimeoutError) {
    }
}
项目:TrackIt-Android    文件:ActorDetailActivity.java   
private void fetchData() {
    wheel.setVisibility(View.VISIBLE);
    RequestQueue requestQueue = VolleySingleton.getInstance().getRequestQueue();
    StringRequest req = new StringRequest(Request.Method.GET, API.BASE_IMAGE_URL + showID + "/actors.xml",
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    new loadData().execute(response);
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if (error instanceof TimeoutError || error instanceof NoConnectionError) {
                tvError.setText(R.string.timeout_error);
            } else if (error instanceof ServerError) {
                tvError.setText(R.string.server_error);
            } else if (error instanceof NetworkError) {
                tvError.setText(R.string.network_error);
            } else {
                tvError.setText(R.string.connection_error);
            }
            tapToRetry.setVisibility(View.VISIBLE);
            wheel.setVisibility(View.GONE);
        }
    });
    requestQueue.add(req);
}
项目:publicProject    文件:JRYGRequest.java   
public void deliverError(VolleyError error) {
    CommonLog.e("请求异常 -> VolleyError"+error.getMessage());
    CommonLog.e("请求异常 -> VolleyError"+error);//TODO  添加的
    if (errorListener != null) {
        errorListener.onErrorResponse(error);
    }
    if (error instanceof NoConnectionError) {
        PromptManager.showToast(JRYGApplaction.context, R.string.network_anomaly);
    }
}
项目:quire    文件:UpdateUserListingPresenter.java   
private void handleNetworkError(VolleyError error) {
    if (error instanceof TimeoutError || error instanceof NoConnectionError) {
        getView().showTimeOutError();
    } else if (error instanceof ServerError) {
        getView().show500ServerError();
    } else if (error instanceof NetworkError) {
        getView().showNetworkError();
    }
}
项目:quire    文件:ListNewItemPresenter.java   
private void handleErrors(VolleyError error) {
    if (error instanceof TimeoutError || error instanceof NoConnectionError) {
        getView().showTimeOutError();
    } else if (error instanceof ServerError) {
        getView().show500ServerError();
    } else if (error instanceof NetworkError) {
        getView().showNetworkError();
    }
}
项目:LnkShortener    文件:SetupActivity.java   
@Override
public void onErrorResponse(VolleyError error) {

    if (error instanceof TimeoutError || error instanceof NoConnectionError) {
        // Is thrown if there's no network connection or server is down
        Toast.makeText(context, getString(R.string.error_network_timeout),
                Toast.LENGTH_LONG).show();
        // We return to the last fragment
        if (getFragmentManager().getBackStackEntryCount() != 0) {
            getFragmentManager().popBackStack();
        }

    } else if (error instanceof AuthFailureError) {
        // Is thrown if the API-Key is wrong
        Toast.makeText(context, getString(R.string.error_apikey),
                Toast.LENGTH_LONG).show();
        // We return to the last fragment
        if (getFragmentManager().getBackStackEntryCount() != 0) {
            getFragmentManager().popBackStack();
        }
    }
        else if (error instanceof ServerError) {
            // Is thrown if 404 or server down
            Toast.makeText(context, getString(R.string.error_server),
                    Toast.LENGTH_LONG).show();
            // We return to the last fragment
            if (getFragmentManager().getBackStackEntryCount() != 0) {
                getFragmentManager().popBackStack();
            }
        } else {
            // Some other problem.
            Toast.makeText(context, getString(R.string.error_network),
                    Toast.LENGTH_LONG).show();
            // We return to the last fragment
            if (getFragmentManager().getBackStackEntryCount() != 0) {
                getFragmentManager().popBackStack();
            }

        }
    }
项目:LnkShortener    文件:SetupActivity.java   
@Override
    public void onErrorResponse(VolleyError error) {

        if (error instanceof TimeoutError || error instanceof NoConnectionError) {
            // Is thrown if there's no network connection or server is down
            Toast.makeText(context, getString(R.string.error_network_timeout),
                    Toast.LENGTH_LONG).show();
            // We return to the last fragment
            if (getFragmentManager().getBackStackEntryCount() != 0) {
                getFragmentManager().popBackStack();
            }

        } else if (error instanceof AuthFailureError) {
            // Is thrown if the API-Key is wrong
            Toast.makeText(context, getString(R.string.error_apikey),
                    Toast.LENGTH_LONG).show();
            // We return to the last fragment
            if (getFragmentManager().getBackStackEntryCount() != 0) {
                getFragmentManager().popBackStack();
            }
        }
        else if (error instanceof ServerError) {
            // Is thrown if 404 or server down
            Toast.makeText(context, getString(R.string.error_server),
                    Toast.LENGTH_LONG).show();
            // We return to the last fragment
            if (getFragmentManager().getBackStackEntryCount() != 0) {
                getFragmentManager().popBackStack();
            }
        } else {
            // Some other problem.
            Toast.makeText(context, getString(R.string.error_network),
                    Toast.LENGTH_LONG).show();
            // We return to the last fragment
            if (getFragmentManager().getBackStackEntryCount() != 0) {
                getFragmentManager().popBackStack();
            }

        }
}
项目:joy-library    文件:ErrorHelper.java   
/**
     * @param error
     * @return Return generic message for errors
     */
    public static String getErrorType(Throwable error) {

        if (error == null)
            return null;

        int resId = -1;
        if (error instanceof TimeoutError) {

            resId = R.string.generic_server_timeout;
        } else if (error instanceof ServerError) {

            resId = R.string.generic_server_down;
        } else if (error instanceof AuthFailureError) {

            resId = R.string.auth_failed;
        } else if (error instanceof NetworkError) {

            resId = R.string.no_internet;
        } else if (error instanceof NoConnectionError) {

            resId = R.string.no_network_connection;
        } else if (error instanceof ParseError) {

            resId = R.string.parsing_failed;
        }
//        return BaseApplication.getAppString(R.string.generic_error);
        return resId == -1 ? error.getMessage() : BaseApplication.getAppString(resId);
    }
项目:minhaeiro    文件:Categoria.java   
public static void cadastrar(final Categoria categoria, final ApiListener listener) {
    String url = ApiRoutes.CATEGORIA.Post();
    final int metodo = Request.Method.POST;
    final JsonObjectRequest request = new JsonObjectRequest(
            metodo,
            url,
            new JSONObject(categoria.toParams()),
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    Categoria resposta = new Gson().fromJson(response.toString(), Categoria.class);
                    Categoria.cadastrar(categoria);
                    listener.sucesso(resposta);
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    if (error instanceof NoConnectionError) {
                        Categoria c = Categoria.cadastrar(categoria);
                        Requisicao.adicionar(new Requisicao(metodo,Requisicao.CATEGORIA,new Gson().toJson(c)));
                        listener.sucesso(c);
                    } else {
                        listener.erro(error);
                    }
                }
            }
    );
    AppController.getInstance().addToRequestQueue(request);
}
项目:minhaeiro    文件:Categoria.java   
public static void editar(final Categoria categoria, final ApiListener listener) {
    String url = ApiRoutes.CATEGORIA.Put(categoria.categoria_id);
    final int metodo = Request.Method.PUT;
    JsonObjectRequest request = new JsonObjectRequest(
            metodo,
            url,
            new JSONObject(categoria.toParams()),
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    Categoria resposta = new Gson().fromJson(response.toString(), Categoria.class);
                    Categoria.editar(categoria);
                    listener.sucesso(resposta);
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    if (error instanceof NoConnectionError) {
                        Categoria c = Categoria.editar(categoria);
                        Requisicao.adicionar(new Requisicao(metodo, Requisicao.CATEGORIA, new Gson().toJson(c)));
                        listener.sucesso(c);
                    } else {
                        listener.erro(error);
                    }
                }
            }
    );
    AppController.getInstance().addToRequestQueue(request);
}
项目:minhaeiro    文件:Categoria.java   
public static void excluir(final Categoria categoria, final ApiListener listener) {
    String url = ApiRoutes.CATEGORIA.Delete(categoria.categoria_id);
    final int metodo = Request.Method.DELETE;
    StringRequest request = new StringRequest(
            metodo,
            url,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    Categoria resposta = new Gson().fromJson(response, Categoria.class);
                    Categoria.excluir(categoria);
                    listener.sucesso(resposta);
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    if (error instanceof NoConnectionError) {
                        Categoria.excluir(categoria);
                        Requisicao.adicionar(new Requisicao(metodo, Requisicao.CATEGORIA, new Gson().toJson(categoria)));
                        listener.sucesso(categoria);
                    } else {
                        listener.erro(error);
                    }
                }
            }
    );
    AppController.getInstance().addToRequestQueue(request);
}
项目:minhaeiro    文件:MovimentacaoItem.java   
public static void cadastrar(final MovimentacaoItem item, final ApiListener listener) {
    final String url = ApiRoutes.MOVIMENTACAO_ITEM.Post(item.movimentacao_id);
    final int metodo = Request.Method.POST;
    JsonObjectRequest request = new JsonObjectRequest(
            metodo,
            url,
            new JSONObject(item.toParams()),
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    MovimentacaoItem resposta = new Gson().fromJson(response.toString(), MovimentacaoItem.class);
                    MovimentacaoItem.cadastrar(item);
                    listener.sucesso(resposta);

                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if (error instanceof NoConnectionError) {
                MovimentacaoItem i = MovimentacaoItem.cadastrar(item);
                Requisicao.adicionar(new Requisicao(metodo, Requisicao.MOVIMENTACAO_ITEM, new Gson().toJson(i)));
                listener.sucesso(i);
            } else {
                listener.erro(error);
            }
        }
    });
    AppController.getInstance().addToRequestQueue(request);
}
项目:minhaeiro    文件:MovimentacaoItem.java   
public static void editar(final MovimentacaoItem item, final ApiListener listener) {
    final String url = ApiRoutes.MOVIMENTACAO_ITEM.Put(item.movimentacao_id, item.item_id);
    final int metodo = Request.Method.PUT;
    JsonObjectRequest request = new JsonObjectRequest(
            metodo,
            url,
            new JSONObject(item.toParams()),
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    MovimentacaoItem resposta = new Gson().fromJson(response.toString(), MovimentacaoItem.class);
                    MovimentacaoItem.editar(item);
                    listener.sucesso(resposta);
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if (error instanceof NoConnectionError) {
                MovimentacaoItem i = MovimentacaoItem.editar(item);
                Requisicao.adicionar(new Requisicao(metodo, Requisicao.MOVIMENTACAO_ITEM, new Gson().toJson(i)));
                listener.sucesso(i);
            } else {
                listener.erro(error);
            }
        }
    });
    AppController.getInstance().addToRequestQueue(request);
}
项目:minhaeiro    文件:MovimentacaoItem.java   
public static void excluir(final MovimentacaoItem item, final ApiListener listener) {
    final String url = ApiRoutes.MOVIMENTACAO_ITEM.Delete(item.movimentacao_id, item.item_id);
    final int metodo = Request.Method.DELETE;
    StringRequest request = new StringRequest(
            metodo,
            url,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    MovimentacaoItem.excluir(item);
                    listener.sucesso(null);
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if (error instanceof NoConnectionError) {
                MovimentacaoItem.excluir(item);
                Requisicao.adicionar(new Requisicao(metodo, Requisicao.MOVIMENTACAO_ITEM, new Gson().toJson(item)));
                listener.sucesso(item);
            } else {
                listener.erro(error);
            }
        }
    }
    );
    AppController.getInstance().addToRequestQueue(request);
}
项目:minhaeiro    文件:Movimentacao.java   
public static void excluir(final Movimentacao movimentacao, final ApiListener listener) {
    final String url = ApiRoutes.MOVIMENTACAO.Delete(movimentacao.movimentacao_id);
    final int metodo = Request.Method.DELETE;
    StringRequest request = new StringRequest(
            metodo,
            url,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    Movimentacao.excluir(movimentacao);
                    listener.sucesso(movimentacao);
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if (error instanceof NoConnectionError) {
                Movimentacao.excluir(movimentacao);
                Requisicao.adicionar(new Requisicao(metodo, Requisicao.MOVIMENTACAO, new Gson().toJson(movimentacao)));
                listener.sucesso(movimentacao);
            } else {
                listener.erro(error);
            }
        }
    }
    );
    AppController.getInstance().addToRequestQueue(request);
}
项目:minhaeiro    文件:Movimentacao.java   
public static void cadastrar(final Movimentacao movimentacao, final ApiListener listener) {
    final String url = ApiRoutes.MOVIMENTACAO.Post();
    final int metodo = Request.Method.POST;
    JsonObjectRequest request = new JsonObjectRequest(
            metodo,
            url,
            new JSONObject(movimentacao.toParams()),
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    Movimentacao resposta = new Gson().fromJson(response.toString(), Movimentacao.class);
                    Movimentacao.cadastrar(resposta);
                    listener.sucesso(resposta);
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if (error instanceof NoConnectionError) {
                Movimentacao m = Movimentacao.cadastrar(movimentacao);
                Requisicao.adicionar(new Requisicao(metodo, Requisicao.MOVIMENTACAO, new Gson().toJson(m)));
                listener.sucesso(m);
            } else {
                listener.erro(error);
            }
        }
    });
    AppController.getInstance().addToRequestQueue(request);
}
项目:minhaeiro    文件:Movimentacao.java   
public static void editar(final Movimentacao movimentacao, final ApiListener listener) {
    final String url = ApiRoutes.MOVIMENTACAO.Put(movimentacao.movimentacao_id);
    final int metodo = Request.Method.PUT;
    JsonObjectRequest request = new JsonObjectRequest(
            metodo,
            url,
            new JSONObject(movimentacao.toParams()),
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    Movimentacao resposta = new Gson().fromJson(response.toString(), Movimentacao.class);
                    Movimentacao.editar(movimentacao);
                    listener.sucesso(resposta);
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if (error instanceof NoConnectionError) {
                Movimentacao m = Movimentacao.editar(movimentacao);
                Requisicao.adicionar(new Requisicao(metodo, Requisicao.MOVIMENTACAO, new Gson().toJson(m)));
                listener.sucesso(m);
            } else {
                listener.erro(error);
            }
        }
    });
    AppController.getInstance().addToRequestQueue(request);
}
项目:minhaeiro    文件:Usuario.java   
public static void listar(final ApiListener listener) {
    StringRequest request = new StringRequest(
            ApiRoutes.USUARIO.Get(),
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    Usuario usuario = new Gson().fromJson(response, Usuario.class);
                    P.inserir(P.USUARIO_JSON, response);
                    P.inserir(P.USUARIO_ID, String.valueOf(usuario.usuario_id));
                    P.inserir(P.USUARIO_NOME, usuario.nome);
                    P.inserir(P.USUARIO_LOGIN, usuario.login);
                    P.inserir(P.USUARIO_AUTENTICACAO, usuario.autenticacao);
                    listener.sucesso(usuario);
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if (error instanceof NoConnectionError) {
                listener.sucesso(P.getUsuarioInstance());
            } else {
                listener.erro(error);
            }
        }
    }
    );
    AppController.getInstance().addToRequestQueue(request);
}
项目:minhaeiro    文件:Pessoa.java   
public static void excluir(final Pessoa pessoa, final ApiListener listener) {
    String url = ApiRoutes.PESSOA.Delete(pessoa.pessoa_id);
    final int metodo = Request.Method.DELETE;
    StringRequest request = new StringRequest(
            metodo,
            url,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    Pessoa resposta = new Gson().fromJson(response, Pessoa.class);
                    Pessoa.excluir(pessoa);
                    listener.sucesso(resposta);
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    if (error instanceof NoConnectionError) {
                        Pessoa.excluir(pessoa);
                        Requisicao.adicionar(new Requisicao(metodo, Requisicao.PESSOA, new Gson().toJson(pessoa)));
                        listener.sucesso(pessoa);
                    } else {
                        listener.erro(error);
                    }
                }
            }
    );
    AppController.getInstance().addToRequestQueue(request);
}
项目:minhaeiro    文件:Pessoa.java   
public static void cadastrar(final Pessoa pessoa, final ApiListener listener) {
    String url = ApiRoutes.PESSOA.Post();
    final int metodo = Request.Method.POST;
    JsonObjectRequest request = new JsonObjectRequest(
            metodo,
            url,
            new JSONObject(pessoa.toParams()),
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    Pessoa resposta = new Gson().fromJson(response.toString(), Pessoa.class);
                    Pessoa.cadastrar(pessoa);
                    listener.sucesso(resposta);
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    if (error instanceof NoConnectionError) {
                        Pessoa p = Pessoa.cadastrar(pessoa);
                        Requisicao.adicionar(new Requisicao(metodo, Requisicao.PESSOA, new Gson().toJson(p)));
                        listener.sucesso(p);
                    } else {
                        listener.erro(error);
                    }
                }
            }
    );
    AppController.getInstance().addToRequestQueue(request);
}
项目:minhaeiro    文件:Pessoa.java   
public static void editar(final Pessoa pessoa, final ApiListener listener) {
    String url = ApiRoutes.PESSOA.Put(pessoa.pessoa_id);
    final int metodo = Request.Method.PUT;
    JsonObjectRequest request = new JsonObjectRequest(
            metodo,
            url,
            new JSONObject(pessoa.toParams()),
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    Pessoa resposta = new Gson().fromJson(response.toString(), Pessoa.class);
                    Pessoa.editar(pessoa);
                    listener.sucesso(resposta);
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    if (error instanceof NoConnectionError) {
                        Pessoa p = Pessoa.editar(pessoa);
                        Requisicao.adicionar(new Requisicao(metodo, Requisicao.PESSOA, new Gson().toJson(p)));
                        listener.sucesso(p);
                    } else {
                        listener.erro(error);
                    }
                }
            }
    );
    AppController.getInstance().addToRequestQueue(request);
}
项目:yun2win-sdk-android    文件:MyErrorMessage.java   
public MyErrorMessage(VolleyError e) {
    if (e instanceof NoConnectionError) {
        code = MyErrorMessage.ERROR_NO_CONNECTION;
        message = "Network No Connection";
    } else if (e instanceof NetworkError) {
        code = MyErrorMessage.ERROR_NETWORK;
        message = "Network Error";
    } else if (e instanceof TimeoutError) {
        code = MyErrorMessage.ERROR_TIMEOUT;
        message = "Timeout Error";
    } else if (e instanceof ParseError) {
        code = MyErrorMessage.ERROR_PARSE;
        message = "Xml Parser Error";
    } else if (e instanceof ServerError) {
        code = MyErrorMessage.ERROR_SERVER;
        message = "Server Responded with an error response";
    } else if (e instanceof MyErrorMessage){
        MyErrorMessage msg = (MyErrorMessage) e;
        code = msg.code;
        message = msg.message;
    } else {
        code = MyErrorMessage.ERROR_UNKNOWN;
        message = e.getMessage();
        if(message.contains("INTERNET")) {
            android.os.Process.killProcess(android.os.Process.myPid());
        }
    }
}