summaryrefslogtreecommitdiff
path: root/src/de/blinkt/openvpn/LogWindow.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/blinkt/openvpn/LogWindow.java')
-rw-r--r--src/de/blinkt/openvpn/LogWindow.java105
1 files changed, 72 insertions, 33 deletions
diff --git a/src/de/blinkt/openvpn/LogWindow.java b/src/de/blinkt/openvpn/LogWindow.java
index 16f54b12..f6004882 100644
--- a/src/de/blinkt/openvpn/LogWindow.java
+++ b/src/de/blinkt/openvpn/LogWindow.java
@@ -10,6 +10,7 @@ import android.os.Handler.Callback;
import android.os.Message;
import android.view.Menu;
import android.view.MenuInflater;
+import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
@@ -18,33 +19,42 @@ import android.widget.TextView;
import de.blinkt.openvpn.OpenVPN.LogListener;
public class LogWindow extends ListActivity {
-
+
class LogWindowListAdapter implements ListAdapter,LogListener, Callback {
+ private static final int MESSAGE_NEWLOG = 0;
+
+ private static final int MESSAGE_CLEARLOG = 1;
+
private Vector<String> myEntries=new Vector<String>();
-
+
private Handler mHandler;
private Vector<DataSetObserver> observers=new Vector<DataSetObserver>();
public LogWindowListAdapter() {
+ initLogBuffer();
+
+ if (mHandler == null) {
+ mHandler = new Handler(this);
+ }
+
+ OpenVPN.addLogListener(this);
+ }
+
+ private void initLogBuffer() {
+ myEntries.clear();
for (String litem : OpenVPN.getlogbuffer()) {
myEntries.add(litem);
}
-
- if (mHandler == null) {
- mHandler = new Handler(this);
- }
-
- OpenVPN.addLogListener(this);
}
-
+
@Override
public void registerDataSetObserver(DataSetObserver observer) {
observers.add(observer);
-
+
}
-
+
@Override
public void unregisterDataSetObserver(DataSetObserver observer) {
observers.remove(observer);
@@ -94,7 +104,7 @@ public class LogWindow extends ListActivity {
@Override
public boolean isEmpty() {
return myEntries.isEmpty();
-
+
}
@Override
@@ -110,6 +120,7 @@ public class LogWindow extends ListActivity {
@Override
public void newLog(String logmessage) {
Message msg = Message.obtain();
+ msg.what=MESSAGE_NEWLOG;
Bundle mbundle=new Bundle();
mbundle.putString("logmessage", logmessage);
msg.setData(mbundle);
@@ -119,39 +130,67 @@ public class LogWindow extends ListActivity {
@Override
public boolean handleMessage(Message msg) {
// We have been called
- String logmessage = msg.getData().getString("logmessage");
- myEntries.add(logmessage);
+ if(msg.what==MESSAGE_NEWLOG) {
+
+ String logmessage = msg.getData().getString("logmessage");
+ myEntries.add(logmessage);
- for (DataSetObserver observer : observers) {
- observer.onChanged();
+ for (DataSetObserver observer : observers) {
+ observer.onChanged();
+ }
+ } else if (msg.what == MESSAGE_CLEARLOG) {
+ initLogBuffer();
+ for (DataSetObserver observer : observers) {
+ observer.onInvalidated();
+ }
}
-
-
+
return true;
}
-
+
+ void clearLog() {
+ OpenVPN.clearLog();
+ OpenVPN.logMessage(0,"","Log cleared.");
+ mHandler.sendEmptyMessage(MESSAGE_CLEARLOG);
+ }
+
+ }
+
+
+
+ private LogWindowListAdapter ladapter;
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if(item.getItemId()==R.id.clearlog) {
+ ladapter.clearLog();
+ return true;
+ }
+
+ return super.onOptionsItemSelected(item);
+
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
- MenuInflater inflater = getMenuInflater();
- inflater.inflate(R.menu.logmenu, menu);
- return true;
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.logmenu, menu);
+ return true;
}
-
-
+
+
@Override
public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- ListView lv = getListView();
- //lv.setTextFilterEnabled(true);
- LogWindowListAdapter adapter = new LogWindowListAdapter();
- lv.setAdapter(adapter);
+ super.onCreate(savedInstanceState);
+
+ ListView lv = getListView();
+ //lv.setTextFilterEnabled(true);
+ ladapter = new LogWindowListAdapter();
+ lv.setAdapter(ladapter);
+
+ }
+
- }
-
-
}