use of com.android.volley.toolbox.JsonArrayRequest in project MPW by shineangelic.
the class MPWCoinmarketcapService method asynchCurrenciesFromCoinmarketcap.
private void asynchCurrenciesFromCoinmarketcap(final Context ctx, final CurrencyEnum mCur, final JobParameters job) {
try {
JsonArrayRequest jsonArrayCurrenciesReq = new JsonArrayRequest(Request.Method.GET, Constants.ETHER_STATS_URL, null, new Response.Listener<JSONArray>() {
@Override
public void onResponse(final JSONArray response) {
Log.d(Constants.TAG, response.toString());
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
Log.d(Constants.TAG, response.toString());
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);
}
}
// eventually resets when fnd = null
CryptoSharedPreferencesUtils.saveEtherValues(fnd, ctx);
Log.e(TAG, "SERVICE MARKETCAP END Ok2");
MPWCoinmarketcapService.this.jobFinished(job, false);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "SERVICE MARKETCAP END KO2");
VolleyLog.d(Constants.TAG, "Error: " + error.getMessage());
Crashlytics.logException(error);
MPWCoinmarketcapService.this.jobFinished(job, true);
}
});
// Adding request to request queue
JSONClientSingleton.getInstance(ctx).addToRequestQueue(jsonArrayCurrenciesReq);
} catch (Exception e) {
Log.d(Constants.TAG, "ERROR DURING COINMARKETCAP: " + e.getMessage());
}
}
use of com.android.volley.toolbox.JsonArrayRequest in project saga-android by AnandChowdhary.
the class DownloadFragment method getCharts.
private void getCharts() {
mImageLoader = VolleySingleton.getInstance(getActivity()).getImageLoader();
String url = "http://boundbytech.com/saga/get_charts.php";
JsonArrayRequest request = new JsonArrayRequest(url, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
mAdapter = new ChartsAdapter(response);
mRecyclerView.setAdapter(mAdapter);
mProgress.setVisibility(View.GONE);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
mProgress.setVisibility(View.GONE);
}
});
mQueue.add(request);
}
use of com.android.volley.toolbox.JsonArrayRequest in project FastDev4Android by jiangqqlmj.
the class JsonRequestCharsetTest method specifiedCharsetJsonArray.
@Test
public void specifiedCharsetJsonArray() throws Exception {
byte[] data = jsonArrayString().getBytes(Charset.forName("ISO-8859-2"));
Map<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json; charset=iso-8859-2");
NetworkResponse network = new NetworkResponse(data, headers);
JsonArrayRequest arrayRequest = new JsonArrayRequest("", null, null);
Response<JSONArray> arrayResponse = arrayRequest.parseNetworkResponse(network);
assertNotNull(arrayResponse);
assertTrue(arrayResponse.isSuccess());
assertEquals(TEXT_VALUE, arrayResponse.result.getString(TEXT_INDEX));
// don't check the copyright symbol, ISO-8859-2 doesn't have it, but it has Czech characters
}
use of com.android.volley.toolbox.JsonArrayRequest in project FastDev4Android by jiangqqlmj.
the class Fdv_JsonArrayRequest method get.
/**
* 请求返回JSONArray对象 Get请求 无参数,或者get请求的参数直接拼接在URL上面
* @param url 请求地址
* @param listener 数据返回回调接口
*/
public void get(String url, final Fdv_CallBackListener<JSONArray> listener) {
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, url, null, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
if (listener != null) {
listener.onSuccessResponse(response);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
if (listener != null) {
listener.onErrorResponse(error);
}
}
});
addRequest(jsonArrayRequest);
}
use of com.android.volley.toolbox.JsonArrayRequest in project TaEmCasa by Dionen.
the class JsonRequestCharsetTest method defaultCharsetJsonArray.
@Test
public void defaultCharsetJsonArray() throws Exception {
// UTF-8 is default charset for JSON
byte[] data = jsonArrayString().getBytes(Charset.forName("UTF-8"));
NetworkResponse network = new NetworkResponse(data);
JsonArrayRequest arrayRequest = new JsonArrayRequest("", null, null);
Response<JSONArray> arrayResponse = arrayRequest.parseNetworkResponse(network);
assertNotNull(arrayResponse);
assertTrue(arrayResponse.isSuccess());
assertEquals(TEXT_VALUE, arrayResponse.result.getString(TEXT_INDEX));
assertEquals(COPY_VALUE, arrayResponse.result.getString(COPY_INDEX));
}
Aggregations