Skip to content

Commit

Permalink
ANDROID-604 Rename internal Log class to ApptentiveLog
Browse files Browse the repository at this point in the history
  • Loading branch information
Barry Li committed Mar 21, 2016
1 parent b134b60 commit f3b0f5b
Show file tree
Hide file tree
Showing 98 changed files with 655 additions and 664 deletions.
115 changes: 57 additions & 58 deletions apptentive/src/com/apptentive/android/sdk/Apptentive.java

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions apptentive/src/com/apptentive/android/sdk/ApptentiveInternal.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static PushAction parse(String name) {
try {
return PushAction.valueOf(name);
} catch (IllegalArgumentException e) {
Log.d("Error parsing unknown PushAction: " + name);
ApptentiveLog.d("Error parsing unknown PushAction: " + name);
}
return unknown;
}
Expand Down Expand Up @@ -100,17 +100,17 @@ public static OnSurveyFinishedListener getOnSurveyFinishedListener() {
}

/**
* Pass in a log level to override the default, which is {@link Log.Level#INFO}
* Pass in a log level to override the default, which is {@link ApptentiveLog.Level#INFO}
*
*/
public static void setMinimumLogLevel(Log.Level level) {
Log.overrideLogLevel(level);
public static void setMinimumLogLevel(ApptentiveLog.Level level) {
ApptentiveLog.overrideLogLevel(level);
}

private static String pushCallbackActivityName;
public static void setPushCallbackActivity(Class<? extends Activity> activity) {
pushCallbackActivityName = activity.getName();
Log.d("Setting push callback activity name to %s", pushCallbackActivityName);
ApptentiveLog.d("Setting push callback activity name to %s", pushCallbackActivityName);
}

public static String getPushCallbackActivityName() {
Expand All @@ -127,20 +127,20 @@ public static String getPushCallbackActivityName() {
static String getApptentivePushNotificationData(Intent intent) {
String apptentive = null;
if (intent != null) {
Log.v("Got an Intent.");
ApptentiveLog.v("Got an Intent.");
// Parse
if (intent.hasExtra(PARSE_PUSH_EXTRA_KEY)) {
String parseStringExtra = intent.getStringExtra(PARSE_PUSH_EXTRA_KEY);
Log.v("Got a Parse Push.");
ApptentiveLog.v("Got a Parse Push.");
try {
JSONObject parseJson = new JSONObject(parseStringExtra);
apptentive = parseJson.optString(APPTENTIVE_PUSH_EXTRA_KEY, null);
} catch (JSONException e) {
Log.e("Corrupt Parse String Extra: %s", parseStringExtra);
ApptentiveLog.e("Corrupt Parse String Extra: %s", parseStringExtra);
}
} else {
// Straight GCM / SNS
Log.v("Got a non-Parse push.");
ApptentiveLog.v("Got a non-Parse push.");
apptentive = intent.getStringExtra(APPTENTIVE_PUSH_EXTRA_KEY);
}
}
Expand All @@ -156,7 +156,7 @@ static String getApptentivePushNotificationData(Bundle pushBundle) {

static boolean setPendingPushNotification(Context context, String apptentivePushData) {
if (apptentivePushData != null) {
Log.d("Saving Apptentive push notification data.");
ApptentiveLog.d("Saving Apptentive push notification data.");
SharedPreferences prefs = context.getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE);
prefs.edit().putString(Constants.PREF_KEY_PENDING_PUSH_NOTIFICATION, apptentivePushData).commit();
MessageManager.startMessagePreFetchTask(context);
Expand All @@ -181,7 +181,7 @@ public static boolean showMessageCenterInternal(Activity activity, Map<String, O
value instanceof Float ||
value instanceof Integer ||
value instanceof Short)) {
Log.w("Removing invalid customData type: %s", value.getClass().getSimpleName());
ApptentiveLog.w("Removing invalid customData type: %s", value.getClass().getSimpleName());
keysIterator.remove();
}
}
Expand Down Expand Up @@ -224,7 +224,7 @@ public static void addCustomDeviceData(Context context, String key, Object value
customData.put(key, value);
DeviceManager.storeCustomDeviceData(context, customData);
} catch (JSONException e) {
Log.w("Unable to add custom device data.", e);
ApptentiveLog.w("Unable to add custom device data.", e);
}
}
}
Expand All @@ -239,7 +239,7 @@ public static void addCustomPersonData(Context context, String key, Object value
customData.put(key, value);
PersonManager.storeCustomPersonData(context, customData);
} catch (JSONException e) {
Log.w("Unable to add custom person data.", e);
ApptentiveLog.w("Unable to add custom person data.", e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
/**
* @author Sky Kelsey
*/
public class Log {
public class ApptentiveLog {
private static final String TAG = "Apptentive";

private static Level logLevel = Level.DEFAULT;

public static void overrideLogLevel(Level level) {
Log.logLevel = level;
ApptentiveLog.logLevel = level;
}

private static void doLog(Level level, Throwable throwable, String message, Object... args){
Expand Down
11 changes: 5 additions & 6 deletions apptentive/src/com/apptentive/android/sdk/ViewActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package com.apptentive.android.sdk;

import android.content.Intent;
import android.content.res.Resources;
import android.graphics.PixelFormat;
import android.os.Build;
import android.os.Bundle;
Expand Down Expand Up @@ -55,7 +54,7 @@ protected void onCreate(Bundle savedInstanceState) {
String activityContentTypeString = getIntent().getStringExtra(ActivityContent.KEY);
Interaction interaction = null;
if (activityContentTypeString != null) {
Log.v("Started ViewActivity normally for %s.", activityContent);
ApptentiveLog.v("Started ViewActivity normally for %s.", activityContent);
activeContentType = ActivityContent.Type.parse(activityContentTypeString);

/* The default status bar color fallback order are,
Expand Down Expand Up @@ -141,7 +140,7 @@ protected void onCreate(Bundle savedInstanceState) {
case INTERACTION:
break; // end INTERACTION
default:
Log.w("No Activity specified. Finishing...");
ApptentiveLog.w("No Activity specified. Finishing...");
break;
}
if (activityContentRequired) {
Expand All @@ -152,12 +151,12 @@ protected void onCreate(Bundle savedInstanceState) {
}
}
} catch (Exception e) {
Log.e("Error starting ViewActivity.", e);
ApptentiveLog.e("Error starting ViewActivity.", e);
MetricModule.sendError(this, e, null, null);
}
}
} catch (Exception e) {
Log.e("Error creating ViewActivity.", e);
ApptentiveLog.e("Error creating ViewActivity.", e);
MetricModule.sendError(this, e, null, null);
}
if (activeContentType == null) {
Expand All @@ -183,7 +182,7 @@ protected void onStart() {
super.onStart();
break;
default:
Log.w("No Activity specified. Finishing...");
ApptentiveLog.w("No Activity specified. Finishing...");
finish();
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import android.text.TextUtils;

import com.apptentive.android.sdk.GlobalInfo;
import com.apptentive.android.sdk.Log;
import com.apptentive.android.sdk.ApptentiveLog;
import com.apptentive.android.sdk.model.*;
import com.apptentive.android.sdk.module.messagecenter.model.ApptentiveMessage;
import com.apptentive.android.sdk.module.messagecenter.model.CompoundMessage;
Expand Down Expand Up @@ -129,12 +129,12 @@ public static ApptentiveHttpResponse getInteractions(Context appContext) {
*/
private static ApptentiveHttpResponse performHttpRequest(Context appContext, String oauthToken, String uri, Method method, String body) {
uri = getEndpointBase(appContext) + uri;
Log.d("Performing %s request to %s", method.name(), uri);
ApptentiveLog.d("Performing %s request to %s", method.name(), uri);
//Log.e("OAUTH Token: %s", oauthToken);

ApptentiveHttpResponse ret = new ApptentiveHttpResponse();
if (!Util.isNetworkConnectionPresent(appContext)) {
Log.d("Network unavailable.");
ApptentiveLog.d("Network unavailable.");
return ret;
}

Expand Down Expand Up @@ -163,14 +163,14 @@ private static ApptentiveHttpResponse performHttpRequest(Context appContext, Str
sendPostPutRequest(connection, "POST", body);
break;
default:
Log.e("Unrecognized method: " + method.name());
ApptentiveLog.e("Unrecognized method: " + method.name());
return ret;
}

int responseCode = connection.getResponseCode();
ret.setCode(responseCode);
ret.setReason(connection.getResponseMessage());
Log.d("Response Status Line: " + connection.getResponseMessage());
ApptentiveLog.d("Response Status Line: " + connection.getResponseMessage());

// Get the Http response header values
Map<String, String> headers = new HashMap<String, String>();
Expand All @@ -181,36 +181,36 @@ private static ApptentiveHttpResponse performHttpRequest(Context appContext, Str
ret.setHeaders(headers);

// Read the response, if available
Log.d("HTTP %d: %s", connection.getResponseCode(), connection.getResponseMessage());
ApptentiveLog.d("HTTP %d: %s", connection.getResponseCode(), connection.getResponseMessage());
if (responseCode >= 200 && responseCode < 300) {
ret.setContent(getResponse(connection, ret.isZipped()));
Log.v("Response: %s", ret.getContent());
ApptentiveLog.v("Response: %s", ret.getContent());
} else {
ret.setContent(getErrorResponse(connection, ret.isZipped()));
Log.w("Response: %s", ret.getContent());
ApptentiveLog.w("Response: %s", ret.getContent());
}
} catch (IllegalArgumentException e) {
Log.w("Error communicating with server.", e);
ApptentiveLog.w("Error communicating with server.", e);
} catch (SocketTimeoutException e) {
Log.w("Timeout communicating with server.", e);
ApptentiveLog.w("Timeout communicating with server.", e);
} catch (final MalformedURLException e) {
Log.w("MalformedUrlException", e);
ApptentiveLog.w("MalformedUrlException", e);
} catch (final IOException e) {
Log.w("IOException", e);
ApptentiveLog.w("IOException", e);
// Read the error response.
try {
ret.setContent(getErrorResponse(connection, ret.isZipped()));
Log.w("Response: " + ret.getContent());
ApptentiveLog.w("Response: " + ret.getContent());
} catch (IOException ex) {
Log.w("Can't read error stream.", ex);
ApptentiveLog.w("Can't read error stream.", ex);
}
}
return ret;
}

private static void sendPostPutRequest(final HttpURLConnection connection, final String requestMethod, String body) throws IOException {

Log.d("%s body: %s", requestMethod, body);
ApptentiveLog.d("%s body: %s", requestMethod, body);

connection.setRequestMethod(requestMethod);
connection.setDoInput(true);
Expand All @@ -234,12 +234,12 @@ private static void sendPostPutRequest(final HttpURLConnection connection, final

private static ApptentiveHttpResponse performMultipartFilePost(Context appContext, String oauthToken, String uri, String postBody, List<StoredFile> associatedFiles) {
uri = getEndpointBase(appContext) + uri;
Log.d("Performing multipart POST to %s", uri);
Log.d("Multipart POST body: %s", postBody);
ApptentiveLog.d("Performing multipart POST to %s", uri);
ApptentiveLog.d("Multipart POST body: %s", postBody);

ApptentiveHttpResponse ret = new ApptentiveHttpResponse();
if (!Util.isNetworkConnectionPresent(appContext)) {
Log.d("Network unavailable.");
ApptentiveLog.d("Network unavailable.");
return ret;
}

Expand Down Expand Up @@ -336,7 +336,7 @@ private static ApptentiveHttpResponse performMultipartFilePost(Context appContex
bytesRead = fis.read(buffer, 0, bufferSize);
}
} catch (IOException e) {
Log.d("Error writing file bytes to HTTP connection.", e);
ApptentiveLog.d("Error writing file bytes to HTTP connection.", e);
ret.setBadPayload(true);
throw e;
} finally {
Expand Down Expand Up @@ -370,20 +370,20 @@ private static ApptentiveHttpResponse performMultipartFilePost(Context appContex
Util.ensureClosed(nbaos);
}

Log.d("HTTP %d: %s", connection.getResponseCode(), connection.getResponseMessage());
Log.v("Response: %s", ret.getContent());
ApptentiveLog.d("HTTP %d: %s", connection.getResponseCode(), connection.getResponseMessage());
ApptentiveLog.v("Response: %s", ret.getContent());
} catch (FileNotFoundException e) {
Log.e("Error getting file to upload.", e);
ApptentiveLog.e("Error getting file to upload.", e);
} catch (MalformedURLException e) {
Log.e("Error constructing url for file upload.", e);
ApptentiveLog.e("Error constructing url for file upload.", e);
} catch (SocketTimeoutException e) {
Log.w("Timeout communicating with server.");
ApptentiveLog.w("Timeout communicating with server.");
} catch (IOException e) {
Log.e("Error executing file upload.", e);
ApptentiveLog.e("Error executing file upload.", e);
try {
ret.setContent(getErrorResponse(connection, ret.isZipped()));
} catch (IOException ex) {
Log.w("Can't read error stream.", ex);
ApptentiveLog.w("Can't read error stream.", ex);
}
} finally {
Util.ensureClosed(os);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import android.app.Activity;
import android.content.Context;
import com.apptentive.android.sdk.ApptentiveInternal;
import com.apptentive.android.sdk.Log;
import com.apptentive.android.sdk.ApptentiveLog;
import com.apptentive.android.sdk.SessionEvent;
import com.apptentive.android.sdk.model.Event;
import com.apptentive.android.sdk.module.engagement.EngagementModule;
Expand Down Expand Up @@ -64,7 +64,7 @@ private static void sendEvent(Activity activity, SessionEvent event) {
}

private static void sendEvent(Activity activity, SessionEvent event, boolean crash) {
Log.d("Sending " + event.getDebugString());
ApptentiveLog.d("Sending " + event.getDebugString());
switch (event.getAction()) {
case START:
if (!crash) {
Expand Down Expand Up @@ -102,14 +102,14 @@ public static void activityStarted(Activity activity) {
// Due to the nature of the Activity Lifecycle, onStart() of the next Activity may be called before or after
// the onStart() of the current previous Activity. This complicated the detection. This is the distilled logic.
if (pairs == 0 && starts == 0) {
Log.v("First start.");
ApptentiveLog.v("First start.");
addEvents(start);
sendEvent(activity, start);
} else if (pairs == 0 && starts == 1) {
Log.v("Continuation Start. (1)");
ApptentiveLog.v("Continuation Start. (1)");
addEvents(start);
} else if (pairs == 0 && starts == 2) {
Log.i("Starting new session after crash. (1)");
ApptentiveLog.i("Starting new session after crash. (1)");
removeAllEvents();
sendEvent(activity, lastStart != null ? lastStart : start, true);
addEvents(lastStart, start);
Expand All @@ -118,26 +118,26 @@ public static void activityStarted(Activity activity) {
boolean expired = expiration < start.getTime();
addEvents(start);
if (expired) {
Log.d("Session expired. Starting new session.");
ApptentiveLog.d("Session expired. Starting new session.");
sendEvent(activity, lastStop);
sendEvent(activity, start);
} else {
Log.v("Continuation Start. (2)");
ApptentiveLog.v("Continuation Start. (2)");
}
} else if (pairs == 1 && starts == 2) {
Log.v("Continuation start. (3)");
ApptentiveLog.v("Continuation start. (3)");
addEvents(start);
} else if (pairs == 1 && starts == 3) {
Log.i("Starting new session after crash. (2)");
ApptentiveLog.i("Starting new session after crash. (2)");
sendEvent(activity, lastStart != null ? lastStart : start, true);
// Reconstruct Queue.
removeAllEvents();
addEvents(lastStart, start);
} else {
Log.w("ERROR: Unexpected state in LifecycleManager: " + getQueueAsString());
ApptentiveLog.w("ERROR: Unexpected state in LifecycleManager: " + getQueueAsString());
}
} catch (Exception e) {
Log.e("Error while handling activity start.", e);
ApptentiveLog.e("Error while handling activity start.", e);
}
}

Expand All @@ -149,7 +149,7 @@ public static void activityStopped(Activity activity) {
init(activity);
addEvents(new SessionEvent(new Date().getTime(), SessionEvent.Action.STOP, activity.toString()));
} catch (Exception e) {
Log.e("Error while handling activity stop.", e);
ApptentiveLog.e("Error while handling activity stop.", e);
}
}

Expand Down
Loading

0 comments on commit f3b0f5b

Please sign in to comment.