diff options
author | steckbrief <steckbrief@chefmail.de> | 2015-12-10 20:37:34 +0100 |
---|---|---|
committer | steckbrief <steckbrief@chefmail.de> | 2015-12-10 20:37:34 +0100 |
commit | 3b1723dcf19dc6e3390df63a71df903d9cb7dd94 (patch) | |
tree | a912db2e2204645fc3138cce62bb75a8d1a9b7d3 /src/main/java/de | |
parent | aa6a2e1c182858e7bcc077f5220546e08df12ec1 (diff) | |
parent | a7454223008c78dcf5e0ff727bca64241f99daa1 (diff) |
Merge remote-tracking branch 'remotes/origin/trz/rename' into trz/rebase
Diffstat (limited to '')
10 files changed, 87 insertions, 23 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/Logging.java b/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/Logging.java index 40ec66a0..6af7a70e 100644 --- a/src/main/java/de/thedevstack/conversationsplus/utils/Logging.java +++ b/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/Logging.java @@ -1,12 +1,36 @@ -package de.thedevstack.conversationsplus.utils; +package de.thedevstack.android.logcat; import android.util.Log; /** - * Created by tzur on 20.11.2015. + * Utility class to prefix every log tag. + * This can be used for better filtering in the log cat output activity. */ public class Logging { - protected static final String LOG_TAG_PREFIX = "thedevstack."; + /** + * The prefix for every log tag. + */ + protected static String LOG_TAG_PREFIX = "thedevstack."; + + /** + * Changes the default log tag prefix. + * The default value is <code>thedevstack.</code> + * @param logTagPrefix the new log tag prefix to use + */ + public static void initLogTagPrefix(String logTagPrefix) { + if (null != logTagPrefix) { + LOG_TAG_PREFIX = logTagPrefix; + } + } + + /** + * Returns the current log tag prefix. + * @return value of Logging.LOG_TAG_PREFIX + */ + public static String getLogTagPrefix() { + return LOG_TAG_PREFIX; + } + /** * Send a {@link Log#VERBOSE} log message. * @param tag Used to identify the source of a log message. It usually identifies diff --git a/src/main/java/de/thedevstack/android/logcat/adapters/LogCatArrayAdapter.java b/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/adapters/LogCatArrayAdapter.java index c8a96ea3..c8a96ea3 100644 --- a/src/main/java/de/thedevstack/android/logcat/adapters/LogCatArrayAdapter.java +++ b/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/adapters/LogCatArrayAdapter.java diff --git a/src/main/java/de/thedevstack/android/logcat/tasks/ReadLogCatAsyncTask.java b/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/tasks/ReadLogCatAsyncTask.java index b9fa450b..1136faf8 100644 --- a/src/main/java/de/thedevstack/android/logcat/tasks/ReadLogCatAsyncTask.java +++ b/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/tasks/ReadLogCatAsyncTask.java @@ -1,7 +1,6 @@ package de.thedevstack.android.logcat.tasks; import android.os.AsyncTask; -import de.thedevstack.conversationsplus.utils.Logging; import android.widget.ArrayAdapter; import java.io.BufferedReader; @@ -9,20 +8,46 @@ import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; -import de.thedevstack.conversationsplus.utils.StreamUtil; +import de.thedevstack.android.logcat.Logging; /** - * Created by tzur on 20.11.2015. + * Task to read the logcat of the App. + * The command <code>logcat -d -v time</code> is used to load the logs. + * This reader uses a white list to restrict the messages to display, otherwise it might be flooded with useless log messages. + * The white list checks if a log messages contains one of the following strings: + * <ul> + * <li>{@value Logging#LOG_TAG_PREFIX}</li> + * <li><code>E/</code> - for every error message</li> + * <li><code>W/</code> - for every warning message</li> + * </ul> */ public class ReadLogCatAsyncTask extends AsyncTask<Void, Void, String[]> { + /** + * The array adapter to publish the log messages to. + */ private final ArrayAdapter<String> arrayAdapter; + /** + * The command to execute logcat. + */ private static final String[] LOG_CAT_CMD = { "logcat", "-d", "-v", "time"}; - private static final String[] WHITE_LIST = { "thedevstack.", "E/", "W/" }; - private static final String[] BLACK_LIST = { "D/TextLayoutCache" }; + /** + * The white list to filter log messages. + */ + private static final String[] WHITE_LIST = { Logging.getLogTagPrefix(), "E/", "W/" }; + /** + * Initializes the Task with the array adapter to publish the log messages to. + * @param arrayAdapter the array adapter + */ public ReadLogCatAsyncTask(ArrayAdapter<String> arrayAdapter) { this.arrayAdapter = arrayAdapter; } + + /** + * Executes the logcat command, reads the output of the command and returns all log messages. + * @param params no params will be passed. (interface compliance) + * @return the array of log messages + */ @Override protected String[] doInBackground(Void... params) { ArrayList<String> logCatOutput = new ArrayList<>(); @@ -34,16 +59,24 @@ public class ReadLogCatAsyncTask extends AsyncTask<Void, Void, String[]> { while ((line = bufferedReader.readLine()) != null) { logCatOutput.add(line); } - bufferedReader.close(); } catch (IOException e) { Logging.e("ReadLogCat", "error while retrieving information from logcat: " + e.getMessage(), e); } finally { - StreamUtil.close(bufferedReader); + if (null != bufferedReader) { + try { + bufferedReader.close(); + } catch (IOException e) { + } + } } logCatOutput.trimToSize(); return logCatOutput.toArray(new String[0]); } + /** + * Clears the array adapter and adds the filtered log messages. + * @param items all log messages + */ @Override protected void onPostExecute(String[] items) { this.arrayAdapter.clear(); @@ -56,6 +89,11 @@ public class ReadLogCatAsyncTask extends AsyncTask<Void, Void, String[]> { } } + /** + * Checks whether a log message contains a white listed string or not. + * @param item the item to filter + * @return <code>true</code> if the string should be filtered (removed from the list) <code>false</code> otherwise. + */ protected boolean filter(String item) { for (String whiteListed : ReadLogCatAsyncTask.WHITE_LIST) { if (item.contains(whiteListed)) { diff --git a/src/main/java/de/thedevstack/android/logcat/ui/LogCatOutputCopyOnClickListener.java b/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/ui/LogCatOutputCopyOnClickListener.java index 1a37555a..6568a2c5 100644 --- a/src/main/java/de/thedevstack/android/logcat/ui/LogCatOutputCopyOnClickListener.java +++ b/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/ui/LogCatOutputCopyOnClickListener.java @@ -9,9 +9,6 @@ import android.widget.Toast; import java.util.ArrayList; import de.thedevstack.android.logcat.adapters.LogCatArrayAdapter; -import de.thedevstack.conversationsplus.ConversationsPlusApplication; - -import eu.siacs.conversations.R; /** * Created by tzur on 20.11.2015. @@ -19,10 +16,12 @@ import eu.siacs.conversations.R; public class LogCatOutputCopyOnClickListener implements View.OnClickListener { private final LogCatArrayAdapter logCatOutputAdapter; private final Context context; + private final int resIdForToast; - public LogCatOutputCopyOnClickListener(Context context, LogCatArrayAdapter logCatOutputAdapter) { + public LogCatOutputCopyOnClickListener(Context context, LogCatArrayAdapter logCatOutputAdapter, int resIdForToast) { this.logCatOutputAdapter = logCatOutputAdapter; this.context = context; + this.resIdForToast = resIdForToast; } @Override @@ -34,10 +33,10 @@ public class LogCatOutputCopyOnClickListener implements View.OnClickListener { sb.append(item); sb.append("\n"); } - ClipboardManager clipboard = (ClipboardManager) ConversationsPlusApplication.getInstance().getSystemService(Context.CLIPBOARD_SERVICE); + ClipboardManager clipboard = (ClipboardManager) this.context.getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("c+logcat", sb.toString()); clipboard.setPrimaryClip(clip); - Toast.makeText(this.context, R.string.cplus_copied_to_clipboard, Toast.LENGTH_LONG).show(); + Toast.makeText(this.context, this.context.getText(this.resIdForToast), Toast.LENGTH_LONG).show(); } } } diff --git a/src/main/java/de/thedevstack/android/logcat/ui/LogCatOutputActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/LogCatOutputActivity.java index 477cfc48..733da0cc 100644 --- a/src/main/java/de/thedevstack/android/logcat/ui/LogCatOutputActivity.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/LogCatOutputActivity.java @@ -1,4 +1,4 @@ -package de.thedevstack.android.logcat.ui; +package de.thedevstack.conversationsplus.ui; import android.app.Activity; import android.os.Bundle; @@ -7,6 +7,7 @@ import android.widget.ListView; import de.thedevstack.android.logcat.adapters.LogCatArrayAdapter; import de.thedevstack.android.logcat.tasks.ReadLogCatAsyncTask; +import de.thedevstack.android.logcat.ui.LogCatOutputCopyOnClickListener; import eu.siacs.conversations.R; @@ -23,6 +24,6 @@ public class LogCatOutputActivity extends Activity { lv.setAdapter(logCatOutputAdapter); new ReadLogCatAsyncTask(logCatOutputAdapter).execute(); Button copyButton = (Button) findViewById(R.id.actLogOutputCopyButton); - copyButton.setOnClickListener(new LogCatOutputCopyOnClickListener(this, logCatOutputAdapter)); + copyButton.setOnClickListener(new LogCatOutputCopyOnClickListener(this, logCatOutputAdapter, R.string.cplus_copied_to_clipboard)); } } diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/MessageDetailsDialog.java b/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/MessageDetailsDialog.java index 7d82223c..b1b2298b 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/MessageDetailsDialog.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/MessageDetailsDialog.java @@ -2,12 +2,13 @@ package de.thedevstack.conversationsplus.ui.dialogs; import android.app.Activity; import android.text.format.DateFormat; -import de.thedevstack.conversationsplus.utils.Logging; import android.view.View; import android.widget.TextView; import java.util.Date; +import de.thedevstack.android.logcat.Logging; + import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Message; diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/preferences/LogInformationPreference.java b/src/main/java/de/thedevstack/conversationsplus/ui/preferences/LogInformationPreference.java index 65b3b1b3..5dcfc607 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/preferences/LogInformationPreference.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/preferences/LogInformationPreference.java @@ -5,7 +5,7 @@ import android.content.Intent; import android.preference.Preference; import android.util.AttributeSet; -import de.thedevstack.android.logcat.ui.LogCatOutputActivity; +import de.thedevstack.conversationsplus.ui.LogCatOutputActivity; /** * Created by tzur on 07.10.2015. diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/AvatarUtil.java b/src/main/java/de/thedevstack/conversationsplus/utils/AvatarUtil.java index 6b080202..401c77fc 100644 --- a/src/main/java/de/thedevstack/conversationsplus/utils/AvatarUtil.java +++ b/src/main/java/de/thedevstack/conversationsplus/utils/AvatarUtil.java @@ -4,7 +4,6 @@ import android.graphics.Bitmap; import android.net.Uri; import android.util.Base64; import android.util.Base64OutputStream; -import de.thedevstack.conversationsplus.utils.Logging; import java.io.ByteArrayOutputStream; import java.io.File; @@ -16,6 +15,7 @@ import java.security.DigestOutputStream; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.ConversationsPlusApplication; import eu.siacs.conversations.Config; diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/ImageUtil.java b/src/main/java/de/thedevstack/conversationsplus/utils/ImageUtil.java index 802c7ffb..204f56c4 100644 --- a/src/main/java/de/thedevstack/conversationsplus/utils/ImageUtil.java +++ b/src/main/java/de/thedevstack/conversationsplus/utils/ImageUtil.java @@ -7,7 +7,6 @@ import android.graphics.Matrix; import android.graphics.RectF; import android.media.ExifInterface; import android.net.Uri; -import de.thedevstack.conversationsplus.utils.Logging; import android.util.LruCache; import java.io.File; @@ -15,6 +14,8 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import de.thedevstack.android.logcat.Logging; + import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.persistance.FileBackend; import eu.siacs.conversations.utils.ExifHelper; diff --git a/src/main/java/de/tzur/conversations/Settings.java b/src/main/java/de/tzur/conversations/Settings.java index b8922f0a..2484a88f 100644 --- a/src/main/java/de/tzur/conversations/Settings.java +++ b/src/main/java/de/tzur/conversations/Settings.java @@ -1,8 +1,8 @@ package de.tzur.conversations; import android.content.SharedPreferences; -import de.thedevstack.conversationsplus.utils.Logging; +import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.ConversationsPlusApplication; /** |