diff options
author | Arne Schwabe <arne@rfc2549.org> | 2013-02-10 21:25:04 +0100 |
---|---|---|
committer | Arne Schwabe <arne@rfc2549.org> | 2013-02-10 21:25:04 +0100 |
commit | dad578cff15e77be2f7e1ce6ff2b8dad4753da4d (patch) | |
tree | 81c2902ad2b11e3f6b6b549c07b63193beb588d3 /src | |
parent | af936c72849df3ecd628d88018bc4631c367da49 (diff) |
Add timestamps to log window
--HG--
extra : rebase_source : cbcf8f519b4a2c616a645636653fe711304a5942
Diffstat (limited to 'src')
-rw-r--r-- | src/de/blinkt/openvpn/LogWindow.java | 47 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/OpenVPN.java | 66 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/OpenVpnService.java | 1 |
3 files changed, 87 insertions, 27 deletions
diff --git a/src/de/blinkt/openvpn/LogWindow.java b/src/de/blinkt/openvpn/LogWindow.java index 4d2047f8..ef29ad5e 100644 --- a/src/de/blinkt/openvpn/LogWindow.java +++ b/src/de/blinkt/openvpn/LogWindow.java @@ -1,5 +1,6 @@ package de.blinkt.openvpn; +import java.util.Date; import java.util.Vector; import android.app.AlertDialog; @@ -19,6 +20,7 @@ import android.os.Handler; import android.os.Handler.Callback; import android.os.IBinder; import android.os.Message; +import android.text.format.DateFormat; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; @@ -65,13 +67,17 @@ public class LogWindow extends ListActivity implements StateListener { private static final int MESSAGE_NEWLOG = 0; private static final int MESSAGE_CLEARLOG = 1; + + private static final int MESSAGE_NEWTS = 1; - private Vector<String> myEntries=new Vector<String>(); + private Vector<LogItem> myEntries=new Vector<LogItem>(); private Handler mHandler; private Vector<DataSetObserver> observers=new Vector<DataSetObserver>(); + private int mTimeFormat=0; + public LogWindowListAdapter() { initLogBuffer(); @@ -88,14 +94,14 @@ public class LogWindow extends ListActivity implements StateListener { private void initLogBuffer() { myEntries.clear(); for (LogItem litem : OpenVPN.getlogbuffer()) { - myEntries.add(litem.getString(getContext())); + myEntries.add(litem); } } String getLogStr() { String str = ""; - for(String entry:myEntries) { - str+=entry + '\n'; + for(LogItem entry:myEntries) { + str+=entry.getString(LogWindow.this) + '\n'; } return str; } @@ -147,7 +153,15 @@ public class LogWindow extends ListActivity implements StateListener { v = new TextView(getBaseContext()); else v = (TextView) convertView; - v.setText(myEntries.get(position)); + + LogItem le = myEntries.get(position); + String msg = le.getString(LogWindow.this); + if (mTimeFormat%2 == 1) { + Date d = new Date(le.getLogtime()); + String time = DateFormat.getTimeFormat(LogWindow.this).format(d); + msg = time + " " + msg; + } + v.setText(msg); return v; } @@ -182,7 +196,7 @@ public class LogWindow extends ListActivity implements StateListener { Message msg = Message.obtain(); msg.what=MESSAGE_NEWLOG; Bundle mbundle=new Bundle(); - mbundle.putString("logmessage", logmessage.getString(getBaseContext())); + mbundle.putParcelable("logmessage", logmessage); msg.setData(mbundle); mHandler.sendMessage(msg); } @@ -192,7 +206,7 @@ public class LogWindow extends ListActivity implements StateListener { // We have been called if(msg.what==MESSAGE_NEWLOG) { - String logmessage = msg.getData().getString("logmessage"); + LogItem logmessage = msg.getData().getParcelable("logmessage"); myEntries.add(logmessage); for (DataSetObserver observer : observers) { @@ -203,7 +217,11 @@ public class LogWindow extends ListActivity implements StateListener { for (DataSetObserver observer : observers) { observer.onInvalidated(); } - } + } else if (msg.what == MESSAGE_NEWTS) { + for (DataSetObserver observer : observers) { + observer.onInvalidated(); + } + } return true; } @@ -215,6 +233,13 @@ public class LogWindow extends ListActivity implements StateListener { OpenVPN.logMessage(0,"","Log cleared."); mHandler.sendEmptyMessage(MESSAGE_CLEARLOG); } + + + + public void nextTimeFormat() { + mTimeFormat+=1; + mHandler.sendEmptyMessage(MESSAGE_NEWTS); + } } @@ -261,7 +286,8 @@ public class LogWindow extends ListActivity implements StateListener { } else { Toast.makeText(this, R.string.log_no_last_vpn, Toast.LENGTH_LONG).show(); } - + } else if(item.getItemId() == R.id.toggle_time) { + ladapter.nextTimeFormat(); } else if(item.getItemId() == android.R.id.home) { // This is called when the Home (Up) button is pressed // in the Action Bar. @@ -278,9 +304,6 @@ public class LogWindow extends ListActivity implements StateListener { } - protected Context getContext() { - return this; - } @Override public boolean onCreateOptionsMenu(Menu menu) { diff --git a/src/de/blinkt/openvpn/OpenVPN.java b/src/de/blinkt/openvpn/OpenVPN.java index 2ca2d259..03db7677 100644 --- a/src/de/blinkt/openvpn/OpenVPN.java +++ b/src/de/blinkt/openvpn/OpenVPN.java @@ -6,6 +6,8 @@ import java.util.Vector; import android.content.Context; import android.os.Build; +import android.os.Parcel; +import android.os.Parcelable; public class OpenVPN { @@ -23,7 +25,7 @@ public class OpenVPN { private static String mLaststate = "NOPROCESS"; private static int mLastStateresid=R.string.state_noprocess; - + private static long mlastByteCount[]={0,0,0,0}; static { @@ -34,7 +36,7 @@ public class OpenVPN { logInformation(); } - public static class LogItem { + public static class LogItem implements Parcelable { public static final int ERROR = 1; public static final int INFO = 2; public static final int VERBOSE = 3; @@ -44,12 +46,46 @@ public class OpenVPN { private int mRessourceId; // Default log priority int mLevel = INFO; + private long logtime = System.currentTimeMillis(); public LogItem(int ressourceId, Object[] args) { mRessourceId = ressourceId; mArgs = args; } + @Override + public int describeContents() { + return 0; + } + + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeArray(mArgs); + dest.writeString(mMessage); + dest.writeInt(mRessourceId); + dest.writeInt(mLevel); + dest.writeLong(logtime); + } + + public LogItem(Parcel in) { + mArgs = in.readArray(Object.class.getClassLoader()); + mMessage = in.readString(); + mRessourceId = in.readInt(); + mLevel = in.readInt(); + logtime = in.readLong(); + } + + public static final Parcelable.Creator<LogItem> CREATOR + = new Parcelable.Creator<LogItem>() { + public LogItem createFromParcel(Parcel in) { + return new LogItem(in); + } + + public LogItem[] newArray(int size) { + return new LogItem[size]; + } + }; public LogItem(int loglevel,int ressourceId, Object[] args) { mRessourceId = ressourceId; @@ -73,7 +109,6 @@ public class OpenVPN { mLevel = loglevel; } - public String getString(Context c) { if(mMessage !=null) { return mMessage; @@ -87,21 +122,22 @@ public class OpenVPN { String str = String.format(Locale.ENGLISH,"Log (no context) resid %d", mRessourceId); if(mArgs !=null) for(Object o:mArgs) - str += "|" + o.toString(); + str += "|" + o.toString(); return str; } } } - } - private static final int MAXLOGENTRIES = 500; - - - public static final String MANAGMENT_PREFIX = "M:"; + public long getLogtime() { + return logtime; + } + } + private static final int MAXLOGENTRIES = 500; + public static final String MANAGMENT_PREFIX = "M:"; public interface LogListener { @@ -111,7 +147,7 @@ public class OpenVPN { public interface StateListener { void updateState(String state, String logmessage, int localizedResId); } - + public interface ByteCountListener { void updateByteCount(long in, long out, long diffin, long diffout); } @@ -139,12 +175,12 @@ public class OpenVPN { public synchronized static void removeLogListener(LogListener ll) { logListener.remove(ll); } - + public static void addByteCountListener(ByteCountListener bcl) { bcl.updateByteCount(mlastByteCount[0], mlastByteCount[1], mlastByteCount[2], mlastByteCount[3]); byteCountListener.add(bcl); } - + public static void removeByteCountListener(ByteCountListener bcl) { byteCountListener.remove(bcl); } @@ -157,7 +193,7 @@ public class OpenVPN { sl.updateState(mLaststate, mLaststatemsg, mLastStateresid); } } - + private static int getLocalizedState(String state){ if (state.equals("CONNECTING")) return R.string.state_connecting; @@ -223,7 +259,7 @@ public class OpenVPN { mLaststate= state; mLaststatemsg = msg; mLastStateresid = resid; - + for (StateListener sl : stateListener) { sl.updateState(state,msg,resid); } @@ -264,7 +300,7 @@ public class OpenVPN { long lastOut = mlastByteCount[1]; long diffin = in - lastIn; long diffout = out - lastOut; - + mlastByteCount = new long[] {in,out,diffin,diffout}; for(ByteCountListener bcl:byteCountListener){ bcl.updateByteCount(in, out, diffin,diffout); diff --git a/src/de/blinkt/openvpn/OpenVpnService.java b/src/de/blinkt/openvpn/OpenVpnService.java index ce9f75a1..881eda9d 100644 --- a/src/de/blinkt/openvpn/OpenVpnService.java +++ b/src/de/blinkt/openvpn/OpenVpnService.java @@ -316,6 +316,7 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); mOvpn3 = prefs.getBoolean("ovpn3", false); + mOvpn3 = false; Runnable processThread; if(mOvpn3) { |