Android Open Source - photo-share-android Volley Helper






From Project

Back to project page photo-share-android.

License

The source code is released under:

Apache License

If you think the Android project photo-share-android 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 com.project.photoshare.utils.volley;
/* www . j  av a 2  s.  c  o  m*/
import android.content.Context;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.toolbox.HttpStack;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import com.project.photoshare.api.InputStreamRequest;
import com.project.photoshare.api.MultipartHurlStack;

import org.apache.http.HttpResponse;
import org.json.JSONObject;

import java.io.IOException;
import java.io.InputStream;
import java.util.Map;

/**
 *
 * @author <a href="mailto:">TakuyaKodama</a> (kodama-t)
 * @version 1.00 14/02/06 kodama-t
 */
public class VolleyHelper {

    private static RequestQueue mRequestQueue;
    private static RequestQueue mMultipartRequestQueue;

    public static RequestQueue getRequestQueue(Context context) {
        if(mRequestQueue == null) {
            mRequestQueue = Volley.newRequestQueue(context, new MultipartHurlStack());
        }
        return mRequestQueue;
    }

    public static RequestQueue getMultipartRequestQueue(Context context) {
        if (mMultipartRequestQueue == null) {
            mMultipartRequestQueue = Volley.newRequestQueue(context, new HttpStack() {
                @Override
                public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders) throws IOException, AuthFailureError {
                    return null;
                }
            });
        }
        return mMultipartRequestQueue;
    }

    public static void sendInputStreamRequest(Context context, String url) {
        sendInputStreamRequest(context, url, null, null);
    }

    public static void sendInputStreamRequest(Context context, String url,
                                              Response.Listener<InputStream> responseListener, Response.ErrorListener errorListener) {
        InputStreamRequest inputStreamRequest = new InputStreamRequest(url, responseListener, errorListener);

        getRequestQueue(context).add(inputStreamRequest);
    }

    public static void postJsonRequest(Context context, String url,
            Response.Listener<JSONObject> resoponseListener, Response.ErrorListener errorListener) {

        getRequestQueue(context).add(
                new JsonObjectRequest(Request.Method.POST, url, null, resoponseListener, errorListener)
        );
    }
}




Java Source Code List

com.project.photoshare.DefaultActivity.java
com.project.photoshare.DownloadPageFragment.java
com.project.photoshare.HistoryPageFragment.java
com.project.photoshare.InputPassword.java
com.project.photoshare.MainActivity.java
com.project.photoshare.MyPageFragment.java
com.project.photoshare.PasswordConfirmation.java
com.project.photoshare.SelectIsAddLater.java
com.project.photoshare.SplashActivity.java
com.project.photoshare.UploadCompleted.java
com.project.photoshare.UploadPageFragment.java
com.project.photoshare.api.ApiRequestService.java
com.project.photoshare.api.InputStreamRequest.java
com.project.photoshare.api.MultipartHurlStack.java
com.project.photoshare.api.MultipartJsonRequest.java
com.project.photoshare.listener.PostImageErrorListener.java
com.project.photoshare.listener.PostImageSuccessListener.java
com.project.photoshare.utils.BitmapDecodeLoader.java
com.project.photoshare.utils.ImageUtils.java
com.project.photoshare.utils.LogHelper.java
com.project.photoshare.utils.Utils.java
com.project.photoshare.utils.volley.LruImageCache.java
com.project.photoshare.utils.volley.VolleyHelper.java
com.project.photoshare.widget.CustomEditText.java