Skip to content

Commit

Permalink
Updated Sample application to show capability of obtaining TAG within…
Browse files Browse the repository at this point in the history
… ResponseHandler, android-async-http#552
  • Loading branch information
smarek committed Jul 16, 2015
1 parent af7e9e4 commit cf95c42
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.util.Log;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestHandle;
import com.loopj.android.http.ResponseHandlerInterface;

Expand All @@ -43,6 +44,39 @@ public void onCancelButtonPressed() {
getAsyncHttpClient().cancelRequestsByTAG(REQUEST_TAG, false);
}

@Override
public ResponseHandlerInterface getResponseHandler() {
return new AsyncHttpResponseHandler() {

private final int id = counter++;

@Override
public void onStart() {
setStatus(id, "TAG:" + getTag() + ", START");
}

@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
setStatus(id, "SUCCESS");
}

@Override
public void onFinish() {
setStatus(id, "FINISH");
}

@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
setStatus(id, "FAILURE");
}

@Override
public void onCancel() {
setStatus(id, "CANCEL");
}
};
}

@Override
public RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, ResponseHandlerInterface responseHandler) {
return client.get(this, URL, headers, null, responseHandler).setTag(REQUEST_TAG);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
public class ThreadingTimeoutSample extends SampleParentActivity {

private static final String LOG_TAG = "ThreadingTimeoutSample";
private final SparseArray<String> states = new SparseArray<String>();
private int counter = 0;
protected final SparseArray<String> states = new SparseArray<String>();
protected int counter = 0;

@Override
public int getSampleTitle() {
Expand All @@ -59,7 +59,7 @@ public String getDefaultURL() {
return PROTOCOL + "httpbin.org/delay/6";
}

private synchronized void setStatus(int id, String status) {
protected synchronized void setStatus(int id, String status) {
String current = states.get(id, null);
states.put(id, current == null ? status : current + "," + status);
clearOutputs();
Expand Down

0 comments on commit cf95c42

Please sign in to comment.