diff options
-rwxr-xr-x | res/values/strings.xml | 4 | ||||
-rw-r--r-- | src/se/leap/leapclient/Dashboard.java | 59 |
2 files changed, 47 insertions, 16 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml index 3a17803..0981980 100755 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -314,5 +314,9 @@ <string name="log_out_failed_message">Didn\'t logged out.</string> <string name="successful_authed_cert_downloaded_message">Your own cert has been correctly downloaded.</string> <string name="authed_cert_download_failed_message">Your own cert has incorrectly been downloaded.</string> + <string name="eip_cancel_connect_title">Cancel connection?</string> + <string name="eip_cancel_connect_text">There is a connection attempt in progress. Do you wish to cancel it?</string> + <string name="eip_cancel_connect_cancel">Yes</string> + <string name="eip_cancel_connect_false">No</string> </resources> diff --git a/src/se/leap/leapclient/Dashboard.java b/src/se/leap/leapclient/Dashboard.java index 6634479..ebce35e 100644 --- a/src/se/leap/leapclient/Dashboard.java +++ b/src/se/leap/leapclient/Dashboard.java @@ -55,7 +55,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf private View eipDetail; private TextView eipStatus; - private boolean mEipWait = false; + private boolean mEipStartPending = false; private boolean authed = false; public ProviderAPIResultReceiver providerAPI_result_receiver; @@ -187,24 +187,51 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf 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); + + if (isChecked){ + mEipStartPending = true; + eipCommand(EIP.ACTION_START_EIP); + } else { + if (mEipStartPending){ + AlertDialog.Builder alertBuilder = new AlertDialog.Builder(getAppContext()); + alertBuilder.setTitle(getResources().getString(R.string.eip_cancel_connect_title)); + alertBuilder + .setMessage(getResources().getString(R.string.eip_cancel_connect_text)) + .setPositiveButton(getResources().getString(R.string.eip_cancel_connect_cancel), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + eipCommand(EIP.ACTION_STOP_EIP); + } + }) + .setNegativeButton(getResources().getString(R.string.eip_cancel_connect_false), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + eipSwitch.setChecked(true); + } + }) + .show(); } else { - vpnIntent = new Intent(EIP.ACTION_STOP_EIP); + eipCommand(EIP.ACTION_STOP_EIP); } - vpnIntent.putExtra(ConfigHelper.RECEIVER_TAG, mEIPReceiver); - startService(vpnIntent); } } }); } /** + * Send a command to EIP + * + * @param action A valid String constant from EIP class representing an Intent + * filter for the EIP class + */ + private void eipCommand(String action){ + // TODO validate "action"...how do we get the list of intent-filters for a class via Android API? + Intent vpnIntent = new Intent(action); + 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. * @@ -434,18 +461,22 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf @Override public void run() { if (eipStatus != null) { + boolean switchState = true; String statusMessage = ""; String prefix = getString(localizedResId); if (state.equals("CONNECTED")){ statusMessage = "Connection Secure"; + mEipStartPending = false; } else if (state.equals("BYTECOUNT")) { statusMessage = logmessage; } else if (state.equals("NOPROCESS") || state.equals("EXITING")) { statusMessage = "Not running! Connection not secure!"; + switchState = false; } else { statusMessage = prefix + logmessage; } + eipSwitch.setChecked(switchState); eipStatus.setText(statusMessage); } } @@ -474,7 +505,6 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf super.onReceiveResult(resultCode, resultData); String request = resultData.getString(ConfigHelper.REQUEST_TAG); - mEipWait = true; boolean checked = false; if (request == EIP.ACTION_IS_EIP_RUNNING) { @@ -515,10 +545,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf } } - Switch eipS = ((Switch) mDashboard.findViewById(R.id.eipSwitch)); - eipS.setChecked(checked); - eipS.setClickable(true); - mEipWait = false; + eipSwitch.setChecked(checked); } } } |