Search in sources :

Example 11 with VolleyError

use of com.android.volley.VolleyError in project FastDev4Android by jiangqqlmj.

the class Fdv_JsonObjectRequest method post.

/**
     * 发送POST请求, 返回JSONObject对象数据
     * @param url    请求地址
     * @param listener  数据返回回调接口
     * @param params   POST请求参数
     */
public void post(String url, final Fdv_CallBackListener<JSONObject> listener, Map<String, String> params) {
    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url, null, new Response.Listener<JSONObject>() {

        @Override
        public void onResponse(JSONObject response) {
            if (listener != null) {
                listener.onSuccessResponse(response);
            }
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            if (listener != null) {
                listener.onErrorResponse(error);
            }
        }
    });
    addRequest(jsonObjectRequest, params);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) JSONObject(org.json.JSONObject) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest)

Example 12 with VolleyError

use of com.android.volley.VolleyError in project FastDev4Android by jiangqqlmj.

the class Fdv_StringRequest method get.

/**
     * 普通文本等信息 Get请求 无参数,或者get请求的参数直接拼接在URL上面
     * @param url  请求的地址
     * @param listener  数据请求返回接口回调
     */
public void get(String url, final Fdv_CallBackListener<String> listener) {
    StringRequest stringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {

        @Override
        public void onResponse(String response) {
            if (listener != null) {
                listener.onSuccessResponse(response);
            }
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            if (listener != null) {
                listener.onErrorResponse(error);
            }
        }
    });
    addRequest(stringRequest);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) StringRequest(com.android.volley.toolbox.StringRequest)

Example 13 with VolleyError

use of com.android.volley.VolleyError in project FastDev4Android by jiangqqlmj.

the class BasicNetwork method attemptRetryOnException.

/**
     * Attempts to prepare the request for a retry. If there are no more attempts remaining in the
     * request's retry policy, a timeout exception is thrown.
     * @param request The request to use.
     */
private static void attemptRetryOnException(String logPrefix, Request<?> request, VolleyError exception) throws VolleyError {
    RetryPolicy retryPolicy = request.getRetryPolicy();
    int oldTimeout = request.getTimeoutMs();
    try {
        retryPolicy.retry(exception);
    } catch (VolleyError e) {
        request.addMarker(String.format("%s-timeout-giveup [timeout=%s]", logPrefix, oldTimeout));
        throw e;
    }
    request.addMarker(String.format("%s-retry [timeout=%s]", logPrefix, oldTimeout));
}
Also used : VolleyError(com.android.volley.VolleyError) RetryPolicy(com.android.volley.RetryPolicy)

Example 14 with VolleyError

use of com.android.volley.VolleyError in project RxJava-Android-Samples by kaushikgopal.

the class VolleyDemoFragment method startVolleyRequest.

private void startVolleyRequest() {
    DisposableSubscriber<JSONObject> d = new DisposableSubscriber<JSONObject>() {

        @Override
        public void onNext(JSONObject jsonObject) {
            Log.e(TAG, "onNext " + jsonObject.toString());
            _log("onNext " + jsonObject.toString());
        }

        @Override
        public void onError(Throwable e) {
            VolleyError cause = (VolleyError) e.getCause();
            String s = new String(cause.networkResponse.data, Charset.forName("UTF-8"));
            Log.e(TAG, s);
            Log.e(TAG, cause.toString());
            _log("onError " + s);
        }

        @Override
        public void onComplete() {
            Log.e(TAG, "onCompleted");
            Timber.d("----- onCompleted");
            _log("onCompleted ");
        }
    };
    newGetRouteData().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(d);
    _disposables.add(d);
}
Also used : VolleyError(com.android.volley.VolleyError) JSONObject(org.json.JSONObject) DisposableSubscriber(io.reactivex.subscribers.DisposableSubscriber)

Example 15 with VolleyError

use of com.android.volley.VolleyError in project 9GAG by stormzhang.

the class ImageCacheManager method getImageListener.

public static ImageLoader.ImageListener getImageListener(final ImageView view, final Drawable defaultImageDrawable, final Drawable errorImageDrawable) {
    return new ImageLoader.ImageListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            if (errorImageDrawable != null) {
                view.setImageDrawable(errorImageDrawable);
            }
        }

        @Override
        public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) {
            if (response.getBitmap() != null) {
                if (!isImmediate && defaultImageDrawable != null) {
                    TransitionDrawable transitionDrawable = new TransitionDrawable(new Drawable[] { defaultImageDrawable, new BitmapDrawable(App.getContext().getResources(), response.getBitmap()) });
                    transitionDrawable.setCrossFadeEnabled(true);
                    view.setImageDrawable(transitionDrawable);
                    transitionDrawable.startTransition(100);
                } else {
                    view.setImageBitmap(response.getBitmap());
                }
            } else if (defaultImageDrawable != null) {
                view.setImageDrawable(defaultImageDrawable);
            }
        }
    };
}
Also used : VolleyError(com.android.volley.VolleyError) TransitionDrawable(android.graphics.drawable.TransitionDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Aggregations

VolleyError (com.android.volley.VolleyError)180 Response (com.android.volley.Response)121 JSONObject (org.json.JSONObject)104 HashMap (java.util.HashMap)70 JSONException (org.json.JSONException)66 JsonObjectRequest (com.android.volley.toolbox.JsonObjectRequest)61 RequestQueue (com.android.volley.RequestQueue)57 User (model.User)49 JSONArray (org.json.JSONArray)35 CustomRequestArray (dz.easy.androidclient.Util.CustomRequestArray)18 Context (android.content.Context)16 Toast (android.widget.Toast)16 StringRequest (com.android.volley.toolbox.StringRequest)16 RestRequest (com.wordpress.rest.RestRequest)16 CustomRequest (dz.easy.androidclient.Util.CustomRequest)12 TextView (android.widget.TextView)11 MockHttpStack (com.android.volley.mock.MockHttpStack)9 GsonRequest (com.android.volley.toolbox.GsonRequest)9 ImageContainer (com.android.volley.toolbox.ImageLoader.ImageContainer)9 Test (org.junit.Test)9