From a222c8d4489c9e0606266e5185f4f3bb5e240fed Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Thu, 5 Dec 2013 17:35:11 +0100 Subject: Also log time in exports --- src/de/blinkt/openvpn/fragments/LogFragment.java | 49 ++++++++++++++++-------- 1 file changed, 34 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/de/blinkt/openvpn/fragments/LogFragment.java b/src/de/blinkt/openvpn/fragments/LogFragment.java index a03d5160..a2a6e3c4 100644 --- a/src/de/blinkt/openvpn/fragments/LogFragment.java +++ b/src/de/blinkt/openvpn/fragments/LogFragment.java @@ -130,6 +130,7 @@ public class LogFragment extends ListFragment implements StateListener, SeekBar. public static final int TIME_FORMAT_NONE = 0; public static final int TIME_FORMAT_SHORT = 1; public static final int TIME_FORMAT_ISO = 2; + private static final int MAX_STORED_LOG_ENTRIES = 1000; private Vector allEntries=new Vector(); @@ -163,7 +164,7 @@ public class LogFragment extends ListFragment implements StateListener, SeekBar. String getLogStr() { String str = ""; for(LogItem entry:allEntries) { - str+=entry.getString(getActivity()) + '\n'; + str+=getTime(entry, TIME_FORMAT_ISO) + entry.getString(getActivity()) + '\n'; } return str; } @@ -218,17 +219,7 @@ public class LogFragment extends ListFragment implements StateListener, SeekBar. LogItem le = currentLevelEntries.get(position); String msg = le.getString(getActivity()); - String time =""; - if (mTimeFormat != TIME_FORMAT_NONE) { - Date d = new Date(le.getLogtime()); - java.text.DateFormat timeformat; - if (mTimeFormat== TIME_FORMAT_ISO) - timeformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",Locale.getDefault()); - else - timeformat = DateFormat.getTimeFormat(getActivity()); - time = timeformat.format(d) + " "; - - } + String time = getTime(le, mTimeFormat); msg = time + msg; int spanStart = time.length(); @@ -240,6 +231,23 @@ public class LogFragment extends ListFragment implements StateListener, SeekBar. return v; } + private String getTime(LogItem le, int time) { + if (time != TIME_FORMAT_NONE) { + Date d = new Date(le.getLogtime()); + java.text.DateFormat timeformat; + if (time== TIME_FORMAT_ISO) + timeformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); + else + timeformat = DateFormat.getTimeFormat(getActivity()); + + return timeformat.format(d) + " "; + + } else { + return ""; + } + + } + private ImageSpan getSpanImage(LogItem li, int imageSize) { int imageRes = android.R.drawable.ic_menu_call; @@ -352,11 +360,22 @@ public class LogFragment extends ListFragment implements StateListener, SeekBar. */ private boolean addLogMessage(LogItem logmessage) { allEntries.add(logmessage); - if (logmessage.getVerbosityLevel() <= mLogLevel) { - currentLevelEntries.add(logmessage); + + if (allEntries.size() > MAX_STORED_LOG_ENTRIES) { + Vector oldAllEntries = allEntries; + allEntries = new Vector(allEntries.size()); + for (int i=50;i