diff options
5 files changed, 42 insertions, 7 deletions
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 index 1136faf8..e16009ee 100644 --- 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 @@ -9,6 +9,7 @@ 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. @@ -25,7 +26,7 @@ public class ReadLogCatAsyncTask extends AsyncTask<Void, Void, String[]> { /** * The array adapter to publish the log messages to. */ - private final ArrayAdapter<String> arrayAdapter; + private final LogCatArrayAdapter arrayAdapter; /** * The command to execute logcat. */ @@ -39,7 +40,7 @@ public class ReadLogCatAsyncTask extends AsyncTask<Void, Void, String[]> { * Initializes the Task with the array adapter to publish the log messages to. * @param arrayAdapter the array adapter */ - public ReadLogCatAsyncTask(ArrayAdapter<String> arrayAdapter) { + public ReadLogCatAsyncTask(LogCatArrayAdapter arrayAdapter) { this.arrayAdapter = arrayAdapter; } @@ -52,15 +53,35 @@ public class ReadLogCatAsyncTask extends AsyncTask<Void, Void, String[]> { 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 { @@ -68,6 +89,12 @@ public class ReadLogCatAsyncTask extends AsyncTask<Void, Void, String[]> { } catch (IOException e) { } } + if (null != errorReader) { + try { + errorReader.close(); + } catch (IOException e) { + } + } } logCatOutput.trimToSize(); return logCatOutput.toArray(new String[0]); diff --git a/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/ui/LogCatOutputCopyOnClickListener.java b/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/ui/LogCatOutputCopyOnClickListener.java index 6568a2c5..1be04c9c 100644 --- a/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/ui/LogCatOutputCopyOnClickListener.java +++ b/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/ui/LogCatOutputCopyOnClickListener.java @@ -8,6 +8,7 @@ import android.widget.Toast; import java.util.ArrayList; +import de.thedevstack.android.logcat.Logging; import de.thedevstack.android.logcat.adapters.LogCatArrayAdapter; /** @@ -16,16 +17,19 @@ import de.thedevstack.android.logcat.adapters.LogCatArrayAdapter; public class LogCatOutputCopyOnClickListener implements View.OnClickListener { private final LogCatArrayAdapter logCatOutputAdapter; private final Context context; - private final int resIdForToast; + private final int resIdLogcatCopied; + private final int resIdLogcatNotCopied; - public LogCatOutputCopyOnClickListener(Context context, LogCatArrayAdapter logCatOutputAdapter, int resIdForToast) { + public LogCatOutputCopyOnClickListener(Context context, LogCatArrayAdapter logCatOutputAdapter, int resIdLogcatCopied, int resIdLogcatNotCopied) { this.logCatOutputAdapter = logCatOutputAdapter; this.context = context; - this.resIdForToast = resIdForToast; + this.resIdLogcatCopied = resIdLogcatCopied; + this.resIdLogcatNotCopied = resIdLogcatNotCopied; } @Override public void onClick(View v) { + Logging.d("copylogcat", "Start Copying log cat"); ArrayList<String> items = this.logCatOutputAdapter.getItems(); if (null != items && !items.isEmpty()) { StringBuilder sb = new StringBuilder(); @@ -36,7 +40,9 @@ public class LogCatOutputCopyOnClickListener implements View.OnClickListener { ClipboardManager clipboard = (ClipboardManager) this.context.getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("c+logcat", sb.toString()); clipboard.setPrimaryClip(clip); - Toast.makeText(this.context, this.context.getText(this.resIdForToast), Toast.LENGTH_LONG).show(); + Toast.makeText(this.context, this.context.getText(this.resIdLogcatCopied), Toast.LENGTH_LONG).show(); + } else { + Toast.makeText(this.context, this.context.getText(this.resIdLogcatNotCopied), Toast.LENGTH_LONG).show(); } } } diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/LogCatOutputActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/LogCatOutputActivity.java index 733da0cc..14872cb3 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/LogCatOutputActivity.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/LogCatOutputActivity.java @@ -24,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, R.string.cplus_copied_to_clipboard)); + copyButton.setOnClickListener(new LogCatOutputCopyOnClickListener(this, logCatOutputAdapter, R.string.cplus_copied_to_clipboard, R.string.cplus_not_copied_to_clipboard_empty)); } } diff --git a/src/main/res/values-de/strings.xml b/src/main/res/values-de/strings.xml index e6f6273e..617aedd3 100644 --- a/src/main/res/values-de/strings.xml +++ b/src/main/res/values-de/strings.xml @@ -510,4 +510,5 @@ <string name="pref_img_file_transfer">Ordnername, um eingehende Bilder zu speichern</string> <string name="pref_img_file_transfer_summary">Unterordner des globalen Bilderordners, um eingehende Bilder zu speichern.</string> <string name="pref_file_transfer_category">Dateiübertragung</string> + <string name="cplus_not_copied_to_clipboard_empty">Nichts zu kopieren.</string> </resources> diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index c8a50a25..c3444a82 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -543,4 +543,5 @@ <string name="pref_img_file_transfer">Folder to save incoming pictures</string> <string name="pref_img_file_transfer_summary">This is the subdirectory in the pictures directory for incoming files.</string> <string name="pref_file_transfer_category">File Transfer</string> + <string name="cplus_not_copied_to_clipboard_empty">Nothing to copy.</string> </resources> |