Skip to content

Commit a8bb750

Browse files
committed
Added HeadSample to sample application, Closing android-async-http#922
1 parent 4bffe5f commit a8bb750

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

sample/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<activity android:name=".GetSample" />
2626
<activity android:name=".PostSample" />
2727
<activity android:name=".DeleteSample" />
28+
<activity android:name=".HeadSample" />
2829
<activity android:name=".PutSample" />
2930
<activity android:name=".PatchSample" />
3031
<activity android:name=".JsonSample" />
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
Copyright (c) 2015 Marek Sebera <[email protected]>
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
https://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
package com.loopj.android.http.sample;
17+
18+
import com.loopj.android.http.AsyncHttpClient;
19+
import com.loopj.android.http.AsyncHttpResponseHandler;
20+
import com.loopj.android.http.RequestHandle;
21+
import com.loopj.android.http.ResponseHandlerInterface;
22+
23+
import cz.msebera.android.httpclient.Header;
24+
import cz.msebera.android.httpclient.HttpEntity;
25+
26+
public class HeadSample extends FileSample {
27+
28+
private static final String LOG_TAG = "HeadSample";
29+
30+
@Override
31+
public ResponseHandlerInterface getResponseHandler() {
32+
return new AsyncHttpResponseHandler() {
33+
@Override
34+
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
35+
debugStatusCode(LOG_TAG, statusCode);
36+
debugHeaders(LOG_TAG, headers);
37+
debugResponse(LOG_TAG, String.format("Response of size: %d", responseBody == null ? 0 : responseBody.length));
38+
}
39+
40+
@Override
41+
public void onProgress(long bytesWritten, long totalSize) {
42+
addView(getColoredView(LIGHTRED, String.format("Progress %d from %d", bytesWritten, totalSize)));
43+
}
44+
45+
@Override
46+
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable throwable) {
47+
debugStatusCode(LOG_TAG, statusCode);
48+
debugHeaders(LOG_TAG, headers);
49+
debugThrowable(LOG_TAG, throwable);
50+
debugResponse(LOG_TAG, String.format("Response of size: %d", responseBody == null ? 0 : responseBody.length));
51+
}
52+
};
53+
}
54+
55+
@Override
56+
public RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, ResponseHandlerInterface responseHandler) {
57+
return client.head(this, URL, headers, null, responseHandler);
58+
}
59+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class WaypointsActivity extends ListActivity {
3636
new SampleConfig(R.string.title_delete_sample, DeleteSample.class),
3737
new SampleConfig(R.string.title_put_sample, PutSample.class),
3838
new SampleConfig(R.string.title_patch_sample, PatchSample.class),
39+
new SampleConfig(R.string.title_head_sample, HeadSample.class),
3940
new SampleConfig(R.string.title_json_sample, JsonSample.class),
4041
new SampleConfig(R.string.title_json_streamer_sample, JsonStreamerSample.class),
4142
new SampleConfig(R.string.title_sax_example, SaxSample.class),

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<string name="title_post_sample">POST</string>
2424
<string name="title_put_sample">PUT</string>
2525
<string name="title_patch_sample">PATCH</string>
26+
<string name="title_head_sample">HEAD</string>
2627
<string name="title_delete_sample">DELETE</string>
2728
<string name="title_file_sample">GET to File</string>
2829
<string name="title_directory_sample">GET to Directory</string>

0 commit comments

Comments
 (0)