use of com.loopj.android.http.JsonHttpResponseHandler in project AnimeTaste by daimajia.
the class LoadActivity method init.
private void init() {
if (getIntent().getAction().equals(Intent.ACTION_VIEW)) {
Uri uri = getIntent().getData();
if (uri == null) {
error();
}
String vid = uri.getQueryParameter("vid");
int animationId = Integer.valueOf(vid);
ApiConnector.instance().getDetail(animationId, new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, final JSONObject response) {
super.onSuccess(statusCode, response);
try {
if (statusCode == 200 && response.has("data") && response.getJSONObject("data").has("result") && response.getJSONObject("data").getBoolean("result")) {
final JSONObject anime = response.getJSONObject("data").getJSONObject("anime");
new Thread() {
@Override
public void run() {
super.run();
MobclickAgent.onEvent(mContext, "yell");
final Intent intent = new Intent(mContext, PlayActivity.class);
Animation animation = Animation.build(anime);
intent.putExtra("Animation", animation);
runOnUiThread(new Runnable() {
@Override
public void run() {
startActivity(intent);
finish();
}
});
}
}.start();
} else {
error();
}
} catch (Exception e) {
e.printStackTrace();
error();
}
}
@Override
public void onFailure(Throwable throwable, JSONArray jsonArray) {
super.onFailure(throwable, jsonArray);
error();
}
@Override
public void onFinish() {
super.onFinish();
}
});
} else {
ApiConnector.instance().getInitData(20, 5, 2, new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, final JSONObject response) {
super.onSuccess(response);
if (statusCode == 200 && response.has("data")) {
Message msg = Message.obtain();
msg.obj = response;
executeHandler.sendMessage(msg);
} else {
error();
}
}
@Override
public void onFailure(Throwable error) {
super.onFailure(error);
error();
}
});
}
}
use of com.loopj.android.http.JsonHttpResponseHandler in project app by TourLive.
the class APIClient method getRiders.
public static String getRiders(String url, RequestParams params) {
final String[] messages = { "success" };
APIClient.get(url, null, new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject data) {
try {
Parser.parseRidersAndPersist(data.getJSONArray("data"));
messages[0] = "success";
} catch (Exception ex) {
messages[0] = ex.getMessage();
}
}
@Override
public void onSuccess(int statusCode, Header[] headers, JSONArray riders) {
// Not needed and therefore not implemented
}
@Override
public void onFailure(int error, Header[] headers, Throwable throwable, JSONObject riders) {
if (throwable.getMessage().equals(throwableType)) {
messages[0] = readTimeOutMessage + throwable.getMessage();
} else {
messages[0] = throwable.getMessage();
}
}
});
return messages[0];
}
use of com.loopj.android.http.JsonHttpResponseHandler in project app by TourLive.
the class APIClient method getRewards.
public static String getRewards(String url, RequestParams params) {
final String[] messages = { "success" };
APIClient.get(url, null, new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject data) {
try {
Parser.parseRewardsAndPersist(data.getJSONObject("data").getJSONArray("rewards"));
messages[0] = "success";
} catch (Exception ex) {
messages[0] = ex.getMessage();
}
}
@Override
public void onSuccess(int statusCode, Header[] headers, JSONArray riders) {
// Not needed and therefore not implemented
}
@Override
public void onFailure(int error, Header[] headers, Throwable throwable, JSONObject riders) {
if (throwable.getMessage().equals(throwableType)) {
messages[0] = readTimeOutMessage + throwable.getMessage();
} else {
messages[0] = throwable.getMessage();
}
}
});
return messages[0];
}
use of com.loopj.android.http.JsonHttpResponseHandler in project app by TourLive.
the class APIClient method getMaillotsRiderConnections.
public static String getMaillotsRiderConnections(String url, RequestParams params) {
final String[] messages = { "success" };
APIClient.get(url, null, new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject data) {
try {
Parser.parseMaillotsRiderConnectionAndPersist(data.getJSONArray("data"));
messages[0] = "success";
} catch (Exception ex) {
messages[0] = ex.getMessage();
}
}
@Override
public void onSuccess(int statusCode, Header[] headers, JSONArray maillots) {
// Not needed and therefore not implemented
}
@Override
public void onFailure(int error, Header[] headers, Throwable throwable, JSONObject riders) {
if (throwable.getMessage().equals(throwableType)) {
messages[0] = readTimeOutMessage + throwable.getMessage();
} else {
messages[0] = throwable.getMessage();
}
}
});
return messages[0];
}
use of com.loopj.android.http.JsonHttpResponseHandler in project app by TourLive.
the class APIClient method getStateFromAPI.
public static <T> T getStateFromAPI(String url, RequestParams params) {
if (Looper.myLooper() == null)
Looper.prepare();
uiHandler = new Handler();
T[] response = (T[]) new Object[1];
APIClient.get(url, null, new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject data) {
try {
response[0] = (T) data;
} catch (Exception ex) {
Log.d("here", "here");
uiHandler.post(ex::getMessage);
}
}
@Override
public void onSuccess(int statusCode, Header[] headers, JSONArray data) {
try {
response[0] = (T) data;
} catch (Exception ex) {
Log.d("here", "here");
uiHandler.post(ex::getMessage);
}
}
@Override
public void onFailure(int error, Header[] headers, Throwable throwable, JSONObject data) {
Log.d("here", "here");
uiHandler.post(throwable::getMessage);
}
});
return response[0];
}
Aggregations