Search in sources :

Example 81 with Response

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

the class Fdv_StringRequest method post.

/**
     * 根据地址和请求参数 发送POST请求
     * @param url   地址服务器地址
     * @param listener  数据加载回调接口
     * @param params  请求参数
     */
public void post(String url, final Fdv_CallBackListener<String> listener, Map<String, String> params) {
    StringRequest stringRequest = new StringRequest(Request.Method.POST, 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, params);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) StringRequest(com.android.volley.toolbox.StringRequest)

Example 82 with Response

use of com.android.volley.Response in project AndroidNetworkDemo by dodocat.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    responseContentTextView = (TextView) findViewById(R.id.textViewResponseContent);
    StringRequest request = new StringRequest(Request.Method.GET, "https://kyfw.12306.cn/otn/", new Response.Listener<String>() {

        @Override
        public void onResponse(String response) {
            responseContentTextView.setText(response);
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            responseContentTextView.setText(error.toString());
        }
    });
    RequestManager.getInstance(this).addRequest(request, this);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) StringRequest(com.android.volley.toolbox.StringRequest)

Example 83 with Response

use of com.android.volley.Response in project MaterialCalendar by Haoxiqiang.

the class TabooProxy method fetchJSContent.

public static void fetchJSContent() {
    RequestQueue requestQueue = RQManager.getInstance().getRequestQueue();
    for (int i = (SAVEYEAR - 10); i < (SAVEYEAR + 10); i++) {
        final String datePrefix = String.valueOf(i);
        StringRequest stringRequest = new StringRequest(Method.GET, FETCHURL + datePrefix + ".js", new Response.Listener<String>() {

            @Override
            public void onResponse(String response) {
                String result = response.substring(response.indexOf("=") + 1, response.length() - 3) + "]";
                try {
                    AssetJSONLoad.json2file(datePrefix + ".json", result);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
            /* TODO Auto-generated method stub */
            }
        });
        requestQueue.add(stringRequest);
    }
    requestQueue.start();
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) RequestQueue(com.android.volley.RequestQueue) StringRequest(com.android.volley.toolbox.StringRequest) IOException(java.io.IOException)

Example 84 with Response

use of com.android.volley.Response in project MaterialCalendar by Haoxiqiang.

the class WeatherProxy method fetchWeatherContent.

public static void fetchWeatherContent(String dateParam) {
    StringRequest stringRequest = new StringRequest(Method.GET, WE, new Response.Listener<String>() {

        @Override
        public void onResponse(String response) {
            try {
                Logger.json(response);
                JSONObject result = new JSONObject(response);
                insertWeather(result);
            } catch (JSONException e) {
                Logger.d(e.getMessage());
            }
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
        /* TODO Auto-generated method stub */
        }
    });
    RequestQueue requestQueue = RQManager.getInstance().getRequestQueue();
    requestQueue.add(stringRequest);
    requestQueue.start();
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) JSONObject(org.json.JSONObject) RequestQueue(com.android.volley.RequestQueue) StringRequest(com.android.volley.toolbox.StringRequest) JSONException(org.json.JSONException)

Example 85 with Response

use of com.android.volley.Response in project MVCHelper by LuckyJayce.

the class BooksVolleyDataSource method loadHomeGroup.

private RequestHandle loadHomeGroup(final ResponseSender<List<Book>> sender, final int page) throws Exception {
    String url = "https://www.baidu.com";
    Uri.Builder builder = Uri.parse(url).buildUpon();
    builder.appendQueryParameter("page", String.valueOf(page));
    StringRequest jsonObjRequest = new StringRequest(Request.Method.GET, builder.toString(), new Response.Listener<String>() {

        @Override
        public void onResponse(String response) {
            List<Book> books = new ArrayList<Book>();
            for (int i = 0; i < 30; i++) {
                books.add(new Book("page" + page + "  Java编程思想 " + i, 108.00d));
            }
            mPage = page;
            sender.sendData(books);
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            sender.sendError(error);
        }
    });
    MyVolley.getRequestQueue().add(jsonObjRequest);
    return new VolleyRequestHandle(jsonObjRequest);
}
Also used : VolleyError(com.android.volley.VolleyError) StringRequest(com.android.volley.toolbox.StringRequest) Uri(android.net.Uri) Response(com.android.volley.Response) Book(com.shizhefei.test.models.enties.Book) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

Response (com.android.volley.Response)111 VolleyError (com.android.volley.VolleyError)109 JSONObject (org.json.JSONObject)81 JsonObjectRequest (com.android.volley.toolbox.JsonObjectRequest)61 RequestQueue (com.android.volley.RequestQueue)59 HashMap (java.util.HashMap)58 JSONException (org.json.JSONException)58 User (model.User)50 JSONArray (org.json.JSONArray)29 Context (android.content.Context)18 Toast (android.widget.Toast)18 CustomRequestArray (dz.easy.androidclient.Util.CustomRequestArray)18 StringRequest (com.android.volley.toolbox.StringRequest)14 TextView (android.widget.TextView)10 CustomRequest (dz.easy.androidclient.Util.CustomRequest)9 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)7 Intent (android.content.Intent)6 GridLayoutManager (android.support.v7.widget.GridLayoutManager)6 JsonArrayRequest (com.android.volley.toolbox.JsonArrayRequest)6 MaterialViewPagerHeaderDecorator (com.github.florent37.materialviewpager.header.MaterialViewPagerHeaderDecorator)5