summaryrefslogtreecommitdiff
path: root/src/se/leap/leapclient/Dashboard.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/se/leap/leapclient/Dashboard.java')
-rw-r--r--src/se/leap/leapclient/Dashboard.java206
1 files changed, 11 insertions, 195 deletions
diff --git a/src/se/leap/leapclient/Dashboard.java b/src/se/leap/leapclient/Dashboard.java
index 1b6b8e38..4cd517a9 100644
--- a/src/se/leap/leapclient/Dashboard.java
+++ b/src/se/leap/leapclient/Dashboard.java
@@ -6,14 +6,12 @@ import org.json.JSONException;
import org.json.JSONObject;
import se.leap.leapclient.ProviderAPIResultReceiver.Receiver;
-import se.leap.openvpn.LogWindow;
import se.leap.openvpn.MainActivity;
-import se.leap.openvpn.OpenVPN;
-import se.leap.openvpn.OpenVPN.StateListener;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.DialogFragment;
import android.app.Fragment;
+import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.app.ProgressDialog;
import android.content.Context;
@@ -22,15 +20,10 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
-import android.os.ResultReceiver;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
-import android.view.ViewStub;
-import android.widget.CompoundButton;
-import android.widget.RelativeLayout;
-import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
@@ -40,26 +33,23 @@ import android.widget.Toast;
*
* @author Sean Leonard <meanderingcode@aetherislands.net>
*/
-public class Dashboard extends Activity implements LogInDialog.LogInDialogInterface,Receiver,StateListener {
+public class Dashboard extends Activity implements LogInDialog.LogInDialogInterface,Receiver {
protected static final int CONFIGURE_LEAP = 0;
+ private static final String TAG_EIP_FRAGMENT = "EIP_DASHBOARD_FRAGMENT";
+
private ProgressDialog mProgressDialog;
+
private static Context app;
private static SharedPreferences preferences;
private static Provider provider;
private TextView providerNameTV;
- private TextView eipTypeTV;
- private Switch eipSwitch;
- private View eipDetail;
- private TextView eipStatus;
-
- private boolean mEipWait = false;
+
private boolean authed = false;
public ProviderAPIResultReceiver providerAPI_result_receiver;
- private EIPReceiver mEIPReceiver;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -77,28 +67,12 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
else
buildDashboard();
}
-
- @Override
- protected void onStop() {
- super.onStop();
- if (provider != null)
- if (provider.hasEIP() && provider.getEIPType() == "OpenVPN")
- OpenVPN.removeStateListener(this);
- }
-
- @Override
- protected void onResume() {
- super.onResume();
-
- if (provider != null)
- if (provider.hasEIP() && provider.getEIPType() == "OpenVPN")
- OpenVPN.addStateListener(this);
- }
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
if ( requestCode == CONFIGURE_LEAP ) {
if ( resultCode == RESULT_OK ){
+ startService( new Intent(EIP.ACTION_UPDATE_EIP_SERVICE) );
buildDashboard();
if(data != null && data.hasExtra(ConfigHelper.LOG_IN)) {
View view = ((ViewGroup)findViewById(android.R.id.content)).getChildAt(0);
@@ -149,84 +123,13 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
providerNameTV.setText(provider.getName());
providerNameTV.setTextSize(28);
- if ( provider.hasEIP() ){
- startService( new Intent(EIP.ACTION_UPDATE_EIP_SERVICE) );
- if (provider.getEIPType() == "OpenVPN")
- OpenVPN.addStateListener(this);
- serviceItemEIP();
+ FragmentManager fragMan = getFragmentManager();
+ if ( provider.hasEIP() && fragMan.findFragmentByTag(TAG_EIP_FRAGMENT) == null){
+ EipServiceFragment eipFragment = new EipServiceFragment();
+ fragMan.beginTransaction().add(R.id.servicesCollection, eipFragment, TAG_EIP_FRAGMENT).commit();
}
}
- /**
- * Builds the UI for the EIP service Dashboard component
- */
- private void serviceItemEIP() {
- mEIPReceiver = new EIPReceiver(new Handler());
- mEIPReceiver.setReceiver(this);
-
- Intent intent = new Intent(this,EIP.class);
- intent.setAction(EIP.ACTION_IS_EIP_RUNNING);
- intent.putExtra(ConfigHelper.RECEIVER_TAG, mEIPReceiver);
- startService(intent);
-
- ViewStub eip_overview_stub = ((ViewStub) findViewById(R.id.eipOverviewStub));
- if(eip_overview_stub != null)
- eip_overview_stub.inflate();
-
- eipTypeTV = (TextView) findViewById(R.id.eipType);
- eipTypeTV.setText(provider.getEIPType());
-
- eipDetail = ((RelativeLayout) findViewById(R.id.eipDetail));
- View eipSettings = findViewById(R.id.eipSettings);
- eipSettings.setVisibility(View.GONE); // FIXME too!
- eipDetail.setVisibility(View.VISIBLE);
- eipStatus = (TextView) findViewById(R.id.eipStatus);
-
- eipSwitch = (Switch) findViewById(R.id.eipSwitch);
- eipSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- if (!mEipWait){
- buttonView.setClickable(false);
- mEipWait = true;
-
- Intent vpnIntent;
- if (isChecked){
- vpnIntent = new Intent(EIP.ACTION_START_EIP);
- } else {
- vpnIntent = new Intent(EIP.ACTION_STOP_EIP);
- }
- vpnIntent.putExtra(ConfigHelper.RECEIVER_TAG, mEIPReceiver);
- startService(vpnIntent);
- }
- }
- });
- }
-
- /**
- * Expands the EIP Dashboard component for extra details view.
- * Called by onClick property in client_dashboard.xml layout.
- *
- * @param view (Unused) The View calling this method by its onClick property
- */
- public void toggleEipOverview(View view) {
- if (eipDetail.isShown())
- eipDetail.setVisibility(View.GONE);
- else
- eipDetail.setVisibility(View.VISIBLE);
- }
-
- /**
- * Launches the se.leap.openvpn.LogWindow Activity showing detailed OpenVPN log
- *
- * @param view (Unused) The View calling this method by its onClick property
- */
- public void showEIPLog(View view){
- Intent intent = new Intent(getBaseContext(),LogWindow.class);
- intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
- startActivity(intent);
- }
-
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
JSONObject provider_json;
@@ -424,91 +327,4 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
return app;
}
- @Override
- public void updateState(final String state, final String logmessage, final int localizedResId) {
- // Note: "states" are not organized anywhere...collected state strings:
- // NOPROCESS,NONETWORK,BYTECOUNT,AUTH_FAILED + some parsing thing ( WAIT(?),AUTH,GET_CONFIG,ASSIGN_IP,CONNECTED(?) )
- runOnUiThread(new Runnable() {
-
- @Override
- public void run() {
- if (eipStatus != null) {
- String prefix = getString(localizedResId) + ":";
- if (state.equals("BYTECOUNT") || state.equals("NOPROCESS"))
- prefix = "";
- eipStatus.setText(prefix + logmessage);
- }
- }
- });
- }
-
- /**
- * Inner class for handling messages related to EIP status and control requests
- *
- * @author Sean Leonard <meanderingcode@aetherislands.net>
- */
- protected class EIPReceiver extends ResultReceiver {
-
- Dashboard mDashboard;
-
- protected EIPReceiver(Handler handler){
- super(handler);
- }
-
- public void setReceiver(Dashboard receiver) {
- mDashboard = receiver;
- }
-
- @Override
- protected void onReceiveResult(int resultCode, Bundle resultData) {
- super.onReceiveResult(resultCode, resultData);
-
- String request = resultData.getString(ConfigHelper.REQUEST_TAG);
- mEipWait = true;
- boolean checked = false;
-
- if (request == EIP.ACTION_IS_EIP_RUNNING) {
- switch (resultCode){
- case RESULT_OK:
- checked = true;
- break;
- case RESULT_CANCELED:
- checked = false;
- break;
- }
- } else if (request == EIP.ACTION_START_EIP) {
- switch (resultCode){
- case RESULT_OK:
- checked = true;
- break;
- case RESULT_CANCELED:
- checked = false;
- break;
- }
- } else if (request == EIP.ACTION_STOP_EIP) {
- switch (resultCode){
- case RESULT_OK:
- checked = false;
- break;
- case RESULT_CANCELED:
- checked = true;
- break;
- }
- } else if (request == EIP.EIP_NOTIFICATION) {
- switch (resultCode){
- case RESULT_OK:
- checked = true;
- break;
- case RESULT_CANCELED:
- checked = false;
- break;
- }
- }
-
- Switch eipS = ((Switch) mDashboard.findViewById(R.id.eipSwitch));
- eipS.setChecked(checked);
- eipS.setClickable(true);
- mEipWait = false;
- }
- }
}