android: Add helper to read strings from text boxes
This commit is contained in:
+24
-22
@@ -28,7 +28,6 @@ import android.security.KeyChain;
|
|||||||
import android.security.KeyChainAliasCallback;
|
import android.security.KeyChainAliasCallback;
|
||||||
import android.security.KeyChainException;
|
import android.security.KeyChainException;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.Html;
|
|
||||||
import android.text.SpannableString;
|
import android.text.SpannableString;
|
||||||
import android.text.Spanned;
|
import android.text.Spanned;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@@ -632,14 +631,14 @@ public class VpnProfileDetailActivity extends AppCompatActivity
|
|||||||
private boolean verifyInput()
|
private boolean verifyInput()
|
||||||
{
|
{
|
||||||
boolean valid = true;
|
boolean valid = true;
|
||||||
if (mGateway.getText().toString().trim().isEmpty())
|
if (getString(mGateway) == null)
|
||||||
{
|
{
|
||||||
mGatewayWrap.setError(getString(R.string.alert_text_no_input_gateway));
|
mGatewayWrap.setError(getString(R.string.alert_text_no_input_gateway));
|
||||||
valid = false;
|
valid = false;
|
||||||
}
|
}
|
||||||
if (mVpnType.has(VpnTypeFeature.USER_PASS))
|
if (mVpnType.has(VpnTypeFeature.USER_PASS))
|
||||||
{
|
{
|
||||||
if (mUsername.getText().toString().trim().isEmpty())
|
if (getString(mUsername) == null)
|
||||||
{
|
{
|
||||||
mUsernameWrap.setError(getString(R.string.alert_text_no_input_username));
|
mUsernameWrap.setError(getString(R.string.alert_text_no_input_username));
|
||||||
valid = false;
|
valid = false;
|
||||||
@@ -705,17 +704,15 @@ public class VpnProfileDetailActivity extends AppCompatActivity
|
|||||||
private void updateProfileData()
|
private void updateProfileData()
|
||||||
{
|
{
|
||||||
/* the name is optional, we default to the gateway if none is given */
|
/* the name is optional, we default to the gateway if none is given */
|
||||||
String name = mName.getText().toString().trim();
|
String name = getString(mName);
|
||||||
String gateway = mGateway.getText().toString().trim();
|
String gateway = getString(mGateway);
|
||||||
mProfile.setName(name.isEmpty() ? gateway : name);
|
mProfile.setName(name == null ? gateway : name);
|
||||||
mProfile.setGateway(gateway);
|
mProfile.setGateway(gateway);
|
||||||
mProfile.setVpnType(mVpnType);
|
mProfile.setVpnType(mVpnType);
|
||||||
if (mVpnType.has(VpnTypeFeature.USER_PASS))
|
if (mVpnType.has(VpnTypeFeature.USER_PASS))
|
||||||
{
|
{
|
||||||
mProfile.setUsername(mUsername.getText().toString().trim());
|
mProfile.setUsername(getString(mUsername));
|
||||||
String password = mPassword.getText().toString().trim();
|
mProfile.setPassword(getString(mPassword));
|
||||||
password = password.isEmpty() ? null : password;
|
|
||||||
mProfile.setPassword(password);
|
|
||||||
}
|
}
|
||||||
if (mVpnType.has(VpnTypeFeature.CERTIFICATE))
|
if (mVpnType.has(VpnTypeFeature.CERTIFICATE))
|
||||||
{
|
{
|
||||||
@@ -724,8 +721,7 @@ public class VpnProfileDetailActivity extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
String certAlias = mCheckAuto.isChecked() ? null : mCertEntry.getAlias();
|
String certAlias = mCheckAuto.isChecked() ? null : mCertEntry.getAlias();
|
||||||
mProfile.setCertificateAlias(certAlias);
|
mProfile.setCertificateAlias(certAlias);
|
||||||
String remote_id = mRemoteId.getText().toString().trim();
|
mProfile.setRemoteId(getString(mRemoteId));
|
||||||
mProfile.setRemoteId(remote_id.isEmpty() ? null : remote_id);
|
|
||||||
mProfile.setMTU(getInteger(mMTU));
|
mProfile.setMTU(getInteger(mMTU));
|
||||||
mProfile.setPort(getInteger(mPort));
|
mProfile.setPort(getInteger(mPort));
|
||||||
mProfile.setNATKeepAlive(getInteger(mNATKeepalive));
|
mProfile.setNATKeepAlive(getInteger(mNATKeepalive));
|
||||||
@@ -736,22 +732,17 @@ public class VpnProfileDetailActivity extends AppCompatActivity
|
|||||||
flags |= mStrictRevocation.isChecked() ? VpnProfile.FLAGS_STRICT_REVOCATION : 0;
|
flags |= mStrictRevocation.isChecked() ? VpnProfile.FLAGS_STRICT_REVOCATION : 0;
|
||||||
flags |= mRsaPss.isChecked() ? VpnProfile.FLAGS_RSA_PSS : 0;
|
flags |= mRsaPss.isChecked() ? VpnProfile.FLAGS_RSA_PSS : 0;
|
||||||
mProfile.setFlags(flags);
|
mProfile.setFlags(flags);
|
||||||
String included = mIncludedSubnets.getText().toString().trim();
|
mProfile.setIncludedSubnets(getString(mIncludedSubnets));
|
||||||
mProfile.setIncludedSubnets(included.isEmpty() ? null : included);
|
mProfile.setExcludedSubnets(getString(mExcludedSubnets));
|
||||||
String excluded = mExcludedSubnets.getText().toString().trim();
|
|
||||||
mProfile.setExcludedSubnets(excluded.isEmpty() ? null : excluded);
|
|
||||||
int st = 0;
|
int st = 0;
|
||||||
st |= mBlockIPv4.isChecked() ? VpnProfile.SPLIT_TUNNELING_BLOCK_IPV4 : 0;
|
st |= mBlockIPv4.isChecked() ? VpnProfile.SPLIT_TUNNELING_BLOCK_IPV4 : 0;
|
||||||
st |= mBlockIPv6.isChecked() ? VpnProfile.SPLIT_TUNNELING_BLOCK_IPV6 : 0;
|
st |= mBlockIPv6.isChecked() ? VpnProfile.SPLIT_TUNNELING_BLOCK_IPV6 : 0;
|
||||||
mProfile.setSplitTunneling(st == 0 ? null : st);
|
mProfile.setSplitTunneling(st == 0 ? null : st);
|
||||||
mProfile.setSelectedAppsHandling(mSelectedAppsHandling);
|
mProfile.setSelectedAppsHandling(mSelectedAppsHandling);
|
||||||
mProfile.setSelectedApps(mSelectedApps);
|
mProfile.setSelectedApps(mSelectedApps);
|
||||||
String ike = mIkeProposal.getText().toString().trim();
|
mProfile.setIkeProposal(getString(mIkeProposal));
|
||||||
mProfile.setIkeProposal(ike.isEmpty() ? null : ike);
|
mProfile.setEspProposal(getString(mEspProposal));
|
||||||
String esp = mEspProposal.getText().toString().trim();
|
mProfile.setDnsServers(getString(mDnsServers));
|
||||||
mProfile.setEspProposal(esp.isEmpty() ? null : esp);
|
|
||||||
String dns = mDnsServers.getText().toString().trim();
|
|
||||||
mProfile.setDnsServers(dns.isEmpty() ? null : dns);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -846,6 +837,17 @@ public class VpnProfileDetailActivity extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the string value in the given text box or null if empty
|
||||||
|
*
|
||||||
|
* @param view text box
|
||||||
|
*/
|
||||||
|
private String getString(EditText view)
|
||||||
|
{
|
||||||
|
String value = view.getText().toString().trim();
|
||||||
|
return value.isEmpty() ? null : value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the integer value in the given text box or null if empty
|
* Get the integer value in the given text box or null if empty
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user