use of com.android.volley.toolbox.JsonArrayRequest in project Space-Station-Tracker by Kiarasht.
the class MapsActivity method updatePolyline.
/**
* Update polyline sets the future predictions of ISS's position for up to 90 minutes.
*/
private void updatePolyline(Date currentDate) {
long currentLong = currentDate.getTime() / 1000;
final long[] futureTen = new long[10];
for (int i = 0; i < futureTen.length; ++i) {
futureTen[i] = currentLong + (30 * mPoly++);
}
final StringBuilder urlBuilder = new StringBuilder();
for (long aFutureTen : futureTen) {
urlBuilder.append(aFutureTen).append(",");
}
urlBuilder.setLength(urlBuilder.length() - 1);
//TODO: As a user, I would like the option of changing the units from metric to imperial
final String units = "miles";
final String url = "https://api.wheretheiss.at/v1/satellites/25544/positions?timestamps=" + urlBuilder.toString() + "&units=" + units;
final int finalStart = mPoly;
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(url, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
try {
final LatLng[] latLngs = new LatLng[10];
for (int i = 0; i < response.length(); ++i) {
latLngs[i] = new LatLng(response.getJSONObject(i).getDouble("latitude"), response.getJSONObject(i).getDouble("longitude"));
}
MapsActivity.this.runOnUiThread(new Runnable() {
public void run() {
if (finalStart == 10) {
for (int i = 0; i < futureTen.length - 1; ++i) {
mPolyLine = mMap.addPolyline(new PolylineOptions().add(latLngs[i], latLngs[i + 1]).width(mCurrentWidth).color(mCurrentColor));
mPolyArray[mPolyCounter++] = mPolyLine;
}
mLast = latLngs[latLngs.length - 1];
++mProgress;
} else {
mPolyArray[mPolyCounter++] = mMap.addPolyline(new PolylineOptions().add(mLast, latLngs[0]).width(mCurrentWidth).color(mCurrentColor));
for (int i = 0; i < futureTen.length - 1; ++i) {
mPolyArray[mPolyCounter++] = mMap.addPolyline(new PolylineOptions().add(latLngs[i], latLngs[i + 1]).width(mCurrentWidth).color(mCurrentColor));
}
mLast = latLngs[latLngs.length - 1];
++mProgress;
}
}
});
} catch (Exception e) {
if (mLast == null) {
FirebaseCrash.report(new Exception("mLast was null"));
}
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError e) {
}
});
mRequestQueue.add(jsonArrayRequest);
}
use of com.android.volley.toolbox.JsonArrayRequest in project EC2018App by Manan-YMCA.
the class QuestionFragment method getQuestion.
public void getQuestion() {
JSONArray jsonArray = new JSONArray();
JSONObject params = new JSONObject();
try {
params.put("fid", currFbid);
if (Profile.getCurrentProfile() != null) {
params.put("skey", mContext.getResources().getString(R.string.skey));
params.put("fname", Profile.getCurrentProfile().getFirstName());
params.put("lname", Profile.getCurrentProfile().getLastName());
}
} catch (JSONException e) {
e.printStackTrace();
}
jsonArray.put(params);
jobReq = new JsonArrayRequest(Request.Method.POST, queURL, jsonArray, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
bar.setVisibility(View.GONE);
JSONObject resp;
refreshButton.setVisibility(View.GONE);
try {
resp = response.getJSONObject(0);
try {
String end = resp.getString("response");
contestEnd.setVisibility(View.VISIBLE);
contestEnd.setText("YOU HAVE SUCCESSFULLY COMPLETED ALL THE QUESTIONS.\n WE WILL ANNOUNCE THE WINNERS ON 7th APRIL, 2018.\nIF YOU HAVE WON, WE WILL CONTACT YOU SHORTLY");
refreshButton.setVisibility(View.GONE);
} catch (Exception e) {
bar.setVisibility(View.GONE);
barImage.setVisibility(View.VISIBLE);
queLayout.setVisibility(View.VISIBLE);
String imgUrl = resp.getString("image");
String que = resp.getString("desc");
Integer level = resp.getInt("pk");
question.setText(que);
QuestionFragment.this.level.setText("Level " + Integer.toString(level));
Picasso.with(mContext).load("https://xunbao-1.herokuapp.com" + imgUrl).into(xunbaoimg, new Callback() {
@Override
public void onSuccess() {
barImage.setVisibility(View.GONE);
}
@Override
public void onError() {
barImage.setVisibility(View.GONE);
}
});
}
} catch (JSONException e) {
bar.setVisibility(View.GONE);
// progressBar.dismiss();
refreshButton.setVisibility(View.VISIBLE);
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
// progressBar.dismiss();
bar.setVisibility(View.GONE);
refreshButton.setVisibility(View.VISIBLE);
volleyError.printStackTrace();
}
});
queue.add(stat);
}
use of com.android.volley.toolbox.JsonArrayRequest in project MPW by shineangelic.
the class Utils method synchCurrenciesFromCoinmarketcap.
public static void synchCurrenciesFromCoinmarketcap(Context ctx, CurrencyEnum mCur) {
try {
// synch jason
RequestFuture<JSONArray> future = RequestFuture.newFuture();
JsonArrayRequest request = new JsonArrayRequest(Request.Method.GET, Constants.ETHER_STATS_URL, new JSONArray(), future, future);
JSONClientSingleton.getInstance(ctx).addToRequestQueue(request);
// this will block
JSONArray response = future.get();
Log.d(Constants.TAG, response.toString());
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
Type listType = new TypeToken<List<Ticker>>() {
}.getType();
List<Ticker> posts = gson.fromJson(response.toString(), listType);
Ticker fnd = null;
for (Ticker currency : posts) {
if (mCur.name().equalsIgnoreCase(currency.getSymbol()) || mCur.toString().equalsIgnoreCase(currency.getName())) {
fnd = currency;
}
// always save ETH
if (CurrencyEnum.ETH.name().equalsIgnoreCase(currency.getSymbol())) {
CryptoSharedPreferencesUtils.saveEthereumValues(currency, ctx);
}
// always save BTC
if (CurrencyEnum.BTC.name().equalsIgnoreCase(currency.getSymbol())) {
CryptoSharedPreferencesUtils.saveBtcValues(currency, ctx);
}
}
CryptoSharedPreferencesUtils.saveEtherValues(fnd, ctx);
} catch (Exception e) {
Log.d(Constants.TAG, "ERROR DURING COINMARKETCAP: " + e.getMessage());
}
}
use of com.android.volley.toolbox.JsonArrayRequest in project mintube by imshyam.
the class MainActivity method onQueryTextChange.
@Override
public boolean onQueryTextChange(String newText) {
if (newText.length() > 0) {
newText = newText.replace(" ", "+");
String url = "http://suggestqueries.google.com/complete/search?client=youtube&ds=yt&client=firefox&q=" + newText;
JsonArrayRequest req = new JsonArrayRequest(url, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
try {
JSONArray jsonArraySuggestion = (JSONArray) response.get(1);
String[] suggestions = new String[10];
for (int i = 0; i < 10; i++) {
if (!jsonArraySuggestion.isNull(i)) {
suggestions[i] = jsonArraySuggestion.get(i).toString();
}
}
Log.d("Suggestions", Arrays.toString(suggestions));
// Cursor Adaptor
String[] columnNames = { "_id", "suggestion" };
MatrixCursor cursor = new MatrixCursor(columnNames);
String[] temp = new String[2];
int id = 0;
for (String item : suggestions) {
if (item != null) {
temp[0] = Integer.toString(id++);
temp[1] = item;
cursor.addRow(temp);
}
}
CursorAdapter cursorAdapter = new CursorAdapter(getApplicationContext(), cursor, false) {
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return LayoutInflater.from(context).inflate(R.layout.search_suggestion_list_item, parent, false);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
final TextView suggest = (TextView) view.findViewById(R.id.suggest);
ImageView putInSearchBox = (ImageView) view.findViewById(R.id.put_in_search_box);
String body = cursor.getString(cursor.getColumnIndexOrThrow("suggestion"));
suggest.setText(body);
suggest.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
searchView.setQuery(suggest.getText(), true);
searchView.clearFocus();
}
});
putInSearchBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
searchView.setQuery(suggest.getText(), false);
}
});
}
};
searchView.setSuggestionsAdapter(cursorAdapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d("Tag", "Error: " + error.getMessage());
Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_SHORT).show();
}
});
// Adding request to request queue
AppController.getInstance().addToRequestQueue(req);
}
return true;
}
use of com.android.volley.toolbox.JsonArrayRequest in project Habba18 by chiragsastry1996.
the class Gallery_activity method fetchImages.
private void fetchImages() {
// To be replaced by Snackbar
pDialog.setMessage("Downloading ...");
// To be replaced by Snackbar
pDialog.show();
JsonArrayRequest req = new JsonArrayRequest(endpoint, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
Log.d(TAG, response.toString());
// To be replaced by Snackbar
pDialog.hide();
images.clear();
for (int i = 0; i < response.length(); i++) {
try {
JSONObject object = response.getJSONObject(i);
Image image = new Image();
image.setName(object.getString("name"));
JSONObject url = object.getJSONObject("url");
// image.setSmall(url.getString("small"));
image.setMedium(url.getString("medium"));
// image.setLarge(url.getString("large")); Enable this later
image.setTimestamp(object.getString("timestamp"));
images.add(image);
} catch (JSONException e) {
Log.e(TAG, "Json parsing error: " + e.getMessage());
}
}
mAdapter.notifyDataSetChanged();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "Error: " + error.getMessage());
// To be replaced by Snackbar
pDialog.dismiss();
}
});
// Adding request to request queue
AppController.getInstance().addToRequestQueue(req);
}
Aggregations