Search in sources :

Example 11 with StringRequest

use of com.android.volley.toolbox.StringRequest 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 12 with StringRequest

use of com.android.volley.toolbox.StringRequest 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)

Example 13 with StringRequest

use of com.android.volley.toolbox.StringRequest 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 14 with StringRequest

use of com.android.volley.toolbox.StringRequest 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 15 with StringRequest

use of com.android.volley.toolbox.StringRequest in project WordPress-Android by wordpress-mobile.

the class ReaderPostActions method bumpPageViewForPost.

public static void bumpPageViewForPost(SiteStore siteStore, ReaderPost post) {
    if (post == null) {
        return;
    }
    // don't bump stats for posts in sites the current user is an admin of, unless
    // this is a private post since we count views for private posts from owner or member
    SiteModel site = siteStore.getSiteBySiteId(post.blogId);
    // site will be null here if the user is not the owner or a member of the site
    if (site != null && !post.isPrivate) {
        AppLog.d(T.READER, "skipped bump page view - user is admin");
        return;
    }
    Response.Listener<String> listener = new Response.Listener<String>() {

        @Override
        public void onResponse(String response) {
            AppLog.d(T.READER, "bump page view succeeded");
        }
    };
    Response.ErrorListener errorListener = new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError volleyError) {
            AppLog.e(T.READER, volleyError);
            AppLog.w(T.READER, "bump page view failed");
        }
    };
    Request request = new StringRequest(Request.Method.GET, getTrackingPixelForPost(post), listener, errorListener) {

        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            // call will fail without correct refer(r)er
            Map<String, String> headers = new HashMap<>();
            headers.put("Referer", TRACKING_REFERRER);
            return headers;
        }
    };
    WordPress.sRequestQueue.add(request);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) UpdateResultListener(org.wordpress.android.ui.reader.actions.ReaderActions.UpdateResultListener) HashMap(java.util.HashMap) StringRequest(com.android.volley.toolbox.StringRequest) RestRequest(com.wordpress.rest.RestRequest) StringRequest(com.android.volley.toolbox.StringRequest) Request(com.android.volley.Request) SiteModel(org.wordpress.android.fluxc.model.SiteModel)

Aggregations

StringRequest (com.android.volley.toolbox.StringRequest)18 VolleyError (com.android.volley.VolleyError)16 Response (com.android.volley.Response)14 JSONObject (org.json.JSONObject)5 JSONException (org.json.JSONException)4 Uri (android.net.Uri)3 Gson (com.google.gson.Gson)3 HashMap (java.util.HashMap)3 Request (com.android.volley.Request)2 RequestQueue (com.android.volley.RequestQueue)2 ImageLoader (com.android.volley.toolbox.ImageLoader)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 DownloadManager (android.app.DownloadManager)1 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 AsyncTask (android.os.AsyncTask)1 Nullable (android.support.annotation.Nullable)1 View (android.view.View)1 ImageButton (android.widget.ImageButton)1