com.android.volley.toolbox.JsonArrayRequest Java Examples

The following examples show how to use com.android.volley.toolbox.JsonArrayRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: separadorbraga.java    From LuxVilla with Apache License 2.0 6 votes vote down vote up
private void sendjsonRequest(){

        JsonArrayRequest jsonArrayRequest=new JsonArrayRequest(Request.Method.GET,"http://brunoferreira.esy.es/serverdata.php",null, new Response.Listener<JSONArray>() {
            @Override
            public void onResponse(JSONArray response) {
                casas=parsejsonResponse(response);
                adaptador.setCasas(casas);
                progressBar.setVisibility(View.GONE);
                swipeRefreshLayout.setVisibility(View.VISIBLE);

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                progressBar.setVisibility(View.GONE);
                swipeRefreshLayout.setVisibility(View.VISIBLE);
                Snackbar.make(recyclerViewtodas,"Falha ao ligar ao servidor",Snackbar.LENGTH_LONG).show();

            }
        });

        requestQueue.add(jsonArrayRequest);
    }
 
Example #2
Source File: ArticleAPIImpl.java    From the-tech-frontier-app with MIT License 6 votes vote down vote up
private void performRequest(final int page, int category,
        final DataListener<List<Article>> listener, ErrorListener errorListener) {
    JsonArrayRequest request = new JsonArrayRequest(
            "http://www.devtf.cn/api/v1/?type=articles&page=" + mPage + "&count=20&categoty="
                    + category,
            new Listener<JSONArray>() {

                @Override
                public void onResponse(JSONArray jsonArray) {
                    if (listener != null) {
                        // 解析结果
                        listener.onComplete(mRespHandler.parse(jsonArray));
                    }
                }
            }, errorListener);
    RequestQueueMgr.getRequestQueue().add(request);
}
 
Example #3
Source File: RecomendAPIImpl.java    From the-tech-frontier-app with MIT License 6 votes vote down vote up
@Override
public void fetchRecomends(final DataListener<List<Recommend>> listener) {
    JsonArrayRequest request = new JsonArrayRequest(
            "http://www.devtf.cn/api/v1/?type=recommends",
            new Listener<JSONArray>() {

                @Override
                public void onResponse(JSONArray jsonArray) {
                    if (listener != null) {
                        // 解析结果
                        listener.onComplete(mRespHandler.parse(jsonArray));
                    }
                }
            }, null);
    performRequest(request);
}
 
Example #4
Source File: StoryCollectionService.java    From hex with Apache License 2.0 6 votes vote down vote up
public List<Story> getStories(Collection collection) {
    String apiUrl = getUrlForCollection(collection);

    RequestFuture<JSONArray> future = RequestFuture.newFuture();
    JsonArrayRequest request = new JsonArrayRequest(mApiBaseUrl + apiUrl, future, future);
    request.setRetryPolicy(RetryPolicyFactory.build());

    mRequestQueue.add(request);

    try {
        JSONArray response = future.get();
        return FrontPageMarshaller.marshall(response);
    } catch (Exception e) {
        return null;
    }
}
 
