From 9cbd8c726d756ee92ed8237673648e1c5e3a74eb Mon Sep 17 00:00:00 2001 From: Carsten Draeger Date: Tue, 13 Aug 2013 11:16:14 +0200 Subject: [PATCH 1/2] Simple option to set the charset for the response string. Default is still "UTF-8". --- .../loopj/android/http/AsyncHttpResponseHandler.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/com/loopj/android/http/AsyncHttpResponseHandler.java b/src/com/loopj/android/http/AsyncHttpResponseHandler.java index 2030265f5..3227c62b0 100644 --- a/src/com/loopj/android/http/AsyncHttpResponseHandler.java +++ b/src/com/loopj/android/http/AsyncHttpResponseHandler.java @@ -36,7 +36,7 @@ /** * Used to intercept and handle the responses from requests made using - * {@link AsyncHttpClient}. The {@link #onSuccess(String)} method is + * {@link AsyncHttpClient}. The {@link #onSuccess(String)} method is * designed to be anonymously overridden with your own response handling code. *

* Additionally, you can override the {@link #onFailure(Throwable, String)}, @@ -76,6 +76,7 @@ public class AsyncHttpResponseHandler { protected static final int FINISH_MESSAGE = 3; private Handler handler; + private String charset = "UTF-8"; /** * Creates a new AsyncHttpResponseHandler @@ -92,7 +93,6 @@ public void handleMessage(Message msg){ } } - // // Callbacks to be overridden, typically anonymously // @@ -213,6 +213,10 @@ protected void handleMessage(Message msg) { } } + public void setCharset(final String charset) { + this.charset = charset; + } + protected void sendMessage(Message msg) { if(handler != null){ handler.sendMessage(msg); @@ -242,7 +246,7 @@ void sendResponseMessage(HttpResponse response) { HttpEntity temp = response.getEntity(); if(temp != null) { entity = new BufferedHttpEntity(temp); - responseBody = EntityUtils.toString(entity, "UTF-8"); + responseBody = EntityUtils.toString(entity, charset); } } catch(IOException e) { sendFailureMessage(e, (String) null); From eb7c6727e7c2101925cd2de8f62ffa349c0a35c8 Mon Sep 17 00:00:00 2001 From: Carsten Draeger Date: Tue, 13 Aug 2013 11:27:20 +0200 Subject: [PATCH 2/2] Added JavaDoc. --- src/com/loopj/android/http/AsyncHttpResponseHandler.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/com/loopj/android/http/AsyncHttpResponseHandler.java b/src/com/loopj/android/http/AsyncHttpResponseHandler.java index 3227c62b0..0491c9b32 100644 --- a/src/com/loopj/android/http/AsyncHttpResponseHandler.java +++ b/src/com/loopj/android/http/AsyncHttpResponseHandler.java @@ -213,6 +213,12 @@ protected void handleMessage(Message msg) { } } + /** + * Sets the charset for the response string. If not set, the default is UTF-8. + * @see Charset + * + * @param charset to be used for the response string. + */ public void setCharset(final String charset) { this.charset = charset; }