Skip to content

Make methods that can't be overridden final, inline unneeded ones #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="src" path="examples"/>
<classpathentry kind="output" path="bin"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
4 changes: 2 additions & 2 deletions build.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<project default="package">
<property file="local.properties"/>
<property file="default.properties"/>
<property file="project.properties"/>

<!-- Package properties -->
<property name="package.name" value="android-async-http" />
Expand Down Expand Up @@ -68,4 +68,4 @@

<!-- Compile and package a jar -->
<target name="package" depends="compile,jar" />
</project>
</project>
2 changes: 0 additions & 2 deletions default.properties

This file was deleted.

12 changes: 12 additions & 0 deletions project.properties
Original file line number Diff line number Diff line change
@@ -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
26 changes: 6 additions & 20 deletions src/com/loopj/android/http/AsyncHttpResponseHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
* });
* </pre>
*/
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;
Expand Down Expand Up @@ -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();
Expand All @@ -181,15 +167,15 @@ protected void handleMessage(Message msg) {
}
}

protected void sendMessage(Message msg) {
protected final void sendMessage(Message msg) {
if(handler != null){
handler.sendMessage(msg);
} else {
handleMessage(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);
Expand All @@ -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 {
Expand Down
14 changes: 5 additions & 9 deletions src/com/loopj/android/http/JsonHttpResponseHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand All @@ -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();
}
}