diff options
author | Tobias Brunner <tobias@strongswan.org> | 2017-04-21 14:30:16 +0200 |
---|---|---|
committer | Tobias Brunner <tobias@strongswan.org> | 2017-07-03 10:27:45 +0200 |
commit | 74d44e15dcff4bc55627ab08b9ab230c6e3f290d (patch) | |
tree | 23384423fa3834b68e3fd17e42e978a42570d312 | |
parent | 9c4607b4540729ad94973b92a472466c07053f51 (diff) | |
download | strongswan-74d44e15dcff4bc55627ab08b9ab230c6e3f290d.tar.bz2 strongswan-74d44e15dcff4bc55627ab08b9ab230c6e3f290d.tar.xz |
android: Make log view more efficient
This bunches several log messages together before posting Runnables.
Fixes #2148.
-rw-r--r-- | src/frontends/android/app/src/main/java/org/strongswan/android/ui/LogFragment.java | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/src/frontends/android/app/src/main/java/org/strongswan/android/ui/LogFragment.java b/src/frontends/android/app/src/main/java/org/strongswan/android/ui/LogFragment.java index 2f6240726..f68d0c617 100644 --- a/src/frontends/android/app/src/main/java/org/strongswan/android/ui/LogFragment.java +++ b/src/frontends/android/app/src/main/java/org/strongswan/android/ui/LogFragment.java @@ -1,6 +1,6 @@ /* - * Copyright (C) 2012 Tobias Brunner - * Hochschule fuer Technik Rapperswil + * Copyright (C) 2012-2017 Tobias Brunner + * HSR Hochschule fuer Technik Rapperswil * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -32,6 +32,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.StringReader; +import java.util.ArrayList; public class LogFragment extends Fragment implements Runnable { @@ -121,16 +122,20 @@ public class LogFragment extends Fragment implements Runnable * Write the given log line to the TextView. We strip the prefix off to save * some space (it is not that helpful for regular users anyway). * - * @param line log line to log + * @param lines log lines to log */ - public void logLine(final String line) + public void logLines(final ArrayList<String> lines) { mLogHandler.post(new Runnable() { @Override public void run() { - /* strip off prefix (month=3, day=2, time=8, thread=2, spaces=3) */ - mLogView.append((line.length() > 18 ? line.substring(18) : line) + '\n'); + mLogView.beginBatchEdit(); + for (String line : lines) + { /* strip off prefix (month=3, day=2, time=8, thread=2, spaces=3) */ + mLogView.append((line.length() > 18 ? line.substring(18) : line) + '\n'); + } + mLogView.endBatchEdit(); /* calling autoScroll() directly does not work, probably because content * is not yet updated, so we post this to be done later */ mScrollView.post(new Runnable() { @@ -147,18 +152,30 @@ public class LogFragment extends Fragment implements Runnable @Override public void run() { + ArrayList<String> lines = null; + while (mRunning) { try { /* this works as long as the file is not truncated */ String line = mReader.readLine(); if (line == null) - { /* wait until there is more to log */ + { + if (lines != null) + { + logLines(lines); + lines = null; + } + /* wait until there is more to log */ Thread.sleep(1000); } else { - logLine(line); + if (lines == null) + { + lines = new ArrayList<>(); + } + lines.add(line); } } catch (Exception e) @@ -166,6 +183,10 @@ public class LogFragment extends Fragment implements Runnable break; } } + if (lines != null) + { + logLines(lines); + } } /** |