Example #5
Source File: MainActivity.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
public void btnClick3(View view){
    JsonArrayRequest request = new JsonArrayRequest(Request.Method.GET, "", null
            , new Response.Listener<JSONArray>() {
        @Override
        public void onResponse(JSONArray response) {

        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {

        }
    });

    queue.add(request);

}
 
Example #6
Source File: searchableactivity.java    From LuxVilla with Apache License 2.0 6 votes vote down vote up
private void sendjsonRequest(){

        JsonArrayRequest jsonArrayRequest=new JsonArrayRequest(Request.Method.GET,"http://brunoferreira.esy.es/serverdata.php",null, new Response.Listener<JSONArray>() {
            @Override
            public void onResponse(JSONArray response) {
                casas=parsejsonResponse(response);
                adaptador.setCasas(casas);

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Snackbar.make(rvc1,"Falha ao ligar ao servidor",Snackbar.LENGTH_LONG).show();

            }
        });

        requestQueue.add(jsonArrayRequest);
    }
 
Example #7
Source File: separadorporto.java    From LuxVilla with Apache License 2.0 6 votes vote down vote up
private void sendjsonRequest(){

        JsonArrayRequest jsonArrayRequest=new JsonArrayRequest(Request.Method.GET,"http://brunoferreira.esy.es/serverdata.php",null, new Response.Listener<JSONArray>() {
            @Override
            public void onResponse(JSONArray response) {
                casas=parsejsonResponse(response);
                adaptador.setCasas(casas);
                progressBar.setVisibility(View.GONE);
                swipeRefreshLayout.setVisibility(View.VISIBLE);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                progressBar.setVisibility(View.GONE);
                swipeRefreshLayout.setVisibility(View.VISIBLE);
                Snackbar.make(recyclerViewtodas,"Falha ao ligar ao servidor",Snackbar.LENGTH_LONG).show();

            }
        });

        requestQueue.add(jsonArrayRequest);
    }
 
Example #8
Source File: separadoraveiro.java    From LuxVilla with Apache License 2.0 6 votes vote down vote up
private void sendjsonRequest(){

        JsonArrayRequest jsonArrayRequest=new JsonArrayRequest(Request.Method.GET,"http://brunoferreira.esy.es/serverdata.php",null, new Response.Listener<JSONArray>() {
            @Override
            public void onResponse(JSONArray response) {
                casas=parsejsonResponse(response);
                adaptador.setCasas(casas);
                progressBar.setVisibility(View.GONE);
                swipeRefreshLayout.setVisibility(View.VISIBLE);

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                progressBar.setVisibility(View.GONE);
                swipeRefreshLayout.setVisibility(View.VISIBLE);
                Snackbar.make(recyclerViewtodas,"Falha ao ligar ao servidor",Snackbar.LENGTH_LONG).show();

            }
        });

        requestQueue.add(jsonArrayRequest);
    }
 
Example #9
Source File: separadorlikes.java    From LuxVilla with Apache License 2.0 6 votes vote down vote up
private void sendjsonRequest(){

        JsonArrayRequest jsonArrayRequest=new JsonArrayRequest(Request.Method.GET,"http://brunoferreira.esy.es/serverdata.php",null, new Response.Listener<JSONArray>() {
            @Override
            public void onResponse(JSONArray response) {
                casas=parsejsonResponse(response);
                adaptador.setCasas(casas);
                progressBar.setVisibility(View.GONE);
                swipeRefreshLayout.setVisibility(View.VISIBLE);

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                progressBar.setVisibility(View.GONE);
                swipeRefreshLayout.setVisibility(View.VISIBLE);
                Snackbar.make(recyclerViewtodas,"Falha ao ligar ao servidor",Snackbar.LENGTH_LONG).show();

            }
        });

        requestQueue.add(jsonArrayRequest);
    }
 
Example #10
Source File: separadortodas.java    From LuxVilla with Apache License 2.0 6 votes vote down vote up
private void sendjsonRequest(){

        JsonArrayRequest jsonArrayRequest=new JsonArrayRequest(Request.Method.GET,"http://brunoferreira.esy.es/serverdata.php",null, new Response.Listener<JSONArray>() {
            @Override
            public void onResponse(JSONArray response) {
                casas=parsejsonResponse(response);
                adaptador.setCasas(casas);
                progressBar.setVisibility(View.GONE);
                swipeRefreshLayout.setVisibility(View.VISIBLE);

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                progressBar.setVisibility(View.GONE);
                swipeRefreshLayout.setVisibility(View.VISIBLE);
                Snackbar.make(recyclerViewtodas,"Falha ao ligar ao servidor",Snackbar.LENGTH_LONG).show();

            }
        });

        requestQueue.add(jsonArrayRequest);
    }
 
Example #11
Source File: VolleyHelper.java    From AndroidLinkup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 加载JsonArray数据
 * 
 * @param url
 *            url地址
 * @param listener
 *            网络消息处理监听器
 */
public void getJsonArray(String url, final NetMsgListener<JSONArray> listener) {

    JsonArrayRequest jsonObjectRequest = new JsonArrayRequest(url, new Response.Listener<JSONArray>() {
        @Override
        public void onResponse(JSONArray response) {
            if (listener != null) {
                listener.onNetMsg(response);
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError e) {
            if (listener != null) {
                listener.onError(e);
            }
        }
    });
    requestQueue.add(jsonObjectRequest);
}
 
Example #12
Source File: TechFragment.java    From android-kubernetes-blockchain with Apache License 2.0 6 votes vote down vote up
public void requestPages() {
    JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, BACKEND_URL + "/pages", null,
            new Response.Listener<JSONArray>() {
                @Override
                public void onResponse(JSONArray response) {
                    articles.clear();
                    ArticleModel[] articleModels = gson.fromJson(response.toString(), ArticleModel[].class);
                    articles.addAll(Arrays.asList(articleModels));
                    adapter.notifyDataSetChanged();
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.d(TAG, "That didn't work!", error);
            articles.clear();
            articles.addAll(articlesDefault);
            adapter.notifyDataSetChanged();
        }
    });
    this.queue.add(jsonArrayRequest);
}
 
Example #13
Source File: LeaderboardsFragment.java    From android-kubernetes-blockchain with Apache License 2.0 6 votes vote down vote up
public void getLeaderboardTop(int number) {
    JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, BACKEND_URL + "/leaderboard/top/" + String.valueOf(number) , null,
            new Response.Listener<JSONArray>() {
                @Override
                public void onResponse(JSONArray response) {
                    UserInfoModel[] dataModels = gson.fromJson(response.toString(), UserInfoModel[].class);
                    userInfoModels.clear();
                    userInfoModels.addAll(Arrays.asList(dataModels));
                    adapter.notifyDataSetChanged();
                    loadingToast.cancel();
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.d(TAG, "That didn't work!");
        }
    });
    queue.add(jsonArrayRequest);
}
 
