Skip to content

Commit

Permalink
Added debugging mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
noordawod committed Jan 1, 2015
1 parent dcc96da commit d3cd3dd
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
4 changes: 2 additions & 2 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fine47.http"
android:versionCode="4"
android:versionName="1.3"
android:versionCode="5"
android:versionName="1.4"
>

<uses-sdk
Expand Down
24 changes: 24 additions & 0 deletions src/com/fine47/http/ActivityHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class ActivityHttpClient extends AsyncHttpClient {
protected final Class<? extends JsonObjectInterface> jsonObjectClass;
protected final Class<? extends JsonArrayInterface> jsonArrayClass;

private static boolean isDebugging;

private Context ctx;
private CookieStore store;
private long lastCleanup;
Expand All @@ -38,6 +40,24 @@ public class ActivityHttpClient extends AsyncHttpClient {
private boolean isWifiConnected;
private boolean isMobileConnected;

/**
* Returns whether debugging mode is turned on.
*
* @return TRUE if debugging is on, FALSE otherwise
*/
public static boolean isDebugging() {
return isDebugging;
}

/**
* Sets debugging mode.
*
* @param value TRUE to turn debugging mode on
*/
public static void setIsDebugging(boolean value) {
isDebugging = value;
}

/**
* Create a new HTTP client and attach it to the specified context.
*
Expand Down Expand Up @@ -78,6 +98,10 @@ public void run() {
isOnline();
}
});

if(isDebugging()) {
Log.d(LOG_TAG, "Created new " + getClass().getName() + " instance.");
}
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/com/fine47/http/Request.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.fine47.http;

import android.util.Log;
import com.fine47.json.JsonArrayInterface;
import com.fine47.json.JsonObjectInterface;
import com.loopj.android.http.AsyncHttpClient;
Expand Down Expand Up @@ -75,6 +76,10 @@ protected Request(String url, String contentType, boolean noCache) {
AsyncHttpClient.HEADER_ACCEPT_ENCODING,
AsyncHttpClient.ENCODING_GZIP)
);

if(ActivityHttpClient.isDebugging()) {
Log.d(ActivityHttpClient.LOG_TAG, "Request: \n" + this);
}
}

/**
Expand Down
11 changes: 11 additions & 0 deletions src/com/fine47/http/ResponseHandler.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.fine47.http;

import android.util.Log;
import com.loopj.android.http.JsonHttpResponseHandler;
import org.apache.http.Header;
import org.json.JSONArray;
Expand Down Expand Up @@ -29,6 +30,11 @@ public void onSuccess(
Header[] headers,
JSONObject result
) {
if(ActivityHttpClient.isDebugging()) {
Log.d(
ActivityHttpClient.LOG_TAG,
"Response JSON (Object): \n" + result.toString());
}
response.onSuccess(
client.normalizeJson(result)
);
Expand All @@ -41,6 +47,11 @@ public void onSuccess(
Header[] headers,
JSONArray result
) {
if(ActivityHttpClient.isDebugging()) {
Log.d(
ActivityHttpClient.LOG_TAG,
"Response JSON (Array): \n" + result.toString());
}
response.onSuccess(
client.normalizeJson(result)
);
Expand Down

0 comments on commit d3cd3dd

Please sign in to comment.