Android Open Source - TAQueue Custom String Request






From Project

Back to project page TAQueue.

License

The source code is released under:

MIT License

If you think the Android project TAQueue 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.familybiz.greg.taqueue.network;
//ww  w.j a  va2 s. co m
import com.android.volley.AuthFailureError;
import com.android.volley.Response;
import com.android.volley.VolleyLog;
import com.android.volley.toolbox.StringRequest;

import java.io.UnsupportedEncodingException;
import java.util.Map;

/**
 * Template by fdoyle: https://gist.github.com/fdoyle/6424721
 */
public class CustomStringRequest extends StringRequest {

    public static final String PROTOCOL_CHARSET = "utf-8";
    private Map<String, String> headers;
    private String payload;

    public CustomStringRequest(int method, String url, Map<String, String> headers, String payload, Response.Listener<String> listener, Response.ErrorListener errorListener) {
        super(method, url, listener, errorListener);
        this.headers = headers;
        this.payload = payload;
    }

    public static CustomStringRequest get(String url, Map<String, String> headers, Response.Listener<String> listener, Response.ErrorListener errorListener) {
        CustomStringRequest request = new CustomStringRequest(Method.GET, url, headers, null, listener, errorListener);
        request.setTag(url);
        return request;
    }

    public static CustomStringRequest post(String url, Map<String, String> headers,  String payload, Response.Listener<String> listener, Response.ErrorListener errorListener) {
        CustomStringRequest request = new CustomStringRequest(Method.POST, url, headers,  payload, listener, errorListener);
        request.setTag(url);
        return request;
    }

    public static CustomStringRequest put(String url, Map<String, String> headers, String payload, Response.Listener<String> listener, Response.ErrorListener errorListener) {
        CustomStringRequest request = new CustomStringRequest(Method.PUT, url, headers, payload, listener, errorListener);
        request.setTag(url);
        return request;
    }

  public static CustomStringRequest delete(String url, Map<String, String> headers, Response.Listener<String> listener, Response.ErrorListener errorListener) {
    CustomStringRequest request = new CustomStringRequest(Method.DELETE, url, headers, null, listener, errorListener);
    request.setTag(url);
    return request;
  }


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

    @Override
    public byte[] getBody() {
        try {
            if(payload == null) {
                payload = "";
            }
            return payload.getBytes(PROTOCOL_CHARSET);
        }
        catch (UnsupportedEncodingException e) {
            VolleyLog.wtf("Unsupported Encoding while trying to get the bytes of %s using %s", payload, PROTOCOL_CHARSET);
            return null;
        }
    }

  @Override
    public String getBodyContentType() {
        return "application/json";
    }
}




Java Source Code List

com.familybiz.greg.taqueue.ApplicationTest.java
com.familybiz.greg.taqueue.MainActivity.java
com.familybiz.greg.taqueue.MoreInformationActivity.java
com.familybiz.greg.taqueue.NetworkTestFragment.java
com.familybiz.greg.taqueue.SettingsActivity.java
com.familybiz.greg.taqueue.model.Instructor.java
com.familybiz.greg.taqueue.model.School.java
com.familybiz.greg.taqueue.model.StudentQueue.java
com.familybiz.greg.taqueue.model.Student.java
com.familybiz.greg.taqueue.model.TA.java
com.familybiz.greg.taqueue.model.User.java
com.familybiz.greg.taqueue.model.queue.QueueData.java
com.familybiz.greg.taqueue.model.queue.QueueStudent.java
com.familybiz.greg.taqueue.model.queue.QueueTA.java
com.familybiz.greg.taqueue.network.CustomStringRequest.java
com.familybiz.greg.taqueue.network.NetworkRequest.java
com.familybiz.greg.taqueue.network.QueueRequest.java
com.familybiz.greg.taqueue.network.SchoolRequest.java
com.familybiz.greg.taqueue.network.StudentRequest.java
com.familybiz.greg.taqueue.network.TARequest.java
com.familybiz.greg.taqueue.view.lists.InstructorListFragment.java
com.familybiz.greg.taqueue.view.lists.ListFragment.java
com.familybiz.greg.taqueue.view.lists.QueueListFragment.java
com.familybiz.greg.taqueue.view.lists.SchoolListFragment.java
com.familybiz.greg.taqueue.view.login.LoginFragment.java
com.familybiz.greg.taqueue.view.login.StudentLoginFragment.java
com.familybiz.greg.taqueue.view.login.TALoginFragment.java
com.familybiz.greg.taqueue.view.queue.ColorableStudentArrayAdapter.java
com.familybiz.greg.taqueue.view.queue.ColorableTAArrayAdapter.java
com.familybiz.greg.taqueue.view.queue.QueueFragment.java
com.familybiz.greg.taqueue.view.queue.StudentQueueFragment.java
com.familybiz.greg.taqueue.view.queue.TAQueueFragment.java