Example #14
Source File: JsonRequestCharsetTest.java    From CrossBow with Apache License 2.0 5 votes vote down vote up
@Test public void specifiedCharsetJsonArray() throws Exception {
    byte[] data = jsonArrayString().getBytes(Charset.forName("ISO-8859-2"));
    Map<String, String> headers = new HashMap<String, String>();
    headers.put("Content-Type", "application/json; charset=iso-8859-2");
    NetworkResponse network = new NetworkResponse(data, headers);
    JsonArrayRequest arrayRequest = new JsonArrayRequest("", null, null);
    Response<JSONArray> arrayResponse = arrayRequest.parseNetworkResponse(network);

    assertNotNull(arrayResponse);
    assertTrue(arrayResponse.isSuccess());
    assertEquals(TEXT_VALUE, arrayResponse.result.getString(TEXT_INDEX));
    // don't check the copyright symbol, ISO-8859-2 doesn't have it, but it has Czech characters
}
 
Example #15
Source File: JsonRequestCharsetTest.java    From product-emm with Apache License 2.0 5 votes vote down vote up
@Test public void specifiedCharsetJsonArray() throws Exception {
    byte[] data = jsonArrayString().getBytes(Charset.forName("ISO-8859-2"));
    Map<String, String> headers = new HashMap<String, String>();
    headers.put("Content-Type", "application/json; charset=iso-8859-2");
    NetworkResponse network = new NetworkResponse(data, headers);
    JsonArrayRequest arrayRequest = new JsonArrayRequest("", null, null);
    Response<JSONArray> arrayResponse = arrayRequest.parseNetworkResponse(network);

    assertNotNull(arrayResponse);
    assertTrue(arrayResponse.isSuccess());
    assertEquals(TEXT_VALUE, arrayResponse.result.getString(TEXT_INDEX));
    // don't check the copyright symbol, ISO-8859-2 doesn't have it, but it has Czech characters
}
 
Example #16
Source File: JsonRequestCharsetTest.java    From product-emm with Apache License 2.0 5 votes vote down vote up
@Test public void defaultCharsetJsonArray() throws Exception {
    // UTF-8 is default charset for JSON
    byte[] data = jsonArrayString().getBytes(Charset.forName("UTF-8"));
    NetworkResponse network = new NetworkResponse(data);
    JsonArrayRequest arrayRequest = new JsonArrayRequest("", null, null);
    Response<JSONArray> arrayResponse = arrayRequest.parseNetworkResponse(network);

    assertNotNull(arrayResponse);
    assertTrue(arrayResponse.isSuccess());
    assertEquals(TEXT_VALUE, arrayResponse.result.getString(TEXT_INDEX));
    assertEquals(COPY_VALUE, arrayResponse.result.getString(COPY_INDEX));
}
 
