diff options
author | schwabe <devnull@localhost> | 2012-04-28 19:58:02 +0200 |
---|---|---|
committer | schwabe <devnull@localhost> | 2012-04-28 19:58:02 +0200 |
commit | 63e466054c2f1d66e4618ac4d73208751f1e5bd1 (patch) | |
tree | 84a00021ec486093b406ec050087ee486f6e6958 /src/de/blinkt/openvpn/LogWindow.java | |
parent | 031186e74c9f174d05a09c4059def7bcbc558ac6 (diff) |
Almost ready for version 0.4
Diffstat (limited to 'src/de/blinkt/openvpn/LogWindow.java')
-rw-r--r-- | src/de/blinkt/openvpn/LogWindow.java | 151 |
1 files changed, 132 insertions, 19 deletions
diff --git a/src/de/blinkt/openvpn/LogWindow.java b/src/de/blinkt/openvpn/LogWindow.java index a26da2ba..6c3e1ff7 100644 --- a/src/de/blinkt/openvpn/LogWindow.java +++ b/src/de/blinkt/openvpn/LogWindow.java @@ -1,37 +1,150 @@ package de.blinkt.openvpn; +import java.util.Vector; + import android.app.ListActivity; +import android.database.DataSetObserver; import android.os.Bundle; +import android.os.Handler; +import android.os.Handler.Callback; +import android.os.Message; import android.view.View; -import android.widget.AdapterView; -import android.widget.AdapterView.OnItemClickListener; -import android.widget.ArrayAdapter; +import android.view.ViewGroup; +import android.widget.ListAdapter; import android.widget.ListView; +import android.widget.SimpleAdapter; +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 LIST_CHANGED = 0; + + private Vector<String> myEntries=new Vector<String>(); + + private Handler mHandler; + + private Vector<DataSetObserver> observers=new Vector<DataSetObserver>(); + + public LogWindowListAdapter() { + 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); + } + + @Override + public int getCount() { + return myEntries.size(); + } + + @Override + public Object getItem(int position) { + return myEntries.get(position); + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public boolean hasStableIds() { + return true; + } + @Override + public View getView(int position, View convertView, ViewGroup parent) { + TextView v; + if(convertView==null) + v = new TextView(getBaseContext()); + else + v = (TextView) convertView; + v.setText(myEntries.get(position)); + return v; + } + + @Override + public int getItemViewType(int position) { + return 0; + } + + @Override + public int getViewTypeCount() { + return 1; + } + @Override + public boolean isEmpty() { + return myEntries.isEmpty(); + + } + + @Override + public boolean areAllItemsEnabled() { + return true; + } + + @Override + public boolean isEnabled(int position) { + return true; + } + + @Override + public void newLog(String logmessage) { + Message msg = Message.obtain(); + Bundle mbundle=new Bundle(); + mbundle.putString("logmessage", logmessage); + msg.setData(mbundle); + mHandler.sendMessage(msg); + } + + @Override + public boolean handleMessage(Message msg) { + // We have been called + String logmessage = msg.getData().getString("logmessage"); + myEntries.add(logmessage); + + for (DataSetObserver observer : observers) { + observer.onChanged(); + } + + + return true; + } + + } -public class LogWindow extends ListActivity implements OnItemClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - //setListAdapter(new ArrayAdapter<String>(this, R.layout.log_entry, COUNTRIES)); - setListAdapter(new ArrayAdapter<String>(this, R.layout.log_entry, OpenVPN.getlogbuffer())); - //setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, OpenVPN.logbuffer)); - + ListView lv = getListView(); - lv.setTextFilterEnabled(true); + //lv.setTextFilterEnabled(true); + LogWindowListAdapter adapter = new LogWindowListAdapter(); + lv.setAdapter(adapter); - lv.setOnItemClickListener(this); } + + - @Override - public void onItemClick(AdapterView<?> parent, View view, - int position, long id) { - // When clicked, show a toast with the TextView text - //Toast.makeText(getApplicationContext(), ((TextView) view).getText(), - //Toast.LENGTH_SHORT).show(); - - setListAdapter(new ArrayAdapter<String>(this, R.layout.log_entry, OpenVPN.getlogbuffer())); - } } |