Skip to content

Commit 9e117fa

Browse files
committed
Added SampleInterface, fixed interface methods to use abstract interfaces
1 parent 70df3d0 commit 9e117fa

13 files changed

+110
-78
lines changed

sample/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<activity android:name=".ThreadingTimeoutSample"/>
2727
<activity android:name=".CancelAllRequestsSample"/>
2828
<activity android:name=".CancelRequestHandleSample"/>
29+
<activity android:name=".SynchronousClientSample"/>
2930
</application>
3031

3132
</manifest>

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

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

33
import com.loopj.android.http.AsyncHttpClient;
4-
import com.loopj.android.http.AsyncHttpResponseHandler;
54
import com.loopj.android.http.BinaryHttpResponseHandler;
65
import com.loopj.android.http.RequestHandle;
6+
import com.loopj.android.http.ResponseHandlerInterface;
77

88
import org.apache.http.Header;
99
import org.apache.http.HttpEntity;
@@ -12,27 +12,27 @@ public class BinarySample extends SampleParentActivity {
1212
private static final String LOG_TAG = "BinarySample";
1313

1414
@Override
15-
protected int getSampleTitle() {
15+
public int getSampleTitle() {
1616
return R.string.title_binary_sample;
1717
}
1818

1919
@Override
20-
protected boolean isRequestBodyAllowed() {
20+
public boolean isRequestBodyAllowed() {
2121
return false;
2222
}
2323

2424
@Override
25-
protected boolean isRequestHeadersAllowed() {
25+
public boolean isRequestHeadersAllowed() {
2626
return true;
2727
}
2828

2929
@Override
30-
protected String getDefaultURL() {
30+
public String getDefaultURL() {
3131
return "http://httpbin.org/gzip";
3232
}
3333

3434
@Override
35-
protected AsyncHttpResponseHandler getResponseHandler() {
35+
public ResponseHandlerInterface getResponseHandler() {
3636
return new BinaryHttpResponseHandler() {
3737
@Override
3838
public void onStart() {
@@ -64,7 +64,7 @@ public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Th
6464
}
6565

6666
@Override
67-
protected RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, AsyncHttpResponseHandler responseHandler) {
67+
public RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, ResponseHandlerInterface responseHandler) {
6868
return client.get(this, URL, headers, null, responseHandler);
6969
}
7070
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
public class CancelAllRequestsSample extends ThreadingTimeoutSample {
44

55
@Override
6-
protected int getSampleTitle() {
6+
public int getSampleTitle() {
77
return R.string.title_cancel_all;
88
}
99

1010
@Override
11-
protected void onCancelButtonPressed() {
11+
public void onCancelButtonPressed() {
1212
getAsyncHttpClient().cancelAllRequests(true);
1313
}
1414
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
public class CancelRequestHandleSample extends ThreadingTimeoutSample {
66

77
@Override
8-
protected int getSampleTitle() {
8+
public int getSampleTitle() {
99
return R.string.title_cancel_handle;
1010
}
1111

1212
@Override
13-
protected void onCancelButtonPressed() {
13+
public void onCancelButtonPressed() {
1414
for (RequestHandle handle : getRequestHandles()) {
1515
if (!handle.isCancelled() && !handle.isFinished()) {
1616
handle.cancel(true);

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.loopj.android.http.AsyncHttpClient;
44
import com.loopj.android.http.AsyncHttpResponseHandler;
55
import com.loopj.android.http.RequestHandle;
6+
import com.loopj.android.http.ResponseHandlerInterface;
67

78
import org.apache.http.Header;
89
import org.apache.http.HttpEntity;
@@ -11,33 +12,33 @@ public class DeleteSample extends SampleParentActivity {
1112
private static final String LOG_TAG = "DeleteSample";
1213

1314
@Override
14-
protected RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, AsyncHttpResponseHandler responseHandler) {
15+
public RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, ResponseHandlerInterface responseHandler) {
1516
return client.delete(this, URL, headers, null, responseHandler);
1617
}
1718

1819
@Override
19-
protected int getSampleTitle() {
20+
public int getSampleTitle() {
2021
return R.string.title_delete_sample;
2122
}
2223

2324
@Override
24-
protected boolean isRequestBodyAllowed() {
25+
public boolean isRequestBodyAllowed() {
2526
// HttpDelete is not HttpEntityEnclosingRequestBase, thus cannot contain body
2627
return false;
2728
}
2829

2930
@Override
30-
protected boolean isRequestHeadersAllowed() {
31+
public boolean isRequestHeadersAllowed() {
3132
return true;
3233
}
3334

3435
@Override
35-
protected String getDefaultURL() {
36+
public String getDefaultURL() {
3637
return "http://httpbin.org/delete";
3738
}
3839

3940
@Override
40-
protected AsyncHttpResponseHandler getResponseHandler() {
41+
public ResponseHandlerInterface getResponseHandler() {
4142
return new AsyncHttpResponseHandler() {
4243

4344
@Override

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import android.util.Log;
44

55
import com.loopj.android.http.AsyncHttpClient;
6-
import com.loopj.android.http.AsyncHttpResponseHandler;
76
import com.loopj.android.http.FileAsyncHttpResponseHandler;
87
import com.loopj.android.http.RequestHandle;
8+
import com.loopj.android.http.ResponseHandlerInterface;
99
import com.loopj.android.http.sample.util.FileUtil;
1010

1111
import org.apache.http.Header;
@@ -17,27 +17,27 @@ public class FileSample extends SampleParentActivity {
1717
private static final String LOG_TAG = "FileSample";
1818

1919
@Override
20-
protected int getSampleTitle() {
20+
public int getSampleTitle() {
2121
return R.string.title_file_sample;
2222
}
2323

2424
@Override
25-
protected boolean isRequestBodyAllowed() {
25+
public boolean isRequestBodyAllowed() {
2626
return false;
2727
}
2828

2929
@Override
30-
protected boolean isRequestHeadersAllowed() {
30+
public boolean isRequestHeadersAllowed() {
3131
return true;
3232
}
3333

3434
@Override
35-
protected String getDefaultURL() {
35+
public String getDefaultURL() {
3636
return "https://httpbin.org/robots.txt";
3737
}
3838

3939
@Override
40-
protected AsyncHttpResponseHandler getResponseHandler() {
40+
public ResponseHandlerInterface getResponseHandler() {
4141
return new FileAsyncHttpResponseHandler(this) {
4242
@Override
4343
public void onStart() {
@@ -77,7 +77,7 @@ private void debugFile(File file) {
7777
}
7878

7979
@Override
80-
protected RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, AsyncHttpResponseHandler responseHandler) {
80+
public RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, ResponseHandlerInterface responseHandler) {
8181
return client.get(this, URL, headers, null, responseHandler);
8282
}
8383
}

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.loopj.android.http.AsyncHttpClient;
44
import com.loopj.android.http.AsyncHttpResponseHandler;
55
import com.loopj.android.http.RequestHandle;
6+
import com.loopj.android.http.ResponseHandlerInterface;
67

78
import org.apache.http.Header;
89
import org.apache.http.HttpEntity;
@@ -11,32 +12,32 @@ public class GetSample extends SampleParentActivity {
1112
private static final String LOG_TAG = "GetSample";
1213

1314
@Override
14-
protected RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, AsyncHttpResponseHandler responseHandler) {
15+
public RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, ResponseHandlerInterface responseHandler) {
1516
return client.get(this, URL, headers, null, responseHandler);
1617
}
1718

1819
@Override
19-
protected int getSampleTitle() {
20+
public int getSampleTitle() {
2021
return R.string.title_get_sample;
2122
}
2223

2324
@Override
24-
protected boolean isRequestBodyAllowed() {
25+
public boolean isRequestBodyAllowed() {
2526
return false;
2627
}
2728

2829
@Override
29-
protected boolean isRequestHeadersAllowed() {
30+
public boolean isRequestHeadersAllowed() {
3031
return true;
3132
}
3233

3334
@Override
34-
protected String getDefaultURL() {
35+
public String getDefaultURL() {
3536
return "https://httpbin.org/get";
3637
}
3738

3839
@Override
39-
protected AsyncHttpResponseHandler getResponseHandler() {
40+
public ResponseHandlerInterface getResponseHandler() {
4041
return new AsyncHttpResponseHandler() {
4142

4243
@Override

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import com.fasterxml.jackson.core.JsonFactory;
44
import com.fasterxml.jackson.databind.ObjectMapper;
55
import com.loopj.android.http.AsyncHttpClient;
6-
import com.loopj.android.http.AsyncHttpResponseHandler;
76
import com.loopj.android.http.BaseJsonHttpResponseHandler;
87
import com.loopj.android.http.RequestHandle;
8+
import com.loopj.android.http.ResponseHandlerInterface;
99
import com.loopj.android.http.sample.util.SampleJSON;
1010

1111
import org.apache.http.Header;
@@ -16,32 +16,32 @@ public class JsonSample extends SampleParentActivity {
1616
private static final String LOG_TAG = "JsonSample";
1717

1818
@Override
19-
protected RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, AsyncHttpResponseHandler responseHandler) {
19+
public RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, ResponseHandlerInterface responseHandler) {
2020
return client.get(this, URL, headers, null, responseHandler);
2121
}
2222

2323
@Override
24-
protected int getSampleTitle() {
24+
public int getSampleTitle() {
2525
return R.string.title_json_sample;
2626
}
2727

2828
@Override
29-
protected boolean isRequestBodyAllowed() {
29+
public boolean isRequestBodyAllowed() {
3030
return false;
3131
}
3232

3333
@Override
34-
protected boolean isRequestHeadersAllowed() {
34+
public boolean isRequestHeadersAllowed() {
3535
return false;
3636
}
3737

3838
@Override
39-
protected String getDefaultURL() {
39+
public String getDefaultURL() {
4040
return "http://httpbin.org/headers";
4141
}
4242

4343
@Override
44-
protected AsyncHttpResponseHandler getResponseHandler() {
44+
public ResponseHandlerInterface getResponseHandler() {
4545
return new BaseJsonHttpResponseHandler<SampleJSON>() {
4646

4747
@Override

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.loopj.android.http.AsyncHttpClient;
44
import com.loopj.android.http.AsyncHttpResponseHandler;
55
import com.loopj.android.http.RequestHandle;
6+
import com.loopj.android.http.ResponseHandlerInterface;
67

78
import org.apache.http.Header;
89
import org.apache.http.HttpEntity;
@@ -11,32 +12,32 @@ public class PostSample extends SampleParentActivity {
1112
private static final String LOG_TAG = "PostSample";
1213

1314
@Override
14-
protected RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, AsyncHttpResponseHandler responseHandler) {
15+
public RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, ResponseHandlerInterface responseHandler) {
1516
return client.post(this, URL, headers, entity, null, responseHandler);
1617
}
1718

1819
@Override
19-
protected int getSampleTitle() {
20+
public int getSampleTitle() {
2021
return R.string.title_post_sample;
2122
}
2223

2324
@Override
24-
protected boolean isRequestBodyAllowed() {
25+
public boolean isRequestBodyAllowed() {
2526
return true;
2627
}
2728

2829
@Override
29-
protected boolean isRequestHeadersAllowed() {
30+
public boolean isRequestHeadersAllowed() {
3031
return true;
3132
}
3233

3334
@Override
34-
protected String getDefaultURL() {
35+
public String getDefaultURL() {
3536
return "http://httpbin.org/post";
3637
}
3738

3839
@Override
39-
protected AsyncHttpResponseHandler getResponseHandler() {
40+
public ResponseHandlerInterface getResponseHandler() {
4041
return new AsyncHttpResponseHandler() {
4142

4243
@Override

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.loopj.android.http.AsyncHttpClient;
44
import com.loopj.android.http.AsyncHttpResponseHandler;
55
import com.loopj.android.http.RequestHandle;
6+
import com.loopj.android.http.ResponseHandlerInterface;
67

78
import org.apache.http.Header;
89
import org.apache.http.HttpEntity;
@@ -11,32 +12,32 @@ public class PutSample extends SampleParentActivity {
1112
private static final String LOG_TAG = "PutSample";
1213

1314
@Override
14-
protected RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, AsyncHttpResponseHandler responseHandler) {
15+
public RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, ResponseHandlerInterface responseHandler) {
1516
return client.put(this, URL, headers, entity, null, responseHandler);
1617
}
1718

1819
@Override
19-
protected int getSampleTitle() {
20+
public int getSampleTitle() {
2021
return R.string.title_put_sample;
2122
}
2223

2324
@Override
24-
protected boolean isRequestBodyAllowed() {
25+
public boolean isRequestBodyAllowed() {
2526
return true;
2627
}
2728

2829
@Override
29-
protected boolean isRequestHeadersAllowed() {
30+
public boolean isRequestHeadersAllowed() {
3031
return true;
3132
}
3233

3334
@Override
34-
protected String getDefaultURL() {
35+
public String getDefaultURL() {
3536
return "http://httpbin.org/put";
3637
}
3738

3839
@Override
39-
protected AsyncHttpResponseHandler getResponseHandler() {
40+
public ResponseHandlerInterface getResponseHandler() {
4041
return new AsyncHttpResponseHandler() {
4142

4243
@Override

0 commit comments

Comments
 (0)