Android Open Source - Projectile Projectile Request






From Project

Back to project page Projectile.

License

The source code is released under:

Apache License

If you think the Android project Projectile listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.nicktate.projectile;
//from  www .  j  av a2 s.c om
import com.android.volley.AuthFailureError;
import com.android.volley.NetworkResponse;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.RetryPolicy;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.HttpHeaderParser;

import java.util.Map;

/**
 * Request Type for interfacing with the Projectile helper
 */
public class ProjectileRequest<T> extends Request<T> {
    ResponseListener<T> mListener;
    Map<String, String> mHeaders, mParams;
    Priority mPriority = Priority.NORMAL;

    public ProjectileRequest(int method, String url, Map<String, String> headers, Map<String, String> params, final ResponseListener<T> responseListener, Priority p, RetryPolicy retryPolicy, Object tag, boolean shouldCache) {
        super(method, url, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                if(responseListener != null) responseListener.onError(volleyError);
            }
        });

        mListener = responseListener;
        mHeaders = headers;
        mParams = params;
        mPriority = p;
        setRetryPolicy(retryPolicy);
        setTag(tag);
        setShouldCache(shouldCache);
    }

    @Override protected void deliverResponse(T response) {
        if(mListener != null) mListener.onResponse(response);
    }

    @Override
    public Map<String, String> getHeaders() throws AuthFailureError {
        return mHeaders != null ? mHeaders : super.getHeaders();
    }

    @Override
    public Map<String, String> getParams() throws AuthFailureError {
        return mParams != null ? mParams : super.getParams();
    }

    @Override
    public Priority getPriority() {
        return mPriority;
    }

    @Override
    protected Response<T> parseNetworkResponse(NetworkResponse networkResponse) {
        return Response.success(mListener != null ? mListener.responseParser(networkResponse) : null, HttpHeaderParser.parseCacheHeaders(networkResponse));
    }
}




Java Source Code List

com.nicktate.Sample.java
org.nicktate.projectile.JsonElementListener.java
org.nicktate.projectile.Method.java
org.nicktate.projectile.NetworkResponseListener.java
org.nicktate.projectile.OkHttpStack.java
org.nicktate.projectile.Priority.java
org.nicktate.projectile.ProjectileRequest.java
org.nicktate.projectile.Projectile.java
org.nicktate.projectile.ResponseListener.java
org.nicktate.projectile.StringListener.java