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();
}
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);
}
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);
}
}
};
}
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") + "®ion=" + 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();
}
}
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") + "®ion=" + 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();
}
}
Aggregations