From 44fa929579f9d801de9b62269f80310f3405ba4a Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Mon, 30 Apr 2012 02:53:12 +0200 Subject: version 0.4.2 --HG-- rename : src/de/blinkt/openvpn/BasicSettings.java => src/de/blinkt/openvpn/Settings_Basic.java --- src/de/blinkt/openvpn/VPNProfileList.java | 71 ++++++++++++++++++++++++------- 1 file changed, 55 insertions(+), 16 deletions(-) (limited to 'src/de/blinkt/openvpn/VPNProfileList.java') diff --git a/src/de/blinkt/openvpn/VPNProfileList.java b/src/de/blinkt/openvpn/VPNProfileList.java index 8f4304dc..bc61dddb 100644 --- a/src/de/blinkt/openvpn/VPNProfileList.java +++ b/src/de/blinkt/openvpn/VPNProfileList.java @@ -13,6 +13,7 @@ import android.preference.PreferenceScreen; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; +import android.view.inputmethod.EditorInfo; import android.widget.EditText; import android.widget.Toast; import de.blinkt.openvpn.VPNConfigPreference.VpnPreferencesClickListener; @@ -58,6 +59,39 @@ public class VPNProfileList extends PreferenceFragment implements VpnPreference } } + private void askForPW(String type) { + + final EditText entry = new EditText(getActivity()); + entry.setSingleLine(); + entry.setInputType(EditorInfo.TYPE_TEXT_VARIATION_PASSWORD); + + AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity()); + dialog.setTitle("Need " + type); + dialog.setMessage("Enter the password for profile " + mSelectedVPN.mName); + dialog.setView(entry); + + dialog.setPositiveButton(android.R.string.ok, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + String pw = entry.getText().toString(); + mSelectedVPN.mTransientPW = pw; + onActivityResult(START_VPN_PROFILE, Activity.RESULT_OK, null); + + } + + }); + dialog.setNegativeButton(android.R.string.cancel, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + } + }); + + dialog.create().show(); + + } + private void onAddProfileClicked() { Context context = getActivity(); if (context != null) { @@ -97,7 +131,7 @@ public class VPNProfileList extends PreferenceFragment implements VpnPreference } - + private void addProfile(VpnProfile profile) { getPM().addProfile(profile); getPM().saveProfileList(getActivity()); @@ -107,7 +141,7 @@ public class VPNProfileList extends PreferenceFragment implements VpnPreference - + public void refreshList() { PreferenceScreen plist = getPreferenceScreen(); @@ -159,7 +193,12 @@ public class VPNProfileList extends PreferenceFragment implements VpnPreference public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(requestCode==START_VPN_PROFILE && resultCode == Activity.RESULT_OK) { - new startOpenVpnThread().start(); + + if(mSelectedVPN.needUserPWInput()!=null) { + askForPW(mSelectedVPN.needUserPWInput()); + } else { + new startOpenVpnThread().start(); + } } else if (requestCode == START_VPN_CONFIG && resultCode == Activity.RESULT_OK) { String configuredVPN = data.getStringExtra(getActivity().getPackageName() + ".profileUUID"); @@ -183,44 +222,44 @@ public class VPNProfileList extends PreferenceFragment implements VpnPreference Intent startLW = new Intent(getActivity().getBaseContext(),LogWindow.class); startActivity(startLW); - + OpenVPN.logMessage(0, "", "Building configration..."); - + Intent startVPN = mSelectedVPN.prepareIntent(getActivity()); - + getActivity().startService(startVPN); getActivity().finish(); - + } } void showConfigErrorDialog(int vpnok) { - + AlertDialog.Builder d = new AlertDialog.Builder(getActivity()); d.setTitle(R.string.config_error_found); - + d.setMessage(vpnok); - - + + d.setPositiveButton("Ok", null); - + d.show(); } - + @Override public void onStartVPNClick(VPNConfigPreference preference) { getPM(); // Query the System for permission mSelectedVPN = ProfileManager.get(preference.getKey()); - + int vpnok = mSelectedVPN.checkProfile(); if(vpnok!= R.string.no_error_found) { showConfigErrorDialog(vpnok); return; } - - + + getPM().saveProfile(getActivity(), mSelectedVPN); Intent intent = VpnService.prepare(getActivity()); -- cgit v1.2.3