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.java51
1 files changed, 48 insertions, 3 deletions
diff --git a/src/de/blinkt/openvpn/LogWindow.java b/src/de/blinkt/openvpn/LogWindow.java
index 88615e12..4d2047f8 100644
--- a/src/de/blinkt/openvpn/LogWindow.java
+++ b/src/de/blinkt/openvpn/LogWindow.java
@@ -7,14 +7,17 @@ import android.app.AlertDialog.Builder;
import android.app.ListActivity;
import android.content.ClipData;
import android.content.ClipboardManager;
+import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
+import android.content.ServiceConnection;
import android.database.DataSetObserver;
import android.os.Bundle;
import android.os.Handler;
import android.os.Handler.Callback;
+import android.os.IBinder;
import android.os.Message;
import android.view.Menu;
import android.view.MenuInflater;
@@ -30,10 +33,31 @@ import android.widget.Toast;
import de.blinkt.openvpn.OpenVPN.LogItem;
import de.blinkt.openvpn.OpenVPN.LogListener;
import de.blinkt.openvpn.OpenVPN.StateListener;
+import de.blinkt.openvpn.OpenVpnService.LocalBinder;
public class LogWindow extends ListActivity implements StateListener {
private static final int START_VPN_CONFIG = 0;
private String[] mBconfig=null;
+ protected OpenVpnService mService;
+ private ServiceConnection mConnection = new ServiceConnection() {
+
+
+
+ @Override
+ public void onServiceConnected(ComponentName className,
+ IBinder service) {
+ // We've bound to LocalService, cast the IBinder and get LocalService instance
+ LocalBinder binder = (LocalBinder) service;
+ mService = binder.getService();
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName arg0) {
+ mService =null;
+ }
+
+ };
+
class LogWindowListAdapter implements ListAdapter, LogListener, Callback {
@@ -198,6 +222,7 @@ public class LogWindow extends ListActivity implements StateListener {
private LogWindowListAdapter ladapter;
private TextView mSpeedView;
+
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId()==R.id.clearlog) {
@@ -213,7 +238,8 @@ public class LogWindow extends ListActivity implements StateListener {
@Override
public void onClick(DialogInterface dialog, int which) {
ProfileManager.setConntectedVpnProfileDisconnected(getApplicationContext());
- OpenVpnManagementThread.stopOpenVPN();
+ if(mService.getManagement()!=null)
+ mService.getManagement().stopVPN();
}
});
@@ -236,9 +262,18 @@ public class LogWindow extends ListActivity implements StateListener {
Toast.makeText(this, R.string.log_no_last_vpn, Toast.LENGTH_LONG).show();
}
+ } else if(item.getItemId() == android.R.id.home) {
+ // This is called when the Home (Up) button is pressed
+ // in the Action Bar.
+ Intent parentActivityIntent = new Intent(this, MainActivity.class);
+ parentActivityIntent.addFlags(
+ Intent.FLAG_ACTIVITY_CLEAR_TOP |
+ Intent.FLAG_ACTIVITY_NEW_TASK);
+ startActivity(parentActivityIntent);
+ finish();
+ return true;
}
-
return super.onOptionsItemSelected(item);
}
@@ -324,6 +359,13 @@ public class LogWindow extends ListActivity implements StateListener {
lv.setAdapter(ladapter);
mSpeedView = (TextView) findViewById(R.id.speed);
+ getActionBar().setDisplayHomeAsUpEnabled(true);
+
+ Intent intent = new Intent(getBaseContext(), OpenVpnService.class);
+ intent.setAction(OpenVpnService.START_SERVICE);
+
+ bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
+
}
@Override
@@ -335,6 +377,8 @@ public class LogWindow extends ListActivity implements StateListener {
String prefix=getString(resid) + ":";
if (status.equals("BYTECOUNT") || status.equals("NOPROCESS") )
prefix="";
+ if (resid==R.string.unknown_state)
+ prefix+=status;
mSpeedView.setText(prefix + logmessage);
}
});
@@ -343,8 +387,9 @@ public class LogWindow extends ListActivity implements StateListener {
@Override
protected void onDestroy() {
- super.onDestroy();
+ unbindService(mConnection);
OpenVPN.removeLogListener(ladapter);
+ super.onDestroy();
}
}