Skip to content

Commit 72bb013

Browse files
committed
Merge pull request android-async-http#357 from xAnubiSx/master
Implement Sample Application
2 parents e7bce03 + a2ce1e9 commit 72bb013

File tree

22 files changed

+221
-31
lines changed

22 files changed

+221
-31
lines changed
File renamed without changes.

sample/src/main/res/values/strings.xml renamed to sample/main/res/values/strings.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44
<string name="app_name">Android Async Http Sample</string>
55
<string name="title_get_sample">GET Sample</string>
66
<string name="title_json_sample">JSON Sample</string>
7-
7+
<string name="title_post_sample">POST Sample</string>
8+
<string name="title_put_sample">PUT Sample</string>
9+
<string name="title_delete_sample">DELETE Sample</string>
810
</resources>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.loopj.android.http.sample;
2+
3+
import org.apache.http.Header;
4+
5+
import com.loopj.android.http.AsyncHttpClient;
6+
import com.loopj.android.http.AsyncHttpResponseHandler;
7+
8+
public class DeleteSample extends SampleParentActivity {
9+
private static final String LOG_TAG = "DeleteSample";
10+
11+
@Override
12+
protected void executeSample(AsyncHttpClient client, String URL, AsyncHttpResponseHandler responseHandler) {
13+
client.delete(this, URL, null, responseHandler);
14+
}
15+
16+
@Override
17+
protected int getSampleTitle() {
18+
return R.string.title_delete_sample;
19+
}
20+
21+
@Override
22+
protected boolean isRequestBodyAllowed() {
23+
return false;
24+
}
25+
26+
@Override
27+
protected boolean isRequestHeadersAllowed() {
28+
return true;
29+
}
30+
31+
@Override
32+
protected String getDefaultURL() {
33+
return "http://www.google.com";
34+
}
35+
36+
@Override
37+
protected AsyncHttpResponseHandler getResponseHandler() {
38+
return new AsyncHttpResponseHandler() {
39+
40+
@Override
41+
public void onStart() {
42+
clearOutputs();
43+
}
44+
45+
@Override
46+
public void onSuccess(int statusCode, Header[] headers, byte[] response) {
47+
debugHeaders(LOG_TAG, headers);
48+
debugStatusCode(LOG_TAG, statusCode);
49+
debugResponse(LOG_TAG, new String(response));
50+
}
51+
52+
@Override
53+
public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {
54+
debugHeaders(LOG_TAG, headers);
55+
debugStatusCode(LOG_TAG, statusCode);
56+
debugThrowable(LOG_TAG, e);
57+
if (errorResponse != null) {
58+
debugResponse(LOG_TAG, new String(errorResponse));
59+
}
60+
}
61+
};
62+
}
63+
}

sample/src/main/java/com/loopj/android/http/sample/GetSample.java renamed to sample/main/src/com/loopj/android/http/sample/GetSample.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package com.loopj.android.http.sample;
22

3+
import org.apache.http.Header;
4+
35
import com.loopj.android.http.AsyncHttpClient;
46
import com.loopj.android.http.AsyncHttpResponseHandler;
57

