diff --git a/.classpath b/.classpath index 311998ec7..14fcf527f 100644 --- a/.classpath +++ b/.classpath @@ -4,5 +4,5 @@ - + diff --git a/build.xml b/build.xml index 9129325a2..bd3a519cf 100644 --- a/build.xml +++ b/build.xml @@ -1,6 +1,6 @@ - + @@ -68,4 +68,4 @@ - \ No newline at end of file + diff --git a/default.properties b/default.properties deleted file mode 100644 index 3f34fe87c..000000000 --- a/default.properties +++ /dev/null @@ -1,2 +0,0 @@ -target=android-3 -android.library=true diff --git a/project.properties b/project.properties new file mode 100644 index 000000000..1880987e2 --- /dev/null +++ b/project.properties @@ -0,0 +1,12 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system use, +# "ant.properties", and override values to adapt the script to your +# project structure. + +android.library=true +# Project target. +target=android-3 diff --git a/src/com/loopj/android/http/AsyncHttpResponseHandler.java b/src/com/loopj/android/http/AsyncHttpResponseHandler.java index 6eddad6a2..050b92d00 100644 --- a/src/com/loopj/android/http/AsyncHttpResponseHandler.java +++ b/src/com/loopj/android/http/AsyncHttpResponseHandler.java @@ -66,7 +66,7 @@ * }); * */ -public class AsyncHttpResponseHandler { +public abstract class AsyncHttpResponseHandler { private static final int SUCCESS_MESSAGE = 0; private static final int FAILURE_MESSAGE = 1; private static final int START_MESSAGE = 2; @@ -148,29 +148,15 @@ protected void sendFinishMessage() { } - // - // Pre-processing of messages (in original calling thread, typically the UI thread) - // - - protected void handleSuccessMessage(String responseBody) { - onSuccess(responseBody); - } - - protected void handleFailureMessage(Throwable e, String responseBody) { - onFailure(e, responseBody); - } - - - // Methods which emulate android's Handler and Message methods protected void handleMessage(Message msg) { switch(msg.what) { case SUCCESS_MESSAGE: - handleSuccessMessage((String)msg.obj); + onSuccess((String)msg.obj); break; case FAILURE_MESSAGE: Object[] repsonse = (Object[])msg.obj; - handleFailureMessage((Throwable)repsonse[0], (String)repsonse[1]); + onFailure((Throwable)repsonse[0], (String)repsonse[1]); break; case START_MESSAGE: onStart(); @@ -181,7 +167,7 @@ protected void handleMessage(Message msg) { } } - protected void sendMessage(Message msg) { + protected final void sendMessage(Message msg) { if(handler != null){ handler.sendMessage(msg); } else { @@ -189,7 +175,7 @@ protected void sendMessage(Message msg) { } } - protected Message obtainMessage(int responseMessage, Object response) { + protected final Message obtainMessage(int responseMessage, Object response) { Message msg = null; if(handler != null){ msg = this.handler.obtainMessage(responseMessage, response); @@ -203,7 +189,7 @@ protected Message obtainMessage(int responseMessage, Object response) { // Interface to AsyncHttpRequest - void sendResponseMessage(HttpResponse response) { + final void sendResponseMessage(HttpResponse response) { StatusLine status = response.getStatusLine(); String responseBody = null; try { diff --git a/src/com/loopj/android/http/JsonHttpResponseHandler.java b/src/com/loopj/android/http/JsonHttpResponseHandler.java index 59afc1bc4..546493c59 100644 --- a/src/com/loopj/android/http/JsonHttpResponseHandler.java +++ b/src/com/loopj/android/http/JsonHttpResponseHandler.java @@ -35,7 +35,7 @@ * Additionally, you can override the other event methods from the * parent class. */ -public class JsonHttpResponseHandler extends AsyncHttpResponseHandler { +public abstract class JsonHttpResponseHandler extends AsyncHttpResponseHandler { // // Callbacks to be overridden, typically anonymously // @@ -60,22 +60,18 @@ public void onSuccess(JSONArray response) {} // Utility methods @Override - protected void handleSuccessMessage(String responseBody) { - super.handleSuccessMessage(responseBody); - + public final void onSuccess(String responseBody) { try { - Object jsonResponse = parseResponse(responseBody); + Object jsonResponse = new JSONTokener(responseBody).nextValue(); if(jsonResponse instanceof JSONObject) { onSuccess((JSONObject)jsonResponse); } else if(jsonResponse instanceof JSONArray) { onSuccess((JSONArray)jsonResponse); + } else { + throw new JSONException("Unexpected type " + jsonResponse.getClass().getName()); } } catch(JSONException e) { onFailure(e, responseBody); } } - - protected Object parseResponse(String responseBody) throws JSONException { - return new JSONTokener(responseBody).nextValue(); - } } \ No newline at end of file