use of com.android.volley.VolleyError in project MVCHelper by LuckyJayce.
the class LoginAsyncTask method execute.
@Override
public RequestHandle execute(final ResponseSender<User> sender) throws Exception {
String url = "https://www.baidu.com";
Uri.Builder builder = Uri.parse(url).buildUpon();
builder.appendQueryParameter("userName", name);
builder.appendQueryParameter("password", password);
StringRequest jsonObjRequest = new StringRequest(Request.Method.GET, builder.toString(), new Response.Listener<String>() {
@Override
public void onResponse(String response) {
if (TextUtils.isEmpty(name)) {
sender.sendError(new BizException("请输入用户名"));
} else if (TextUtils.isEmpty(password)) {
sender.sendError(new BizException("请输入密码"));
} else if (name.equals("LuckyJayce") && password.equals("111")) {
sender.sendData(new User("1", "LuckyJayce", 23, "中国人"));
} else {
sender.sendError(new BizException("用户名或者密码不正确"));
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
sender.sendError(error);
}
});
MyVolley.getRequestQueue().add(jsonObjRequest);
return new VolleyRequestHandle(jsonObjRequest);
}
use of com.android.volley.VolleyError in project Douya by DreaminginCodeZH.
the class BasicNetwork method attemptRetryOnException.
/**
* Attempts to prepare the request for a retry. If there are no more attempts remaining in the
* request's retry policy, a timeout exception is thrown.
* @param request The request to use.
*/
private static void attemptRetryOnException(String logPrefix, Request<?> request, VolleyError exception) throws VolleyError {
RetryPolicy retryPolicy = request.getRetryPolicy();
int oldTimeout = request.getTimeoutMs();
try {
retryPolicy.retry(exception);
} catch (VolleyError e) {
request.addMarker(String.format("%s-giveup [timeout=%s]", logPrefix, oldTimeout));
throw e;
}
request.addMarker(String.format("%s-retry [timeout=%s]", logPrefix, oldTimeout));
}
use of com.android.volley.VolleyError in project easy by MehdiBenmesa.
the class TimeLineActivity method setDataListItemsStudent.
public void setDataListItemsStudent(final Itimeline callback) {
try {
CustomRequest jsonReq = new CustomRequest(Request.Method.GET, GET_TIME_TABLE_STUDENT + "/" + user.getString("section") + "/" + user.getString("groupe"), null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
callback.onDataRecieved(response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
App.getInstance().addToRequestQueue(jsonReq);
} catch (JSONException e) {
e.printStackTrace();
}
}
use of com.android.volley.VolleyError 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.VolleyError in project Space-Station-Tracker by Kiarasht.
the class MapsActivity method trackISS.
/**
* Get the Lat and Lon of ISS and move the map to that position when called.
*/
private void trackISS() {
final String url = "https://api.wheretheiss.at/v1/satellites/25544";
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
// Server responded successfully
mSuccess = 0;
final double latParameter = Double.parseDouble(response.getString("latitude"));
final double lngParameter = Double.parseDouble(response.getString("longitude"));
final LatLng ISS = new LatLng(latParameter, lngParameter);
final String LAT;
final String LNG;
if (latParameter < 0) {
LAT = mDecimalFormat.format(latParameter) + "° S";
} else {
LAT = mDecimalFormat.format(latParameter) + "° N";
}
if (lngParameter < 0) {
LNG = mDecimalFormat.format(lngParameter) + "° W";
} else {
LNG = mDecimalFormat.format(lngParameter) + "° E";
}
final String position = LAT + ", " + LNG;
final String visibility = response.getString("visibility");
final StringBuilder moreInfo = new StringBuilder();
moreInfo.append("Altitude: ").append(mDecimalFormat.format(Double.parseDouble(response.getString("altitude")))).append(" km").append("\n").append("Velocity: ").append(mDecimalFormat.format(Double.parseDouble(response.getString("velocity")))).append(" kph").append("\n").append("Footprint: ").append(mDecimalFormat.format(Double.parseDouble(response.getString("footprint")))).append(" km").append("\n").append("Solar LAT: ").append(mDecimalFormat.format(Double.parseDouble(response.getString("solar_lat")))).append("°").append("\n").append("Solar LON: ").append(mDecimalFormat.format(Double.parseDouble(response.getString("solar_lon")))).append("°").append("\n").append("Visibility: ").append(visibility.substring(0, 1).toUpperCase()).append(visibility.substring(1)).append("\n");
MapsActivity.this.runOnUiThread(new Runnable() {
public void run() {
if (mOnce) {
mMap.moveCamera(CameraUpdateFactory.newLatLng(ISS));
if (mMap.getUiSettings().isScrollGesturesEnabled()) {
mMap.getUiSettings().setScrollGesturesEnabled(false);
}
mOnce = false;
} else if (mSharedPreferences.getBoolean("lock_ISS", false)) {
mMap.moveCamera(CameraUpdateFactory.newLatLng(ISS));
if (mMap.getUiSettings().isScrollGesturesEnabled()) {
mMap.getUiSettings().setScrollGesturesEnabled(false);
}
} else if (!mSharedPreferences.getBoolean("lock_ISS", false)) {
mMap.getUiSettings().setScrollGesturesEnabled(true);
}
if (mMarker != null) {
mMarker.remove();
}
mDescription.setText(moreInfo.toString());
mLatLong.setText(position);
mMarkerOptions.position(ISS);
mMarker = mMap.addMarker(mMarkerOptions);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError e) {
// Server did not respond. Got 5 chances before stop trying.
if (++mSuccess <= 4) {
Toast.makeText(MapsActivity.this, getResources().getString(R.string.errorLessFive, mSuccess, mRefreshrate), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MapsActivity.this, R.string.errorFiveTimes, Toast.LENGTH_LONG).show();
if (mTimer != null) {
mTimer.cancel();
mTimer.purge();
}
mTimer = null;
}
}
});
jsonObjectRequest.setTag(TAG);
mRequestQueue.add(jsonObjectRequest);
}
Aggregations