Search in sources :

Example 66 with RequestQueue

use of com.android.volley.RequestQueue in project Douya by DreaminginCodeZH.

the class Volley method createAndStartRequestQueue.

/**
     * @see com.android.volley.toolbox.Volley#newRequestQueue(Context, HttpStack)
     */
private void createAndStartRequestQueue() {
    mRequestQueue = new RequestQueue(new DiskBasedCache(new File(DouyaApplication.getInstance().getCacheDir(), "volley")), new BasicNetwork(new HurlStack()));
    mRequestQueue.start();
}
Also used : RequestQueue(com.android.volley.RequestQueue) DiskBasedCache(com.android.volley.toolbox.DiskBasedCache) File(java.io.File)

Example 67 with RequestQueue

use of com.android.volley.RequestQueue in project J2ME-Loader by nikita36078.

the class HockeySender method send.

@Override
public void send(@NonNull Context context, @NonNull final CrashReportData report) {
    final String log = createCrashLog(report);
    String url = BASE_URL + FORM_KEY + CRASHES_PATH;
    RequestQueue queue = Volley.newRequestQueue(context);
    StringRequest postRequest = new StringRequest(Request.Method.POST, url, null, error -> Log.e(TAG, "Response error")) {

        @Override
        protected Map<String, String> getParams() {
            Map<String, String> params = new HashMap<>();
            params.put("raw", log);
            params.put("userID", report.getString(ReportField.INSTALLATION_ID));
            return params;
        }
    };
    postRequest.setShouldCache(false);
    queue.add(postRequest);
}
Also used : HashMap(java.util.HashMap) RequestQueue(com.android.volley.RequestQueue) StringRequest(com.android.volley.toolbox.StringRequest)

Example 68 with RequestQueue

use of com.android.volley.RequestQueue in project User-Behavior-in-Facebook by abozanona.

the class ActivityLog method getActivityLogData.

private void getActivityLogData(final long date, String log_filter) {
    final String userId = getSingleValue.getString("c_user", "");
    String url = "https://mbasic.facebook.com/" + userId + "/allactivity?log_filter=" + log_filter;
    url = "https://mbasic.facebook.com/" + userId + "/allactivity?log_filter=" + "cluster_11";
    Log.d("ActivityLog", url);
    new GetHtml(url) {

        @Override
        public void getHtmlListener(String html) {
            final ArrayList<String> links = new ArrayList<>();
            Document dom0 = Jsoup.parse(html);
            int day = Integer.parseInt((String) DateFormat.format("dd", date));
            int month = Integer.parseInt((String) DateFormat.format("MM", date));
            int year = Integer.parseInt(((String) DateFormat.format("yyyy", date)).substring(2));
            String _day = day + "";
            if (day < 10)
                _day = "0" + _day;
            String _month = month + "";
            if (month < 10)
                _month = "0" + _month;
            String divId = "#tlUnit_" + _month + "_" + _day + "_" + year;
            Elements tlUnit = dom0.select(divId);
            if (tlUnit == null) {
                return;
            }
            Elements dom = tlUnit.select("a");
            for (int i = 0; i < dom.size(); i++) {
                if (!dom.get(i).hasAttr("href"))
                    continue;
                String _link = dom.get(i).attr("href");
                if (_link != null) {
                    _link = replaceWithHash(_link);
                    if (_link.length() != 0) {
                        links.add(_link);
                    }
                }
            }
            if (links.size() != 0) {
                String url = "https://fba.ppu.edu/submitStudyResults.php";
                RequestQueue queue = Volley.newRequestQueue(MainActivity.instance);
                StringRequest postRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {

                    @Override
                    public void onResponse(String response) {
                        new DBHelper(context).setJsonData(links.toString());
                        Log.d("Response", response);
                    }
                }, new Response.ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                    }
                }) {

                    @Override
                    protected Map<String, String> getParams() {
                        String uuid = getSingleValue.getString("clientId", "");
                        if (uuid.equals("")) {
                            uuid = "mobile" + UUID.randomUUID().toString();
                            setSingleValue.putString("clientId", uuid);
                        }
                        JSONArray arr = new JSONArray();
                        for (int i = 0; i < links.size(); i++) arr.put(links.get(i));
                        String clientId = getSingleValue.getString("clientid", "");
                        if (clientId.equals("")) {
                            clientId = randomString();
                            setSingleValue.putString("clientid", clientId);
                            setSingleValue.apply();
                        }
                        Map<String, String> params = new HashMap<>();
                        params.put("clientId", clientId);
                        params.put("data", links.toString());
                        return params;
                    }
                };
                queue.add(postRequest);
            }
        }
    };
}
Also used : VolleyError(com.android.volley.VolleyError) HashMap(java.util.HashMap) DBHelper(com.nullsky.fba.DBHelper) StringRequest(com.android.volley.toolbox.StringRequest) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) Document(com.jsoup.nodes.Document) Elements(com.jsoup.select.Elements) SuppressLint(android.annotation.SuppressLint) Response(com.android.volley.Response) RequestQueue(com.android.volley.RequestQueue)