Example #17
Source File: JsonRequestCharsetTest.java    From product-emm with Apache License 2.0 5 votes vote down vote up
@Test public void specifiedCharsetJsonArray() throws Exception {
    byte[] data = jsonArrayString().getBytes(Charset.forName("ISO-8859-2"));
    Map<String, String> headers = new HashMap<String, String>();
    headers.put("Content-Type", "application/json; charset=iso-8859-2");
    NetworkResponse network = new NetworkResponse(data, headers);
    JsonArrayRequest arrayRequest = new JsonArrayRequest("", null, null);
    Response<JSONArray> arrayResponse = arrayRequest.parseNetworkResponse(network);

    assertNotNull(arrayResponse);
    assertTrue(arrayResponse.isSuccess());
    assertEquals(TEXT_VALUE, arrayResponse.result.getString(TEXT_INDEX));
    // don't check the copyright symbol, ISO-8859-2 doesn't have it, but it has Czech characters
}
 
Example #18
Source File: JsonRequestCharsetTest.java    From product-emm with Apache License 2.0 5 votes vote down vote up
@Test public void defaultCharsetJsonArray() throws Exception {
    // UTF-8 is default charset for JSON
    byte[] data = jsonArrayString().getBytes(Charset.forName("UTF-8"));
    NetworkResponse network = new NetworkResponse(data);
    JsonArrayRequest arrayRequest = new JsonArrayRequest("", null, null);
    Response<JSONArray> arrayResponse = arrayRequest.parseNetworkResponse(network);

    assertNotNull(arrayResponse);
    assertTrue(arrayResponse.isSuccess());
    assertEquals(TEXT_VALUE, arrayResponse.result.getString(TEXT_INDEX));
    assertEquals(COPY_VALUE, arrayResponse.result.getString(COPY_INDEX));
}
 
Example #19
Source File: JsonRequestCharsetTest.java    From CrossBow with Apache License 2.0 5 votes vote down vote up
@Test public void defaultCharsetJsonArray() throws Exception {
    // UTF-8 is default charset for JSON
    byte[] data = jsonArrayString().getBytes(Charset.forName("UTF-8"));
    NetworkResponse network = new NetworkResponse(data);
    JsonArrayRequest arrayRequest = new JsonArrayRequest("", null, null);
    Response<JSONArray> arrayResponse = arrayRequest.parseNetworkResponse(network);

    assertNotNull(arrayResponse);
    assertTrue(arrayResponse.isSuccess());
    assertEquals(TEXT_VALUE, arrayResponse.result.getString(TEXT_INDEX));
    assertEquals(COPY_VALUE, arrayResponse.result.getString(COPY_INDEX));
}
 
Example #20
Source File: JobAPIImpl.java    From the-tech-frontier-app with MIT License 5 votes vote down vote up
private void performRequest(final DataListener<List<Job>> listener,  ErrorListener errorListener) {
    JsonArrayRequest request = new JsonArrayRequest(
            "http://www.devtf.cn/api/v1/?type=jobs",
            new Listener<JSONArray>() {

                @Override
                public void onResponse(JSONArray jsonArray) {
                    if (listener != null) {
                        // 解析结果
                        listener.onComplete(mRespHandler.parse(jsonArray));
                    }
                }
            }, null);
    performRequest(request);
}
 
Example #21
Source File: JsonRequestCharsetTest.java    From device-database with Apache License 2.0 5 votes vote down vote up
@Test public void specifiedCharsetJsonArray() throws Exception {
    byte[] data = jsonArrayString().getBytes(Charset.forName("ISO-8859-2"));
    Map<String, String> headers = new HashMap<String, String>();
    headers.put("Content-Type", "application/json; charset=iso-8859-2");
    NetworkResponse network = new NetworkResponse(data, headers);
    JsonArrayRequest arrayRequest = new JsonArrayRequest("", null, null);
    Response<JSONArray> arrayResponse = arrayRequest.parseNetworkResponse(network);

    assertNotNull(arrayResponse);
    assertTrue(arrayResponse.isSuccess());
    assertEquals(TEXT_VALUE, arrayResponse.result.getString(TEXT_INDEX));
    // don't check the copyright symbol, ISO-8859-2 doesn't have it, but it has Czech characters
}
 
