public class MyVolley {
private static MyVolley myVolley;
public static MyVolley newMyVolley(){
if(myVolley == null){
myVolley = new MyVolley();
}
return myVolley;
}
private static MyVolley myVolley;
public static MyVolley newMyVolley(){
if(myVolley == null){
myVolley = new MyVolley();
}
return myVolley;
}
private CallBack callBack;
private StringRequest stringRequest;
private Context context;
//string get
public void stringRequsetGet(Context context, String url, CallBack callBack){
RequestQueue queue = Volley.newRequestQueue(context);
this.callBack = callBack;
stringRequest = new StringRequest(Request.Method.GET, url, stringListener, errorListener);
queue.add(stringRequest);
}
//string post
public void stringRequestpost(Context context, String url, final Map map, CallBack callBack){
RequestQueue queue =Volley.newRequestQueue(context);
this.callBack = callBack;
stringRequest = new StringRequest(Request.Method.POST, url, stringListener, errorListener){
@Override
protected Map<String, String> getParams() throws AuthFailureError{
return map;
}
};
}
//string Listener
private Response.Listener<String> stringListener = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
// TODO Auto-generated method stub
callBack.onStringSuccess(response);
}
};
private StringRequest stringRequest;
private Context context;
//string get
public void stringRequsetGet(Context context, String url, CallBack callBack){
RequestQueue queue = Volley.newRequestQueue(context);
this.callBack = callBack;
stringRequest = new StringRequest(Request.Method.GET, url, stringListener, errorListener);
queue.add(stringRequest);
}
//string post
public void stringRequestpost(Context context, String url, final Map map, CallBack callBack){
RequestQueue queue =Volley.newRequestQueue(context);
this.callBack = callBack;
stringRequest = new StringRequest(Request.Method.POST, url, stringListener, errorListener){
@Override
protected Map<String, String> getParams() throws AuthFailureError{
return map;
}
};
}
//string Listener
private Response.Listener<String> stringListener = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
// TODO Auto-generated method stub
callBack.onStringSuccess(response);
}
};
//string Listener
private Response.ErrorListener errorListener = new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// TODO Auto-generated method stub
callBack.onFailure(error);
}
};
public interface CallBack{
public void onStringSuccess(String reponse);
public void onFailure(VolleyError error);
}
}
private Response.ErrorListener errorListener = new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// TODO Auto-generated method stub
callBack.onFailure(error);
}
};
public interface CallBack{
public void onStringSuccess(String reponse);
public void onFailure(VolleyError error);
}
}