Example 69 with RequestQueue

use of com.android.volley.RequestQueue in project teamward-client by Neamar.

the class AddAccountActivity method saveAccount.

private void saveAccount(final String name, final String region) {
    final Account newAccount = new Account(name, region, "");
    final ProgressDialog dialog = ProgressDialog.show(this, "", String.format(getString(R.string.loading_summoner_data), name), true);
    dialog.show();
    // Instantiate the RequestQueue.
    final RequestQueue queue = VolleyQueue.newRequestQueue(this);
    try {
        NoCacheRetryJsonRequest jsonRequest = new NoCacheRetryJsonRequest(Request.Method.GET, ((LolApplication) getApplication()).getApiUrl() + "/summoner/data?summoner=" + URLEncoder.encode(name, "UTF-8") + "&region=" + region, null, new Response.Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    if (dialog.isShowing()) {
                        dialog.dismiss();
                    }
                } catch (IllegalArgumentException e) {
                // View is not attached (rotation for instance)
                }
                newAccount.summonerImage = response.optString("profileIcon", "");
                newAccount.summonerName = response.optString("name", newAccount.summonerName);
                Intent intent = new Intent(NEW_ACCOUNT);
                intent.putExtra("account", newAccount);
                setResult(RESULT_OK, intent);
                AccountManager accountManager = new AccountManager(AddAccountActivity.this);
                accountManager.addAccount(newAccount);
                Tracker.trackAccountAdded(AddAccountActivity.this, newAccount, accountManager.getAccountIndex(newAccount));
                queue.stop();
                finish();
            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                try {
                    if (dialog.isShowing()) {
                        dialog.dismiss();
                    }
                } catch (IllegalArgumentException e) {
                // View is not attached (rotation for instance)
                }
                Log.e(TAG, error.toString());
                try {
                    String responseBody = new String(error.networkResponse.data, "utf-8");
                    String errorMessage = responseBody.isEmpty() ? "Unable to load player data" : responseBody;
                    Log.i(TAG, errorMessage);
                    Intent intent = new Intent();
                    intent.putExtra("type", NEW_ACCOUNT);
                    intent.putExtra("error", errorMessage);
                    setResult(RESULT_ERROR, intent);
                    Tracker.trackErrorAddingAccount(AddAccountActivity.this, newAccount, errorMessage);
                } catch (UnsupportedEncodingException | NullPointerException e) {
                    e.printStackTrace();
                }
                queue.stop();
                final TextView nameText = (TextView) findViewById(R.id.summonerText);
                nameText.setError(getString(R.string.error_adding_account));
            }
        });
        queue.add(jsonRequest);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
}
Also used : VolleyError(com.android.volley.VolleyError) Account(fr.neamar.lolgamedata.pojo.Account) NoCacheRetryJsonRequest(fr.neamar.lolgamedata.volley.NoCacheRetryJsonRequest) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Intent(android.content.Intent) ProgressDialog(android.app.ProgressDialog) Response(com.android.volley.Response) JSONObject(org.json.JSONObject) RequestQueue(com.android.volley.RequestQueue) TextView(android.widget.TextView)

Example 70 with RequestQueue

use of com.android.volley.RequestQueue in project teamward-client by Neamar.

the class GameActivity method loadCurrentGame.

