use of com.android.volley.RequestQueue in project Space-Station-Tracker by Kiarasht.
the class Locations method displayPasses.
/**
* After successfully getting a city and country from the last JSON parsing, search a database
* to see when ISS will pass by this city, country.
*/
public List<Date> displayPasses(final String latitude, final String longitude, final Context applicationContext) {
// Used for Alert service
final List<Date> passes = new ArrayList<>();
final String url;
if (latitude == null && longitude == null) {
// Location.java is calling this method
url = "http://api.open-notify.org/iss-pass.json?lat=" + mLatitude + "&lon=" + mLongitude + "&n=20";
} else {
// Alert.java is calling this method
url = "http://api.open-notify.org/iss-pass.json?lat=" + latitude + "&lon=" + longitude;
}
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
final JSONArray results = response.getJSONArray("response");
final List<SightSee> dates = new ArrayList<>();
for (int i = 0; i < results.length(); ++i) {
final JSONObject aPass = results.getJSONObject(i);
passes.add(new Date(Long.parseLong(aPass.getString("risetime")) * 1000L));
final SightSee aSightSee = new SightSee(aPass.getInt("duration"), aPass.getInt("risetime"));
dates.add(aSightSee);
}
final View headerView = LayoutInflater.from(mActivity).inflate(R.layout.locations_header, null);
headerView.post(new Runnable() {
@Override
public void run() {
headerView.getLayoutParams().height = mFlexibleSpaceImageHeight;
}
});
mAdapter = new LocationAdapter(mActivity, headerView);
mAdapter.setDataSet(dates);
mRecyclerView.setAdapter(mAdapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError e) {
if (latitude == null && longitude == null) {
Toast.makeText(Locations.this, R.string.errorConnection, Toast.LENGTH_LONG).show();
}
}
});
// If Alert.java called us
if (requestQueue == null) {
RequestQueue requestQueue = Volley.newRequestQueue(applicationContext);
requestQueue.add(jsonObjectRequest);
} else {
// If Locations.java called us
jsonObjectRequest.setTag(TAG);
requestQueue.add(jsonObjectRequest);
}
// Only Alert.java benefits from this return
return passes;
}
use of com.android.volley.RequestQueue in project DogeTracker_Android by avrland.
the class wallet_balance method getWalletBalance.
// We download here json response, leaving a information everything is ready to update view
public void getWalletBalance(final Context currentContext, final Handler walletBalanceHandler, String address) {
StringRequest request = new StringRequest(url + address, new Response.Listener<String>() {
@Override
public void onResponse(String string) {
parseJsonData(string);
// We're ready, leave messenge for handler to refresh_rates in view
// It doesn't matter now what kind of messege we send.
Message news = new Message();
news.arg1 = 1;
walletBalanceHandler.sendMessage(news);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
// If something went wrong, we leave messege with error
}
});
RequestQueue rQueue = Volley.newRequestQueue(currentContext);
rQueue.add(request);
}
use of com.android.volley.RequestQueue in project DogeTracker_Android by avrland.
the class doge_rates method getRates.
// We download here json response, leaving a information everything is ready to update view
public void getRates(final Handler handler, final String fiatCurrency) {
DIALOG = new ProgressDialog(CURRENT_CONTEXT);
StringRequest request = new StringRequest(URL + "?convert=" + fiatCurrency.toLowerCase(), new Response.Listener<String>() {
@Override
public void onResponse(String string) {
parseJsonData(string, fiatCurrency.toLowerCase());
// We're ready, leave messenge for handler to refresh_rates in view
// It doesn't matter now what kind of messege we send.
Message news = new Message();
news.arg1 = 1;
handler.sendMessage(news);
saveRatesToOffline();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
Message news = new Message();
news.arg1 = 0;
handler.sendMessage(news);
readRatesFromOffline();
}
});
RequestQueue rQueue = Volley.newRequestQueue(CURRENT_CONTEXT);
rQueue.add(request);
}
use of com.android.volley.RequestQueue in project EC2018App by Manan-YMCA.
the class ContentActivity method checkCount.
private void checkCount(final String phone) {
String url = getResources().getString(R.string.get_events_qr_code);
url += phone;
RequestQueue queue = Volley.newRequestQueue(this);
StringRequest request = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
mProgress.dismiss();
try {
JSONObject obj1 = new JSONObject(response);
JSONArray ticketDetails = obj1.getJSONArray("data");
for (int i = 0; i < ticketDetails.length(); i++) {
JSONObject obj2 = ticketDetails.getJSONObject(i);
QRTicketModel TicketModel = new QRTicketModel();
TicketModel.setPaymentStatus(obj2.getInt("paymentstatus"));
TicketModel.setArrivalStatus(obj2.getInt("arrived"));
TicketModel.setQRcode(obj2.getString("qrcode"));
TicketModel.setEventID(obj2.getString("eventid"));
TicketModel.setTimeStamp(obj2.getLong("timestamp"));
userTickets.add(TicketModel);
}
}// Try and catch are included to handle any errors due to JSON
catch (Exception e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
mProgress.dismiss();
}
});
queue.add(request);
}
use of com.android.volley.RequestQueue in project EC2018App by Manan-YMCA.
the class EventRegister method addTicket.
private void addTicket(final String phoneNumber) {
String url = getResources().getString(R.string.get_events_qr_code);
url += phoneNumber;
RequestQueue queue = Volley.newRequestQueue(this);
StringRequest request = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject obj1 = new JSONObject(response);
JSONArray ticketDetails = obj1.getJSONArray("data");
for (int i = 0; i < ticketDetails.length(); i++) {
JSONObject obj2 = ticketDetails.getJSONObject(i);
if (obj2.getString("eventid").equals(eventId)) {
TicketModel = new QRTicketModel();
TicketModel.setPaymentStatus(obj2.getInt("paymentstatus"));
TicketModel.setArrivalStatus(obj2.getInt("arrived"));
TicketModel.setQRcode(obj2.getString("qrcode"));
TicketModel.setEventID(obj2.getString("eventid"));
TicketModel.setTimeStamp(obj2.getLong("timestamp"));
databaseController.addTicketsToDb(TicketModel);
}
}
}// Try and catch are included to handle any errors due to JSON
catch (Exception e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
queue.add(request);
}
Aggregations