Skip to content

Commit 90ea903

Browse files
committed
implement DeleteSample and PutSample
1 parent 55d7249 commit 90ea903

File tree

4 files changed

+121
-9
lines changed

4 files changed

+121
-9
lines changed

sample/main/res/values/strings.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +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-
<string name="title_post_sample">POST Sample</string>
8-
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>
910
</resources>
Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,63 @@
11
package com.loopj.android.http.sample;
22

3-
import android.app.Activity;
3+
import org.apache.http.Header;
44

5-
public class DeleteSample extends Activity {
5+
import com.loopj.android.http.AsyncHttpClient;
6+
import com.loopj.android.http.AsyncHttpResponseHandler;
67

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+
}
763
}
Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,63 @@
11
package com.loopj.android.http.sample;
22

3-
import android.app.Activity;
3+
import org.apache.http.Header;
44

5-
public class PutSample extends Activity {
5+
import com.loopj.android.http.AsyncHttpClient;
6+
import com.loopj.android.http.AsyncHttpResponseHandler;
67

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+
}
763
}

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

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

3+
import java.util.Locale;
4+
35
import android.app.Activity;
46
import android.graphics.Color;
57
import android.os.Bundle;
@@ -18,9 +20,6 @@
1820

1921
import org.apache.http.Header;
2022

21-
import java.io.PrintWriter;
22-
import java.io.StringWriter;
23-
2423
public abstract class SampleParentActivity extends Activity {
2524

2625
private LinearLayout headers; // Sample header, inputs and buttons

0 commit comments

Comments
 (0)