private void loadCurrentGame(final String summonerName, final String region) {
    final ProgressDialog dialog = ProgressDialog.show(this, "", String.format(getString(R.string.loading_game_data), summonerName), true);
    dialog.show();
    // Instantiate the RequestQueue.
    final RequestQueue queue = VolleyQueue.newRequestQueue(this);
    try {
        String version = "unknown";
        try {
            PackageInfo pInfo = this.getPackageManager().getPackageInfo(getPackageName(), 0);
            version = pInfo.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        String url = ((LolApplication) getApplication()).getApiUrl() + "/game/data?summoner=" + URLEncoder.encode(summonerName, "UTF-8") + "&region=" + region + "&version=" + version;
        if (BuildConfig.DEBUG && summonerName.equalsIgnoreCase("MOCK")) {
            url = "https://gist.githubusercontent.com/Neamar/eb278b4d5f188546f56028c3a0310507/raw/game.json";
        }
        NoCacheRetryJsonRequest jsonRequest = new NoCacheRetryJsonRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    game = new Game(response, region, account, shouldUseRelativeTeamColor());
                    GameActivity.this.summonerName = summonerName;
                    displayGame(summonerName, game);
                    Log.i(TAG, "Displaying game #" + game.gameId);
                    String source = getIntent() != null && getIntent().hasExtra("source") && !getIntent().getStringExtra("source").isEmpty() ? getIntent().getStringExtra("source") : "unknown";
                    Tracker.trackGameViewed(GameActivity.this, account, game, getDefaultTabName(), shouldDisplayChampionName(), source);
                } catch (JSONException e) {
                    e.printStackTrace();
                } finally {
                    try {
                        if (dialog.isShowing()) {
                            dialog.dismiss();
                        }
                    } catch (IllegalArgumentException e) {
                    // View is not attached (rotation for instance)
                    }
                    lastLoaded = new Date();
                    queue.stop();
                }
            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                game = null;
                lastLoaded = null;
                try {
                    if (dialog.isShowing()) {
                        dialog.dismiss();
                    }
                } catch (IllegalArgumentException e) {
                // View is not attached (rotation for instance)
                }
                Log.e(TAG, error.toString());
                queue.stop();
                setUiMode(UI_MODE_NO_INTERNET);
                if (error instanceof NoConnectionError) {
                    displaySnack(getString(R.string.no_internet_connection));
                    return;
                }
                try {
                    String responseBody = new String(error.networkResponse.data, "utf-8");
                    Log.i(TAG, responseBody);
                    if (!responseBody.contains("ummoner not in game")) {
                        displaySnack(responseBody);
                        Tracker.trackErrorViewingGame(GameActivity.this, account, responseBody.replace("Error:", ""));
                    } else {
                        setUiMode(UI_MODE_NOT_IN_GAME);
                    }
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                } catch (NullPointerException e) {
                // Do nothing, no text content in the HTTP reply.
                }
            }
        });
        queue.add(jsonRequest);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
}
Also used : VolleyError(com.android.volley.VolleyError) PackageInfo(android.content.pm.PackageInfo) NoCacheRetryJsonRequest(fr.neamar.lolgamedata.volley.NoCacheRetryJsonRequest) JSONException(org.json.JSONException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NoConnectionError(com.android.volley.NoConnectionError) ProgressDialog(android.app.ProgressDialog) Date(java.util.Date) Response(com.android.volley.Response) Game(fr.neamar.lolgamedata.pojo.Game) PackageManager(android.content.pm.PackageManager) JSONObject(org.json.JSONObject) RequestQueue(com.android.volley.RequestQueue)

Aggregations

RequestQueue (com.android.volley.RequestQueue)119 Response (com.android.volley.Response)101 VolleyError (com.android.volley.VolleyError)95 JSONObject (org.json.JSONObject)83 HashMap (java.util.HashMap)71 JsonObjectRequest (com.android.volley.toolbox.JsonObjectRequest)59 User (model.User)50 JSONException (org.json.JSONException)50 StringRequest (com.android.volley.toolbox.StringRequest)29 Context (android.content.Context)22 Toast (android.widget.Toast)20 TextView (android.widget.TextView)14 Intent (android.content.Intent)10 DefaultRetryPolicy (com.android.volley.DefaultRetryPolicy)10 Network (com.android.volley.Network)10 NetworkResponse (com.android.volley.NetworkResponse)10 File (java.io.File)9 UnsupportedEncodingException (java.io.UnsupportedEncodingException)9 ExecutionException (java.util.concurrent.ExecutionException)9 TimeoutException (java.util.concurrent.TimeoutException)9