aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2019-07-07 21:21:12 +0200
committersteckbrief <steckbrief@chefmail.de>2019-07-07 21:21:12 +0200
commit08244e218a3cd08bb1abd1be31776510eee5da6a (patch)
treeb73568cc711268eeaa1b7485c63ec53a2efcbd02
parent77fb7577ee2a637abf6ff151f3b87a273aff7877 (diff)
implements FS#282: In-App Logcat View; introduces piratx application implementation to access the appcontext in a static way
-rw-r--r--build.gradle1
-rw-r--r--libs/thedevstacklogcat/.gitignore1
-rw-r--r--libs/thedevstacklogcat/build.gradle21
-rw-r--r--libs/thedevstacklogcat/src/androidTest/java/de/thedevstack/android/logcat/ApplicationTest.java13
-rw-r--r--libs/thedevstacklogcat/src/main/AndroidManifest.xml4
-rw-r--r--libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/Logging.java148
-rw-r--r--libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/adapters/LogCatArrayAdapter.java126
-rw-r--r--libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/tasks/ReadLogCatAsyncTask.java132
-rw-r--r--libs/thedevstacklogcat/src/main/res/values/strings.xml3
-rw-r--r--settings.gradle1
-rw-r--r--src/main/AndroidManifest.xml6
-rw-r--r--src/main/java/de/pixart/messenger/Config.java2
-rw-r--r--src/main/res/xml/preferences.xml3
-rw-r--r--src/piratx/java/de/thedevstack/piratx/PiratXApplication.java38
-rw-r--r--src/piratx/java/de/thedevstack/piratx/ui/listeners/LogCatOutputCopyOnClickListener.java41
-rw-r--r--src/piratx/java/de/thedevstack/piratx/ui/preferences/LogCatOutputActivity.java56
-rw-r--r--src/piratx/java/de/thedevstack/piratx/ui/preferences/LogInformationPreference.java29
-rw-r--r--src/piratx/java/de/thedevstack/piratx/utils/ClipboardUtil.java47
-rw-r--r--src/piratx/res/layout/activity_logcatoutput.xml19
-rw-r--r--src/piratx/res/layout/list_item_logcatoutput.xml7
-rw-r--r--src/piratx/res/values-de/strings.xml10
-rw-r--r--src/piratx/res/values/strings.xml10
22 files changed, 716 insertions, 2 deletions
diff --git a/build.gradle b/build.gradle
index e23dfc0ee..bbb57ba28 100644
--- a/build.gradle
+++ b/build.gradle
@@ -81,6 +81,7 @@ dependencies {
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
implementation 'com.google.guava:guava:27.1-android'
+ implementation project(':libs:thedevstacklogcat')
}
ext {
diff --git a/libs/thedevstacklogcat/.gitignore b/libs/thedevstacklogcat/.gitignore
new file mode 100644
index 000000000..796b96d1c
--- /dev/null
+++ b/libs/thedevstacklogcat/.gitignore
@@ -0,0 +1 @@
+/build
diff --git a/libs/thedevstacklogcat/build.gradle b/libs/thedevstacklogcat/build.gradle
new file mode 100644
index 000000000..e0c2fab53
--- /dev/null
+++ b/libs/thedevstacklogcat/build.gradle
@@ -0,0 +1,21 @@
+apply plugin: 'com.android.library'
+
+android {
+ compileSdkVersion 28
+
+ defaultConfig {
+ minSdkVersion 16
+ targetSdkVersion 28
+ versionCode 1
+ versionName "1.0"
+ }
+ buildTypes {
+ release {
+ minifyEnabled false
+ }
+ }
+}
+
+dependencies {
+ implementation 'com.android.support:appcompat-v7:28.0.0'
+}
diff --git a/libs/thedevstacklogcat/src/androidTest/java/de/thedevstack/android/logcat/ApplicationTest.java b/libs/thedevstacklogcat/src/androidTest/java/de/thedevstack/android/logcat/ApplicationTest.java
new file mode 100644
index 000000000..2e381ee7b
--- /dev/null
+++ b/libs/thedevstacklogcat/src/androidTest/java/de/thedevstack/android/logcat/ApplicationTest.java
@@ -0,0 +1,13 @@
+package de.thedevstack.android.logcat;
+
+import android.app.Application;
+import android.test.ApplicationTestCase;
+
+/**
+ * <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
+ */
+public class ApplicationTest extends ApplicationTestCase<Application> {
+ public ApplicationTest() {
+ super(Application.class);
+ }
+} \ No newline at end of file
diff --git a/libs/thedevstacklogcat/src/main/AndroidManifest.xml b/libs/thedevstacklogcat/src/main/AndroidManifest.xml
new file mode 100644
index 000000000..594487086
--- /dev/null
+++ b/libs/thedevstacklogcat/src/main/AndroidManifest.xml
@@ -0,0 +1,4 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="de.thedevstack.android.logcat">
+
+</manifest>
diff --git a/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/Logging.java b/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/Logging.java
new file mode 100644
index 000000000..6af7a70e7
--- /dev/null
+++ b/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/Logging.java
@@ -0,0 +1,148 @@
+package de.thedevstack.android.logcat;
+
+import android.util.Log;
+
+/**
+ * Utility class to prefix every log tag.
+ * This can be used for better filtering in the log cat output activity.
+ */
+public class Logging {
+ /**
+ * 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
+ * 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/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/adapters/LogCatArrayAdapter.java b/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/adapters/LogCatArrayAdapter.java
new file mode 100644
index 000000000..eb4efc983
--- /dev/null
+++ b/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/adapters/LogCatArrayAdapter.java
@@ -0,0 +1,126 @@
+package de.thedevstack.android.logcat.adapters;
+
+import android.content.Context;
+import android.widget.ArrayAdapter;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Created by tzur on 20.11.2015.
+ */
+public class LogCatArrayAdapter extends ArrayAdapter<String> {
+ private ArrayList<String> logcatItems = new ArrayList<>();
+
+ /**
+ * Constructor
+ *
+ * @param context The current context.
+ * @param resource The resource ID for a layout file containing a TextView to use when
+ */
+ public LogCatArrayAdapter(Context context, int resource) {
+ super(context, resource);
+ }
+
+ /**
+ * Constructor
+ *
+ * @param context The current context.
+ * @param resource The resource ID for a layout file containing a layout to use when
+ * instantiating views.
+ * @param textViewResourceId The id of the TextView within the layout resource to be populated
+ */
+ public LogCatArrayAdapter(Context context, int resource, int textViewResourceId) {
+ super(context, resource, textViewResourceId);
+ }
+
+ /**
+ * Constructor
+ *
+ * @param context The current context.
+ * @param resource The resource ID for a layout file containing a TextView to use when
+ * instantiating views.
+ * @param objects The objects to represent in the ListView.
+ */
+ public LogCatArrayAdapter(Context context, int resource, String[] objects) {
+ super(context, resource, objects);
+ }
+
+ /**
+ * Constructor
+ *
+ * @param context The current context.
+ * @param resource The resource ID for a layout file containing a layout to use when
+ * instantiating views.
+ * @param textViewResourceId The id of the TextView within the layout resource to be populated
+ * @param objects The objects to represent in the ListView.
+ */
+ public LogCatArrayAdapter(Context context, int resource, int textViewResourceId, String[] objects) {
+ super(context, resource, textViewResourceId, objects);
+ }
+
+ /**
+ * Constructor
+ *
+ * @param context The current context.
+ * @param resource The resource ID for a layout file containing a TextView to use when
+ * instantiating views.
+ * @param objects The objects to represent in the ListView.
+ */
+ public LogCatArrayAdapter(Context context, int resource, List<String> objects) {
+ super(context, resource, objects);
+ }
+
+ /**
+ * Constructor
+ *
+ * @param context The current context.
+ * @param resource The resource ID for a layout file containing a layout to use when
+ * instantiating views.
+ * @param textViewResourceId The id of the TextView within the layout resource to be populated
+ * @param objects The objects to represent in the ListView.
+ */
+ public LogCatArrayAdapter(Context context, int resource, int textViewResourceId, List<String> objects) {
+ super(context, resource, textViewResourceId, objects);
+ }
+
+ @Override
+ public void add(String object) {
+ super.add(object);
+ logcatItems.add(object);
+ }
+
+ @Override
+ public void addAll(Collection<? extends String> collection) {
+ super.addAll(collection);
+ logcatItems.addAll(collection);
+ }
+
+ @Override
+ public void addAll(String... items) {
+ super.addAll(items);
+ Collections.addAll(logcatItems, items);
+ }
+
+ @Override
+ public void clear() {
+ super.clear();
+ logcatItems.clear();
+ }
+
+ @Override
+ public void remove(String object) {
+ super.remove(object);
+ logcatItems.remove(object);
+ }
+
+ /**
+ * Returns an unmodifiable copy of the log cat entries.
+ * @return UnmodifiableList of logcat entries.
+ */
+ public List<String> getItems() {
+ return Collections.unmodifiableList(this.logcatItems);
+ }
+}
diff --git a/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/tasks/ReadLogCatAsyncTask.java b/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/tasks/ReadLogCatAsyncTask.java
new file mode 100644
index 000000000..e16009ee3
--- /dev/null
+++ b/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/tasks/ReadLogCatAsyncTask.java
@@ -0,0 +1,132 @@
+package de.thedevstack.android.logcat.tasks;
+
+import android.os.AsyncTask;
+import android.widget.ArrayAdapter;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+
+import de.thedevstack.android.logcat.Logging;
+import de.thedevstack.android.logcat.adapters.LogCatArrayAdapter;
+
+/**
+ * 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 LogCatArrayAdapter arrayAdapter;
+ /**
+ * The command to execute logcat.
+ */
+ private static final String[] LOG_CAT_CMD = { "logcat", "-d", "-v", "time"};
+ /**
+ * 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(LogCatArrayAdapter 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<>();
+ BufferedReader bufferedReader = null;
+ BufferedReader errorReader = null;
+ try {
+ Process process = Runtime.getRuntime().exec(ReadLogCatAsyncTask.LOG_CAT_CMD);
+ bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
+ errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
+ String line = "";
+ while ((line = bufferedReader.readLine()) != null) {
+ logCatOutput.add(line);
+ }
+
+ String errorLine = "";
+ StringBuilder sb = new StringBuilder();
+ while ((errorLine = errorReader.readLine()) != null) {
+ sb.append(errorLine);
+ sb.append('\n');
+ }
+ int exitValue = process.waitFor();
+
+ Logging.d("ReadLogCat", "Logcat command returned with exitValue '" + exitValue + "'.");
+
+ String errorMessage = sb.toString();
+ if (0 != exitValue && !errorMessage.isEmpty()) {
+ Logging.e("ReadLogCat", errorMessage);
+ logCatOutput.add(errorMessage);
+ }
+ } catch (IOException e) {
+ Logging.e("ReadLogCat", "error while retrieving information from logcat: " + e.getMessage(), e);
+ } catch (InterruptedException e) {
+ Logging.e("ReadLogCat", "error while retrieving information from logcat: " + e.getMessage(), e);
+ } finally {
+ if (null != bufferedReader) {
+ try {
+ bufferedReader.close();
+ } catch (IOException e) {
+ }
+ }
+ if (null != errorReader) {
+ try {
+ errorReader.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();
+ if (null != items && items.length > 0) {
+ for (String item : items) {
+ if (!filter(item)) {
+ this.arrayAdapter.add(item);
+ }
+ }
+ }
+ }
+
+ /**
+ * 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)) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
diff --git a/libs/thedevstacklogcat/src/main/res/values/strings.xml b/libs/thedevstacklogcat/src/main/res/values/strings.xml
new file mode 100644
index 000000000..45f5e7fd0
--- /dev/null
+++ b/libs/thedevstacklogcat/src/main/res/values/strings.xml
@@ -0,0 +1,3 @@
+<resources>
+ <string name="thedevstack_logcat_copy">Copy</string>
+</resources>
diff --git a/settings.gradle b/settings.gradle
index 13cce3507..8072becfa 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -1,4 +1,5 @@
include ':libs:android-transcoder'
include ':libs:xmpp-addr'
include ':libs:fullscreenvideoview'
+include ':libs:thedevstacklogcat'
rootProject.name = 'PiratX'
diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml
index 217f90d1e..fb75c6d69 100644
--- a/src/main/AndroidManifest.xml
+++ b/src/main/AndroidManifest.xml
@@ -48,7 +48,7 @@
android:required="false" />
<application
- android:name="android.support.multidex.MultiDexApplication"
+ android:name="de.thedevstack.piratx.PiratXApplication"
android:allowBackup="false"
android:appCategory="social"
android:icon="@drawable/ic_launcher"
@@ -315,6 +315,10 @@
<activity
android:name=".ui.ChannelDiscoveryActivity"
android:label="@string/discover_channels" />
+ <activity
+ android:name="de.thedevstack.piratx.ui.preferences.LogCatOutputActivity"
+ android:label="@string/piratx_title_activity_loginformation"
+ android:launchMode="singleTask" />
<service android:name=".services.ExportBackupService" />
<service android:name=".services.ImportBackupService" />
diff --git a/src/main/java/de/pixart/messenger/Config.java b/src/main/java/de/pixart/messenger/Config.java
index 7ead13955..0e2d2b4b5 100644
--- a/src/main/java/de/pixart/messenger/Config.java
+++ b/src/main/java/de/pixart/messenger/Config.java
@@ -40,7 +40,7 @@ public final class Config {
}
- public static final String LOGTAG = "Pix-Art_Messenger";
+ public static final String LOGTAG = "thedevstack.piratx";
public static final Jid BUG_REPORTS = Jid.of("piratx+bugs@conference.thedevstack.de");
diff --git a/src/main/res/xml/preferences.xml b/src/main/res/xml/preferences.xml
index d8dd6c89e..580889d8f 100644
--- a/src/main/res/xml/preferences.xml
+++ b/src/main/res/xml/preferences.xml
@@ -465,5 +465,8 @@
android:icon="?attr/ic_settings_about"
android:summary="@string/pref_about_conversations_summary"
android:title="@string/title_activity_about" />
+ <de.thedevstack.piratx.ui.preferences.LogInformationPreference
+ android:summary="@string/pref_show_logcat_summary"
+ android:title="@string/pref_show_logcat_title"/>
</PreferenceScreen>
diff --git a/src/piratx/java/de/thedevstack/piratx/PiratXApplication.java b/src/piratx/java/de/thedevstack/piratx/PiratXApplication.java
new file mode 100644
index 000000000..f4d008d52
--- /dev/null
+++ b/src/piratx/java/de/thedevstack/piratx/PiratXApplication.java
@@ -0,0 +1,38 @@
+package de.thedevstack.piratx;
+
+import android.content.Context;
+import android.support.multidex.MultiDexApplication;
+
+/**
+ *
+ */
+public class PiratXApplication extends MultiDexApplication {
+ /**
+ * Application instance for static access
+ */
+ private static PiratXApplication instance;
+
+ /**
+ * Initializes the application and saves its instance.
+ */
+ public void onCreate() {
+ super.onCreate();
+ PiratXApplication.instance = this;
+ }
+
+ /**
+ * Returns the instance of the application
+ * @return this application instance
+ */
+ public static PiratXApplication getInstance() {
+ return PiratXApplication.instance;
+ }
+
+ /**
+ * Returns the application's context.
+ * @return Context the application's context
+ */
+ public static Context getAppContext() {
+ return PiratXApplication.instance.getApplicationContext();
+ }
+}
diff --git a/src/piratx/java/de/thedevstack/piratx/ui/listeners/LogCatOutputCopyOnClickListener.java b/src/piratx/java/de/thedevstack/piratx/ui/listeners/LogCatOutputCopyOnClickListener.java
new file mode 100644
index 000000000..8699535ba
--- /dev/null
+++ b/src/piratx/java/de/thedevstack/piratx/ui/listeners/LogCatOutputCopyOnClickListener.java
@@ -0,0 +1,41 @@
+package de.thedevstack.piratx.ui.listeners;
+
+import android.view.View;
+
+import java.util.List;
+
+import de.thedevstack.android.logcat.Logging;
+import de.thedevstack.android.logcat.adapters.LogCatArrayAdapter;
+import de.thedevstack.piratx.utils.ClipboardUtil;
+
+/**
+ * OnClickListener to copy logcat entries from LogCatArrayAdapter to clipboard.
+ */
+public class LogCatOutputCopyOnClickListener implements View.OnClickListener {
+ private final LogCatArrayAdapter logCatOutputAdapter;
+
+ public LogCatOutputCopyOnClickListener(LogCatArrayAdapter logCatOutputAdapter) {
+ this.logCatOutputAdapter = logCatOutputAdapter;
+ }
+
+ /**
+ * Copies the entries of LogCatArrayAdapter separated by a new line to the clipboard.
+ *
+ * @param v The view that was clicked.
+ */
+ @Override
+ public void onClick(View v) {
+ Logging.d("copylogcat", "Start Copying log cat");
+ List<String> items = this.logCatOutputAdapter.getItems();
+ String textToCopy = null;
+ if (null != items && !items.isEmpty()) {
+ StringBuilder sb = new StringBuilder();
+ for (String item : items) {
+ sb.append(item);
+ sb.append("\n");
+ }
+ textToCopy = sb.toString();
+ }
+ ClipboardUtil.copyToClipboard("c+logcat", textToCopy);
+ }
+}
diff --git a/src/piratx/java/de/thedevstack/piratx/ui/preferences/LogCatOutputActivity.java b/src/piratx/java/de/thedevstack/piratx/ui/preferences/LogCatOutputActivity.java
new file mode 100644
index 000000000..13ff6a383
--- /dev/null
+++ b/src/piratx/java/de/thedevstack/piratx/ui/preferences/LogCatOutputActivity.java
@@ -0,0 +1,56 @@
+package de.thedevstack.piratx.ui.preferences;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.view.ContextMenu;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.Button;
+import android.widget.ListView;
+
+import de.pixart.messenger.R;
+import de.thedevstack.android.logcat.adapters.LogCatArrayAdapter;
+import de.thedevstack.android.logcat.tasks.ReadLogCatAsyncTask;
+import de.thedevstack.piratx.ui.listeners.LogCatOutputCopyOnClickListener;
+import de.thedevstack.piratx.utils.ClipboardUtil;
+
+/**
+ * Activity to display the logcat output.
+ */
+public class LogCatOutputActivity extends Activity {
+ /**
+ * List adapter containing the logcat entries.
+ */
+ private LogCatArrayAdapter logCatArrayAdapter;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_logcatoutput);
+ ListView lv = findViewById(R.id.actLogInfoOutput);
+ this.logCatArrayAdapter = new LogCatArrayAdapter(this, R.layout.list_item_logcatoutput);
+ lv.setAdapter(this.logCatArrayAdapter);
+ new ReadLogCatAsyncTask(this.logCatArrayAdapter).execute();
+ Button copyButton = findViewById(R.id.actLogOutputCopyButton);
+ copyButton.setOnClickListener(new LogCatOutputCopyOnClickListener(this.logCatArrayAdapter));
+ registerForContextMenu(lv);
+ }
+
+ @Override
+ public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
+ super.onCreateContextMenu(menu, v, menuInfo);
+ menu.add(0, 123456789, 0, R.string.piratx_copy_item);
+ }
+
+ @Override
+ public boolean onContextItemSelected(MenuItem item) {
+ if (123456789 == item.getItemId()) {
+ AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
+ String itemText = this.logCatArrayAdapter.getItems().get(info.position);
+ ClipboardUtil.copyToClipboard(itemText);
+ return true;
+ }
+ return super.onContextItemSelected(item);
+ }
+}
diff --git a/src/piratx/java/de/thedevstack/piratx/ui/preferences/LogInformationPreference.java b/src/piratx/java/de/thedevstack/piratx/ui/preferences/LogInformationPreference.java
new file mode 100644
index 000000000..6b381d9c2
--- /dev/null
+++ b/src/piratx/java/de/thedevstack/piratx/ui/preferences/LogInformationPreference.java
@@ -0,0 +1,29 @@
+package de.thedevstack.piratx.ui.preferences;
+
+import android.content.Context;
+import android.content.Intent;
+import android.preference.Preference;
+import android.util.AttributeSet;
+
+/**
+ *
+ */
+public class LogInformationPreference extends Preference {
+ public LogInformationPreference(final Context context, final AttributeSet attrs, final int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ public LogInformationPreference(final Context context, final AttributeSet attrs) {
+ super(context, attrs);
+ }
+ public LogInformationPreference(Context context) {
+ super(context);
+ }
+
+ @Override
+ protected void onClick() {
+ super.onClick();
+ final Intent intent = new Intent(getContext(), LogCatOutputActivity.class);
+ getContext().startActivity(intent);
+ }
+}
diff --git a/src/piratx/java/de/thedevstack/piratx/utils/ClipboardUtil.java b/src/piratx/java/de/thedevstack/piratx/utils/ClipboardUtil.java
new file mode 100644
index 000000000..623eeb5ba
--- /dev/null
+++ b/src/piratx/java/de/thedevstack/piratx/utils/ClipboardUtil.java
@@ -0,0 +1,47 @@
+package de.thedevstack.piratx.utils;
+
+import android.content.ClipData;
+import android.content.ClipboardManager;
+import android.content.Context;
+import android.widget.Toast;
+
+import de.pixart.messenger.R;
+import de.thedevstack.piratx.PiratXApplication;
+
+/**
+ * Util class to work with the Clipboard.
+ */
+public final class ClipboardUtil {
+ private static final String CLIPBOARD_LABEL = "piratx+clipboard";
+
+ /**
+ * Copies a text to the clipboard.
+ * @param clipboardLabel the label to show to a user to allow identifying the text in clipboard.
+ * @param text the text to copy
+ */
+ public static void copyToClipboard(String clipboardLabel, String text) {
+ Context context = PiratXApplication.getAppContext();
+ if (null != text && !text.isEmpty()) {
+ String label = (null == clipboardLabel) ? CLIPBOARD_LABEL : clipboardLabel;
+ ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
+ ClipData clip = ClipData.newPlainText(label, text);
+ clipboard.setPrimaryClip(clip);
+ Toast.makeText(context, R.string.piratx_copied_to_clipboard, Toast.LENGTH_LONG).show();
+ } else {
+ Toast.makeText(context, R.string.piratx_not_copied_to_clipboard_empty, Toast.LENGTH_LONG).show();
+ }
+
+ }
+
+ /**
+ * Copies a text to the clipboard.
+ * @param text the text to copy
+ */
+ public static void copyToClipboard(String text) {
+ copyToClipboard(CLIPBOARD_LABEL, text);
+ }
+
+ private ClipboardUtil() {
+ // helper class - avoid instantiation
+ }
+}
diff --git a/src/piratx/res/layout/activity_logcatoutput.xml b/src/piratx/res/layout/activity_logcatoutput.xml
new file mode 100644
index 000000000..76c9227e4
--- /dev/null
+++ b/src/piratx/res/layout/activity_logcatoutput.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical" android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <Button
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/piratx_copy_to_clipboard"
+ android:id="@+id/actLogOutputCopyButton" />
+
+ <ListView
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:id="@+id/actLogInfoOutput"
+ android:scrollbars="vertical"
+ android:textSize="12sp"
+ android:textIsSelectable="true"/>
+</LinearLayout> \ No newline at end of file
diff --git a/src/piratx/res/layout/list_item_logcatoutput.xml b/src/piratx/res/layout/list_item_logcatoutput.xml
new file mode 100644
index 000000000..9a31be177
--- /dev/null
+++ b/src/piratx/res/layout/list_item_logcatoutput.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:id="@+id/listItemLogcatoutputText"
+ android:scrollbars="vertical"
+ android:textSize="12sp"/> \ No newline at end of file
diff --git a/src/piratx/res/values-de/strings.xml b/src/piratx/res/values-de/strings.xml
new file mode 100644
index 000000000..54ae0d063
--- /dev/null
+++ b/src/piratx/res/values-de/strings.xml
@@ -0,0 +1,10 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<resources>
+ <string name="pref_show_logcat_title">Zeige logcat-Ausgabe</string>
+ <string name="pref_show_logcat_summary">Zeigt die Ausgabe von logcat an. Hilfreich für die Fehlersuche.</string>
+ <string name="piratx_title_activity_loginformation">Logausgaben</string>
+ <string name="piratx_copy_item">Zeile kopieren</string>
+ <string name="piratx_copy_to_clipboard">Kopieren</string>
+ <string name="piratx_copied_to_clipboard">In Zwischenablage kopiert</string>
+ <string name="piratx_not_copied_to_clipboard_empty">Nichts zu kopieren.</string>
+</resources>
diff --git a/src/piratx/res/values/strings.xml b/src/piratx/res/values/strings.xml
new file mode 100644
index 000000000..1eb5a0ac5
--- /dev/null
+++ b/src/piratx/res/values/strings.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="pref_show_logcat_title">Show logcat output</string>
+ <string name="pref_show_logcat_summary">Shows the output of logcat. This is useful for debugging.</string>
+ <string name="piratx_title_activity_loginformation">Log information</string>
+ <string name="piratx_copy_item">Copy item</string>
+ <string name="piratx_copy_to_clipboard">Copy to clipboard</string>
+ <string name="piratx_copied_to_clipboard">Copied to clipboard</string>
+ <string name="piratx_not_copied_to_clipboard_empty">Nothing to copy.</string>
+</resources>