Skip to content

Commit 5d2c25f

Browse files
committed
Changes to surrounding classes to accomodate new ImageHttpResponseHandler.
1 parent 4baffcd commit 5d2c25f

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ build
66
local.properties
77
bin/
88
gen/
9-
_layouts
9+
_layouts
10+
res/

src/com/loopj/android/http/AsyncHttpRequest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,17 @@ class AsyncHttpRequest implements Runnable {
3232
private final HttpContext context;
3333
private final HttpUriRequest request;
3434
private final AsyncHttpResponseHandler responseHandler;
35+
private boolean isImageResponseHandler;
3536
private int executionCount;
3637

3738
public AsyncHttpRequest(AbstractHttpClient client, HttpContext context, HttpUriRequest request, AsyncHttpResponseHandler responseHandler) {
3839
this.client = client;
3940
this.context = context;
4041
this.request = request;
4142
this.responseHandler = responseHandler;
43+
if(responseHandler instanceof ImageHttpResponseHandler) {
44+
this.isImageResponseHandler = true;
45+
}
4246
}
4347

4448
public void run() {
@@ -55,7 +59,11 @@ public void run() {
5559
} catch (IOException e) {
5660
if(responseHandler != null) {
5761
responseHandler.sendFinishMessage();
58-
responseHandler.sendFailureMessage(e, null);
62+
if(this.isImageResponseHandler) {
63+
responseHandler.sendFailureMessage(e, (byte[]) null);
64+
} else {
65+
responseHandler.sendFailureMessage(e, (String) null);
66+
}
5967
}
6068
}
6169
}

src/com/loopj/android/http/AsyncHttpResponseHandler.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ protected void sendSuccessMessage(String responseBody) {
138138
protected void sendFailureMessage(Throwable e, String responseBody) {
139139
sendMessage(obtainMessage(FAILURE_MESSAGE, new Object[]{e, responseBody}));
140140
}
141+
142+
protected void sendFailureMessage(Throwable e, byte[] responseBody) {
143+
sendMessage(obtainMessage(FAILURE_MESSAGE, new Object[]{e, responseBody}));
144+
}
141145

142146
protected void sendStartMessage() {
143147
sendMessage(obtainMessage(START_MESSAGE, null));

src/com/loopj/android/http/ImageHttpResponseHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
* });
6969
* </pre>
7070
*/
71-
public class ImageHttpResponseHandler {
71+
public class ImageHttpResponseHandler extends AsyncHttpResponseHandler {
7272
private static final int SUCCESS_MESSAGE = 0;
7373
private static final int FAILURE_MESSAGE = 1;
7474
private static final int START_MESSAGE = 2;
@@ -144,7 +144,7 @@ public void onFailure(Throwable error, byte[] imageData) {
144144
//
145145
// Pre-processing of messages (executes in background threadpool thread)
146146
//
147-
147+
148148
protected void sendSuccessMessage(byte[] responseBody) {
149149
sendMessage(obtainMessage(SUCCESS_MESSAGE, responseBody));
150150
}
@@ -246,7 +246,7 @@ void sendResponseMessage(HttpResponse response) {
246246
}
247247
responseBody = EntityUtils.toByteArray(entity);
248248
} catch(IOException e) {
249-
sendFailureMessage(e, null);
249+
sendFailureMessage(e, (byte[]) null);
250250
}
251251

252252
if(status.getStatusCode() >= 300) {

0 commit comments

Comments
 (0)