68
public class GetSample extends SampleParentActivity {
9+
private static final String LOG_TAG = "GetSample";
710

811
@Override
912
protected void executeSample(AsyncHttpClient client, String URL, AsyncHttpResponseHandler responseHandler) {
@@ -39,6 +42,22 @@ public void onStart() {
3942
clearOutputs();
4043
}
4144

45+
@Override
46+
public void onSuccess(int statusCode, Header[] headers, byte[] response) {
47+
debugHeaders(LOG_TAG, headers);
48+
debugStatusCode(LOG_TAG, statusCode);
49+
debugResponse(LOG_TAG, new String(response));
50+
}
51+
52+
@Override
53+
public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {
54+
debugHeaders(LOG_TAG, headers);
55+
debugStatusCode(LOG_TAG, statusCode);
56+
debugThrowable(LOG_TAG, e);
57+
if (errorResponse != null) {
58+
debugResponse(LOG_TAG, new String(errorResponse));
59+
}
60+
}
4261
};
4362
}
4463
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.loopj.android.http.sample;
2+
3+
import org.apache.http.Header;
4+
5+
import com.loopj.android.http.AsyncHttpClient;
6+
import com.loopj.android.http.AsyncHttpResponseHandler;
7+
8+
public class PostSample extends SampleParentActivity {
9+
private static final String LOG_TAG = "PostSample";
10+
11+
@Override
12+
protected void executeSample(AsyncHttpClient client, String URL, AsyncHttpResponseHandler responseHandler) {
13+
client.post(this, URL, null, responseHandler);
14+
}
15+
16+
@Override
17+
protected int getSampleTitle() {
18+
return R.string.title_post_sample;
19+
}
20+
21+
@Override
22+
protected boolean isRequestBodyAllowed() {
23+
return false;
24+
}
25+
26+
@Override
27+
protected boolean isRequestHeadersAllowed() {
28+
return true;
29+
}
30+
31+
@Override
32+
protected String getDefaultURL() {
33+
return "http://www.google.com";
34+
}
35+
36+
@Override
37+
protected AsyncHttpResponseHandler getResponseHandler() {
38+
return new AsyncHttpResponseHandler() {
39+
40+
@Override
41+
public void onStart() {
42+
clearOutputs();
43+
}
44+
45+
@Override
46+
public void onSuccess(int statusCode, Header[] headers, byte[] response) {
47+
debugHeaders(LOG_TAG, headers);
48+
debugStatusCode(LOG_TAG, statusCode);
49+
debugResponse(LOG_TAG, new String(response));
50+
}
51+
52+
@Override
53+
public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {
54+
debugHeaders(LOG_TAG, headers);
55+
debugStatusCode(LOG_TAG, statusCode);
56+
debugThrowable(LOG_TAG, e);
57+
if (errorResponse != null) {
58+
debugResponse(LOG_TAG, new String(errorResponse));
59+
}
60+
}
61+
};
62+
}
63+
}
64+
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.loopj.android.http.sample;
2+
3+
import org.apache.http.Header;
4+
5+
import com.loopj.android.http.AsyncHttpClient;
6+
import com.loopj.android.http.AsyncHttpResponseHandler;
7+
8+
public class PutSample extends SampleParentActivity {
9+
private static final String LOG_TAG = "PutSample";
10+
11+
@Override
12+
protected void executeSample(AsyncHttpClient client, String URL, AsyncHttpResponseHandler responseHandler) {
13+
client.put(this, URL, null, responseHandler);
14+
}
15+
16+
@Override
17+
protected int getSampleTitle() {
18+
return R.string.title_put_sample;
19+
}
20+
21+
@Override
22+
protected boolean isRequestBodyAllowed() {
23+
return false;
24+
}
25+
26+
@Override
27+
protected boolean isRequestHeadersAllowed() {
28+
return true;
29+
}
30+
31+
@Override
32+
protected String getDefaultURL() {
33+
return "http://www.google.com";
34+
}
35+
36+
@Override
37+
protected AsyncHttpResponseHandler getResponseHandler() {
38+
return new AsyncHttpResponseHandler() {
39+
40+
@Override
41+
public void onStart() {
42+
clearOutputs();
43+
}
44+
45+
@Override
46+
public void onSuccess(int statusCode, Header[] headers, byte[] response) {
47+
debugHeaders(LOG_TAG, headers);
48+
debugStatusCode(LOG_TAG, statusCode);
49+
debugResponse(LOG_TAG, new String(response));
50+
}
51+
52+
@Override
53+
public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {
54+
debugHeaders(LOG_TAG, headers);
55+
debugStatusCode(LOG_TAG, statusCode);
56+
debugThrowable(LOG_TAG, e);
57+
if (errorResponse != null) {
58+
debugResponse(LOG_TAG, new String(errorResponse));
59+
}
60+
}
61+
};
62+
}
63+
}

sample/src/main/java/com/loopj/android/http/sample/SampleParentActivity.java renamed to sample/main/src/com/loopj/android/http/sample/SampleParentActivity.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package com.loopj.android.http.sample;
22

3+
import java.io.PrintWriter;
4+
import java.io.StringWriter;
5+
6+
import org.apache.http.Header;
7+
38
import android.app.Activity;
49
import android.graphics.Color;
510
import android.os.Bundle;
@@ -16,11 +21,6 @@
1621
import com.loopj.android.http.AsyncHttpClient;
1722
import com.loopj.android.http.AsyncHttpResponseHandler;
1823

19-
import org.apache.http.Header;
20-
21-
import java.io.PrintWriter;
22-
import java.io.StringWriter;
23-
2424
public abstract class SampleParentActivity extends Activity {
2525

2626
private LinearLayout headers; // Sample header, inputs and buttons
@@ -102,10 +102,10 @@ protected final void debugHeaders(String TAG, Header[] headers) {
102102
protected static String throwableToString(Throwable t) {
103103
if (t == null)
104104
return null;
105+
105106
StringWriter sw = new StringWriter();
106-
PrintWriter pw = new PrintWriter(sw);
107-
t.printStackTrace(pw);
108-
return pw.toString();
107+
t.printStackTrace(new PrintWriter(sw));
108+
return sw.toString();
109109
}
110110

111111
protected final void debugThrowable(String TAG, Throwable t) {

sample/src/main/java/com/loopj/android/http/sample/DeleteSample.java

Lines changed: 0 additions & 7 deletions
This file was deleted.

sample/src/main/java/com/loopj/android/http/sample/PostSample.java

Lines changed: 0 additions & 7 deletions
This file was deleted.

sample/src/main/java/com/loopj/android/http/sample/PutSample.java

Lines changed: 0 additions & 7 deletions
This file was deleted.

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
include ':library'
2-
include ':sample'
2+
include ':sample/main'

0 commit comments

Comments
 (0)