Example #22
Source File: JsonRequestCharsetTest.java    From device-database with Apache License 2.0 5 votes vote down vote up
@Test public void defaultCharsetJsonArray() throws Exception {
    // UTF-8 is default charset for JSON
    byte[] data = jsonArrayString().getBytes(Charset.forName("UTF-8"));
    NetworkResponse network = new NetworkResponse(data);
    JsonArrayRequest arrayRequest = new JsonArrayRequest("", null, null);
    Response<JSONArray> arrayResponse = arrayRequest.parseNetworkResponse(network);

    assertNotNull(arrayResponse);
    assertTrue(arrayResponse.isSuccess());
    assertEquals(TEXT_VALUE, arrayResponse.result.getString(TEXT_INDEX));
    assertEquals(COPY_VALUE, arrayResponse.result.getString(COPY_INDEX));
}
 
Example #23
Source File: PlaceSearchReviewFragment.java    From Place-Search-Service with MIT License 4 votes vote down vote up
public  void yelpRequest(Details details,View view){
    String formmatted_address = details.getFormatted_address();
    parsedAdd = formmatted_address.split(",");
    place_name = details.getName();
    Log.v("add list", parsedAdd.toString());
    address1 = parsedAdd[0];
    address2 = parsedAdd[1].trim() + "," + parsedAdd[2].trim();
    city = parsedAdd[parsedAdd.length - 3].trim();
    String[] arr2 = parsedAdd[parsedAdd.length - 2].split(" ");
    state = arr2[1].trim();

    reviewAdapter = new PlaceSearchReviewAdapter(context, details.getReviews());
    list_review.setAdapter(reviewAdapter);

    //Getting the instance of Spinner and applying OnItemSelectedListener on it
    Spinner type_spin = (Spinner) view.findViewById(R.id.review_type);
    type_spin.setOnItemSelectedListener(this);
    order_spin = (Spinner) view.findViewById(R.id.review_order);
    order_spin.setOnItemSelectedListener(this);

    //Creating the ArrayAdapter instance having the  list
    ArrayAdapter aa1 = new ArrayAdapter(context, android.R.layout.simple_spinner_item, reviewType);
    aa1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    //Setting the ArrayAdapter data on the Spinner
    type_spin.setAdapter(aa1);

    //Creating the ArrayAdapter instance having the  list
    ArrayAdapter aa2 = new ArrayAdapter(context, android.R.layout.simple_spinner_item, reviewOrder);
    aa2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    //Setting the ArrayAdapter data on the Spinner
    order_spin.setAdapter(aa2);



    // request yelp review
    String yelpUrl = "http://placesearch-env.us-west-1.elasticbeanstalk.com/yelp/?address1=";
    yelpUrl += URLEncoder.encode(address1) + "&address2=" + URLEncoder.encode(address2 )+ "&city=" + URLEncoder.encode(city) + "&name=" + URLEncoder.encode(place_name) + "&state=" + state;
    Log.v("yelpURl", yelpUrl);


    JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(
            Request.Method.GET,
            yelpUrl,
            null,
            new Response.Listener<JSONArray>() {
                @Override
                public void onResponse(JSONArray response) {
                    yelpReviewRes = response;
                    originYelpReviewRes = response;
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Toast.makeText(getContext(),"API failure",Toast.LENGTH_LONG).show();

                }
            }
    );
    Volley.newRequestQueue(context).add(jsonArrayRequest);
}
 
Example #24
Source File: UpdateUtil.java    From OpenCircle with GNU General Public License v3.0 4 votes vote down vote up
public static void requestContent(final Context ctx, String url, final String table, final String tag_json_obj){

        JsonArrayRequest jsonObjReq = new JsonArrayRequest(url,
                new Response.Listener<JSONArray>() {

                    @Override
                    public void onResponse(JSONArray array) {

                        addContent(array, table, ctx);

                    }
                }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                VolleyLog.d("Service", "Error: " + error);

            }
        });

        // Adding request to request queue
        CircleOf6Application.getInstance().addToRequestQueue(jsonObjReq, tag_json_obj);

    }
 
