aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/utils')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/utils/AvatarUtil.java4
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/utils/DNSHelper.java4
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/utils/ExceptionHelper.java4
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/utils/ExifHelper.java12
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/utils/ImageUtil.java6
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/utils/Logging.java124
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/utils/PRNGFixes.java4
7 files changed, 141 insertions, 17 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/AvatarUtil.java b/src/main/java/de/thedevstack/conversationsplus/utils/AvatarUtil.java
index 287f4b50..87b9eb32 100644
--- a/src/main/java/de/thedevstack/conversationsplus/utils/AvatarUtil.java
+++ b/src/main/java/de/thedevstack/conversationsplus/utils/AvatarUtil.java
@@ -4,7 +4,7 @@ import android.graphics.Bitmap;
import android.net.Uri;
import android.util.Base64;
import android.util.Base64OutputStream;
-import android.util.Log;
+import de.thedevstack.conversationsplus.utils.Logging;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -100,7 +100,7 @@ public final class AvatarUtil {
if (sha1sum.equals(avatar.sha1sum)) {
file.renameTo(new File(filename));
} else {
- Log.d(Config.LOGTAG, "sha1sum mismatch for " + avatar.owner);
+ Logging.d(Config.LOGTAG, "sha1sum mismatch for " + avatar.owner);
file.delete();
return false;
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/DNSHelper.java b/src/main/java/de/thedevstack/conversationsplus/utils/DNSHelper.java
index 8951426f..bd7a6623 100644
--- a/src/main/java/de/thedevstack/conversationsplus/utils/DNSHelper.java
+++ b/src/main/java/de/thedevstack/conversationsplus/utils/DNSHelper.java
@@ -23,7 +23,7 @@ import java.util.TreeMap;
import java.util.regex.Pattern;
import android.os.Bundle;
-import android.util.Log;
+import de.thedevstack.conversationsplus.utils.Logging;
public class DNSHelper {
@@ -55,7 +55,7 @@ public class DNSHelper {
Bundle bundle = new Bundle();
try {
String qname = "_xmpp-client._tcp." + host;
- Log.d(Config.LOGTAG, "using dns server: " + dnsServer.getHostAddress() + " to look up " + host);
+ Logging.d(Config.LOGTAG, "using dns server: " + dnsServer.getHostAddress() + " to look up " + host);
DNSMessage message = client.query(qname, TYPE.SRV, CLASS.IN, dnsServer.getHostAddress());
TreeMap<Integer, ArrayList<SRV>> priorities = new TreeMap<>();
diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/ExceptionHelper.java b/src/main/java/de/thedevstack/conversationsplus/utils/ExceptionHelper.java
index d25e6d35..999d1027 100644
--- a/src/main/java/de/thedevstack/conversationsplus/utils/ExceptionHelper.java
+++ b/src/main/java/de/thedevstack/conversationsplus/utils/ExceptionHelper.java
@@ -26,7 +26,7 @@ import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.preference.PreferenceManager;
import android.text.format.DateUtils;
-import android.util.Log;
+import de.thedevstack.conversationsplus.utils.Logging;
public class ExceptionHelper {
public static void init(Context context) {
@@ -87,7 +87,7 @@ public class ExceptionHelper {
@Override
public void onClick(DialogInterface dialog, int which) {
- Log.d(Config.LOGTAG, "using account="
+ Logging.d(Config.LOGTAG, "using account="
+ finalAccount.getJid().toBareJid()
+ " to send in stack trace");
Conversation conversation = null;
diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/ExifHelper.java b/src/main/java/de/thedevstack/conversationsplus/utils/ExifHelper.java
index 13aff60d..7aaf8b0b 100644
--- a/src/main/java/de/thedevstack/conversationsplus/utils/ExifHelper.java
+++ b/src/main/java/de/thedevstack/conversationsplus/utils/ExifHelper.java
@@ -16,7 +16,7 @@
package de.thedevstack.conversationsplus.utils;
-import android.util.Log;
+import de.thedevstack.conversationsplus.utils.Logging;
import java.io.IOException;
import java.io.InputStream;
@@ -56,7 +56,7 @@ public class ExifHelper {
}
length = pack(buf, 0, 2, false);
if (length < 2) {
- Log.e(TAG, "Invalid length");
+ Logging.e(TAG, "Invalid length");
return 0;
}
length -= 2;
@@ -91,7 +91,7 @@ public class ExifHelper {
// Identify the byte order.
int tag = pack(jpeg, offset, 4, false);
if (tag != 0x49492A00 && tag != 0x4D4D002A) {
- Log.e(TAG, "Invalid byte order");
+ Logging.e(TAG, "Invalid byte order");
return 0;
}
boolean littleEndian = (tag == 0x49492A00);
@@ -99,7 +99,7 @@ public class ExifHelper {
// Get the offset and check if it is reasonable.
int count = pack(jpeg, offset + 4, 4, littleEndian) + 2;
if (count < 10 || count > length) {
- Log.e(TAG, "Invalid offset");
+ Logging.e(TAG, "Invalid offset");
return 0;
}
offset += count;
@@ -123,7 +123,7 @@ public class ExifHelper {
case 8:
return 270;
}
- Log.i(TAG, "Unsupported orientation");
+ Logging.i(TAG, "Unsupported orientation");
return 0;
}
offset += 12;
@@ -131,7 +131,7 @@ public class ExifHelper {
}
}
- Log.i(TAG, "Orientation not found");
+ Logging.i(TAG, "Orientation not found");
return 0;
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/ImageUtil.java b/src/main/java/de/thedevstack/conversationsplus/utils/ImageUtil.java
index 3c3e1c99..1d126db5 100644
--- a/src/main/java/de/thedevstack/conversationsplus/utils/ImageUtil.java
+++ b/src/main/java/de/thedevstack/conversationsplus/utils/ImageUtil.java
@@ -7,7 +7,7 @@ import android.graphics.Matrix;
import android.graphics.RectF;
import android.media.ExifInterface;
import android.net.Uri;
-import android.util.Log;
+import de.thedevstack.conversationsplus.utils.Logging;
import android.util.LruCache;
import java.io.File;
@@ -66,7 +66,7 @@ public final class ImageUtil {
* @see LruCache#LruCache(int) for details
*/
public static void initBitmapCache() {
- Log.i("Conversations+ImageUtil", "Initializing BitmapCache");
+ Logging.i("Conversations+ImageUtil", "Initializing BitmapCache");
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
final int cacheSize = maxMemory / 8;
BITMAP_CACHE = new LruCache<String, Bitmap>(cacheSize) {
@@ -177,7 +177,7 @@ public final class ImageUtil {
return rotate(original, rotation);
}
} catch (IOException e) {
- Log.w("filebackend", "Error while rotating image, returning original (" + e.getMessage() + ")");
+ Logging.w("filebackend", "Error while rotating image, returning original (" + e.getMessage() + ")");
}
return original;
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/Logging.java b/src/main/java/de/thedevstack/conversationsplus/utils/Logging.java
new file mode 100644
index 00000000..40ec66a0
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/utils/Logging.java
@@ -0,0 +1,124 @@
+package de.thedevstack.conversationsplus.utils;
+
+import android.util.Log;
+
+/**
+ * Created by tzur on 20.11.2015.
+ */
+public class Logging {
+ protected static final String LOG_TAG_PREFIX = "thedevstack.";
+ /**
+ * Send a {@link Log#VERBOSE} log message.
+ * @param tag Used to identify the source of a log message. It usually identifies
+ * the class or activity where the log call occurs.
+ * @param msg The message you would like logged.
+ */
+ public static int v(String tag, String msg) {
+ return Log.v(Logging.LOG_TAG_PREFIX + tag, msg);
+ }
+
+ /**
+ * Send a {@link Log#VERBOSE} log message and log the exception.
+ * @param tag Used to identify the source of a log message. It usually identifies
+ * the class or activity where the log call occurs.
+ * @param msg The message you would like logged.
+ * @param tr An exception to log
+ */
+ public static int v(String tag, String msg, Throwable tr) {
+ return Log.v(Logging.LOG_TAG_PREFIX + tag, msg + '\n' + Log.getStackTraceString(tr));
+ }
+
+ /**
+ * Send a {@link Log#DEBUG} log message.
+ * @param tag Used to identify the source of a log message. It usually identifies
+ * the class or activity where the log call occurs.
+ * @param msg The message you would like logged.
+ */
+ public static int d(String tag, String msg) {
+ return Log.d(Logging.LOG_TAG_PREFIX + tag, msg);
+ }
+
+ /**
+ * Send a {@link Log#DEBUG} log message and log the exception.
+ * @param tag Used to identify the source of a log message. It usually identifies
+ * the class or activity where the log call occurs.
+ * @param msg The message you would like logged.
+ * @param tr An exception to log
+ */
+ public static int d(String tag, String msg, Throwable tr) {
+ return Log.d(Logging.LOG_TAG_PREFIX + tag, msg + '\n' + Log.getStackTraceString(tr));
+ }
+
+ /**
+ * Send an {@link Log#INFO} log message.
+ * @param tag Used to identify the source of a log message. It usually identifies
+ * the class or activity where the log call occurs.
+ * @param msg The message you would like logged.
+ */
+ public static int i(String tag, String msg) {
+ return Log.i(Logging.LOG_TAG_PREFIX + tag, msg);
+ }
+
+ /**
+ * Send a {@link Log#INFO} log message and log the exception.
+ * @param tag Used to identify the source of a log message. It usually identifies
+ * the class or activity where the log call occurs.
+ * @param msg The message you would like logged.
+ * @param tr An exception to log
+ */
+ public static int i(String tag, String msg, Throwable tr) {
+ return Log.i(Logging.LOG_TAG_PREFIX + tag, msg + '\n' + Log.getStackTraceString(tr));
+ }
+
+ /**
+ * Send a {@link Log#WARN} log message.
+ * @param tag Used to identify the source of a log message. It usually identifies
+ * the class or activity where the log call occurs.
+ * @param msg The message you would like logged.
+ */
+ public static int w(String tag, String msg) {
+ return Log.w(Logging.LOG_TAG_PREFIX + tag, msg);
+ }
+
+ /**
+ * Send a {@link Log#WARN} log message and log the exception.
+ * @param tag Used to identify the source of a log message. It usually identifies
+ * the class or activity where the log call occurs.
+ * @param msg The message you would like logged.
+ * @param tr An exception to log
+ */
+ public static int w(String tag, String msg, Throwable tr) {
+ return Log.w(Logging.LOG_TAG_PREFIX + tag, msg + '\n' + Log.getStackTraceString(tr));
+ }
+
+ /*
+ * Send a {@link #WARN} log message and log the exception.
+ * @param tag Used to identify the source of a log message. It usually identifies
+ * the class or activity where the log call occurs.
+ * @param tr An exception to log
+ */
+ public static int w(String tag, Throwable tr) {
+ return Log.w(Logging.LOG_TAG_PREFIX + tag, Log.getStackTraceString(tr));
+ }
+
+ /**
+ * Send an {@link Log#ERROR} log message.
+ * @param tag Used to identify the source of a log message. It usually identifies
+ * the class or activity where the log call occurs.
+ * @param msg The message you would like logged.
+ */
+ public static int e(String tag, String msg) {
+ return Log.e(Logging.LOG_TAG_PREFIX + tag, msg);
+ }
+
+ /**
+ * Send a {@link Log#ERROR} log message and log the exception.
+ * @param tag Used to identify the source of a log message. It usually identifies
+ * the class or activity where the log call occurs.
+ * @param msg The message you would like logged.
+ * @param tr An exception to log
+ */
+ public static int e(String tag, String msg, Throwable tr) {
+ return Log.e(Logging.LOG_TAG_PREFIX + tag, msg + '\n' + Log.getStackTraceString(tr));
+ }
+}
diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/PRNGFixes.java b/src/main/java/de/thedevstack/conversationsplus/utils/PRNGFixes.java
index 78776aeb..ca4d65ff 100644
--- a/src/main/java/de/thedevstack/conversationsplus/utils/PRNGFixes.java
+++ b/src/main/java/de/thedevstack/conversationsplus/utils/PRNGFixes.java
@@ -2,7 +2,7 @@ package de.thedevstack.conversationsplus.utils;
import android.os.Build;
import android.os.Process;
-import android.util.Log;
+import de.thedevstack.conversationsplus.utils.Logging;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
@@ -209,7 +209,7 @@ public final class PRNGFixes {
} catch (IOException e) {
// On a small fraction of devices /dev/urandom is not writable.
// Log and ignore.
- Log.w(PRNGFixes.class.getSimpleName(),
+ Logging.w(PRNGFixes.class.getSimpleName(),
"Failed to mix seed into " + URANDOM_FILE);
} finally {
mSeeded = true;