Example #25
Source File: NotifierService.java    From qBittorrent-Controller with MIT License 4 votes vote down vote up
private List getTorrentList(final String state, final TorrentsListCallBack callback) {

        final List<Torrent> torrents = new ArrayList<>();

        String url = "";

        // if server is publish in a subfolder, fix url
        if (subfolder != null && !subfolder.equals("")) {
            url = subfolder + "/" + url;
        }

        url = protocol + "://" + hostname + ":" + port + url;

        // Command
        url = url + "/api/v2/torrents/info";

        url = url + "?filter=" + state;

        //Log.d("Debug: ", "GetAllTorrents NS - URL: " + url);
        //Log.d("Debug: ", "GetAllTorrents NS - cookies: " + cookie);

        JsonArrayRequest jsArrayRequest = new JsonArrayRequest(
                Request.Method.GET,
                url,
                null,
                new Response.Listener<JSONArray>() {
                    @Override
                    public void onResponse(JSONArray response) {

                        // Get list type to parse it
                        Type listType = new TypeToken<List<Torrent>>() {
                        }.getType();

                        // Parse Lists using Gson
                        torrents.addAll((List<Torrent>) new Gson().fromJson(response.toString(), listType));

                        // Return value
                        callback.onSuccess(torrents);

                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        // Log status code
                        NetworkResponse networkResponse = error.networkResponse;
                        if (networkResponse != null) {
                            Log.d("Debug", "getAllTorrents NS - statusCode: " + networkResponse.statusCode);
                        }

                        // Log error
                        Log.d("Debug", "getAllTorrents NS - Error in JSON response: " + error.getMessage());
                    }
                }

        ) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                Map<String, String> params = new HashMap<>();
                params.put("User-Agent", "qBittorrent for Android");
                params.put("Host", hostname + ":" + port);
                params.put("Referer", protocol + "://" + hostname + ":" + port);
                params.put("Content-Type", "application/x-www-form-urlencoded");
                params.put("Cookie", cookie);
                return params;
            }
        };

        // Add request to te queue
        addVolleyRequest(jsArrayRequest);

        // Return the lists
        return torrents;
    }
 
Example #26
Source File: NotifierService.java    From qBittorrent-Controller with MIT License 4 votes vote down vote up
protected void addVolleyRequest(JsonArrayRequest jsArrayRequest) {
    VolleySingleton.getInstance(context).addToRequestQueueHttps(jsArrayRequest, keystore_path, keystore_password);
}
 
Example #27
Source File: TorrentDetailsFragment.java    From qBittorrent-Controller with MIT License 4 votes vote down vote up
private List getTorrentTrackers(final TrackersListCallback callback) {

        final List<Tracker> trackers = new ArrayList<>();

        String url = "";

        // if server is publish in a subfolder, fix url
        if (subfolder != null && !subfolder.equals("")) {
            url = subfolder + "/" + url;
        }

        url = protocol + "://" + hostname + ":" + port + url;

        // Command
        url = url + "/api/v2/torrents/trackers?hash=" + hash;


        JsonArrayRequest jsArrayRequest = new JsonArrayRequest(
                Request.Method.GET,
                url,
                null,
                new Response.Listener<JSONArray>() {
                    @Override
                    public void onResponse(JSONArray response) {

                        // Get list type to parse itgetTorrentTrackers
                        Type listType = new TypeToken<List<Tracker>>() {
                        }.getType();

                        // Parse Lists using Gson
                        trackers.addAll((List<Tracker>) new Gson().fromJson(response.toString(), listType));

                        // Return value
                        callback.onSuccess(trackers);

                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {

                        // Log status code
                        NetworkResponse networkResponse = error.networkResponse;
                        if (networkResponse != null) {
                            Log.d("Debug", "getTorrentTrackers - statusCode: " + networkResponse.statusCode);
                        }

                        // Log error
                        Log.d("Debug", "getTorrentTrackers - Error in JSON response: " + error.getMessage());
                    }
                }

        ) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                Map<String, String> params = new HashMap<>();
                params.put("User-Agent", "qBittorrent for Android");
                //params.put("Host", hostname + ":" + port);
                params.put("Referer", protocol + "://" + hostname + ":" + port);
                params.put("Content-Type", "application/x-www-form-urlencoded");
                params.put("Cookie", cookie);
                return params;
            }
        };

        // Add request to te queue
        addVolleyRequest(jsArrayRequest);

        // Return the lists
        return trackers;
    }
 
Example #28
Source File: TorrentDetailsFragment.java    From qBittorrent-Controller with MIT License 4 votes vote down vote up
private List getTorrentContents(final ContentsListCallback callback) {

        final List<ContentFile> contentFiles = new ArrayList<>();

        String url = "";

        // if server is publish in a subfolder, fix url
        if (subfolder != null && !subfolder.equals("")) {
            url = subfolder + "/" + url;
        }

        url = protocol + "://" + hostname + ":" + port + url;

        // Command

        url = url + "/api/v2/torrents/files?hash=" + hash;

        JsonArrayRequest jsArrayRequest = new JsonArrayRequest(
                Request.Method.GET,
                url,
                null,
                new Response.Listener<JSONArray>() {
                    @Override
                    public void onResponse(JSONArray response) {

                        // Get list type to parse it
                        Type listType = new TypeToken<List<ContentFile>>() {
                        }.getType();

                        // Parse Lists using Gson
                        contentFiles.addAll((List<ContentFile>) new Gson().fromJson(response.toString(), listType));

                        // Return value
                        callback.onSuccess(contentFiles);

                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {

                        // Log status code
                        NetworkResponse networkResponse = error.networkResponse;
                        if (networkResponse != null) {
                            Log.d("Debug", "getTorrentContents - statusCode: " + networkResponse.statusCode);
                        }

                        // Log error
                        Log.d("Debug", "getTorrentContents - Error in JSON response: " + error.getMessage());

                    }
                }

        ) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                Map<String, String> params = new HashMap<>();
                params.put("User-Agent", "qBittorrent for Android");
                //params.put("Host", hostname + ":" + port);
                params.put("Referer", protocol + "://" + hostname + ":" + port);
                params.put("Content-Type", "application/x-www-form-urlencoded");
                params.put("Cookie", cookie);
                return params;
            }
        };

        // Add request to te queue
        addVolleyRequest(jsArrayRequest);

        // Return the lists
        return contentFiles;
    }
 
Example #29
Source File: TorrentDetailsFragment.java    From qBittorrent-Controller with MIT License 4 votes vote down vote up
protected void addVolleyRequest(JsonArrayRequest jsArrayRequest) {
    VolleySingleton.getInstance(getActivity().getApplication()).addToRequestQueueHttps(jsArrayRequest, keystore_path, keystore_password);
}
 
Example #30
Source File: MainActivity.java    From ImageSliderWithSwipes with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mDemoSlider = (SliderLayout) findViewById(R.id.slider);

    // Creating volley request obj
    JsonArrayRequest billionaireReq = new JsonArrayRequest(getURL,
            new Response.Listener<JSONArray>() {
                @Override
                public void onResponse(JSONArray response) {
                    url_maps = new HashMap<String, String>();
                    // Parsing json
                    for (int i = 0; i < response.length(); i++) {
                        try {

                            JSONObject obj = response.getJSONObject(i);
                            url_maps.put(obj.getString("title") + " - " + obj.getString("releaseYear"), obj.getString("image"));

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }

                    for (String name : url_maps.keySet()) {
                        TextSliderView textSliderView = new TextSliderView(MainActivity.this);
                        // initialize a SliderLayout
                        textSliderView
                                .description(name)
                                .descriptionSize(12)
                                .image(url_maps.get(name))
                                .setScaleType(BaseSliderView.ScaleType.CenterCrop)
                                .setOnSliderClickListener(MainActivity.this);

                        //add your extra information
                        textSliderView.bundle(new Bundle());
                        textSliderView.getBundle().putString("extra", name);

                        mDemoSlider.addSlider(textSliderView);
                    }
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Toast.makeText(getApplicationContext(), "network issue: please enable wifi/mobile data + " + error, Toast.LENGTH_SHORT).show();
        }
    });

    // Adding request to request queue
    AppController.getInstance().addToRequestQueue(billionaireReq);

    mDemoSlider.setPresetTransformer(SliderLayout.Transformer.Stack);
    mDemoSlider.setPresetIndicator(SliderLayout.PresetIndicators.Center_Top);
    mDemoSlider.setCustomAnimation(new DescriptionAnimation());
    mDemoSlider.setDuration(4000);

    mDemoSlider.setPresetTransformer("Stack");

}