--- a/app/src/main/java/com/beem/project/beem/ui/wizard/AccountConfigureFragment.java Mon Jun 15 17:00:36 2015 +0200
+++ b/app/src/main/java/com/beem/project/beem/ui/wizard/AccountConfigureFragment.java Mon Jun 15 19:33:26 2015 +0200
@@ -186,7 +186,7 @@
if (v == mNextButton) {
if (useSystemAccount) {
onDeviceAccountSelected(settings.getString(BeemApplication.ACCOUNT_USERNAME_KEY, ""),
- settings.getString(BeemApplication.ACCOUNT_SYSTEM_TYPE_KEY, ""));
+ settings.getString(BeemApplication.ACCOUNT_SYSTEM_TYPE_KEY, ""));
} else {
String jid = mAccountJID.getText().toString();
jid = StringUtils.parseBareAddress(jid);
@@ -204,7 +204,8 @@
} else if (v == mSelectAccountButton) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
Intent i = AccountManager.newChooseAccountIntent(null, null,
- new String[] {GOOGLE_ACCOUNT_TYPE}, true, null, null, null, null);
+ new String[] {GOOGLE_ACCOUNT_TYPE},
+ true, null, null, null, null);
startActivityForResult(i, SELECT_ACCOUNT_CODE);
}
}
@@ -335,6 +336,22 @@
}
/**
+ * Parse an integer.
+ * Return the default value if a NumberFormatException occurs
+ *
+ * @param value the value to parse
+ * @param defaultValue value to returns on parsing error
+ * @return the value at a int or defaultValue
+ */
+ private int parseInt(String value, int defaultValue) {
+ try {
+ return Integer.parseInt(value);
+ } catch (NumberFormatException e) {
+ return defaultValue;
+ }
+ }
+
+ /**
* Text watcher to test the existence of a password.
*/
private class PasswordTextWatcher implements TextWatcher {
@@ -442,8 +459,8 @@
String serviceName = StringUtils.parseServer(jid);
Connection connection = prepareConnection(jid, server, port);
if (settings.getBoolean(BeemApplication.FULL_JID_LOGIN_KEY, false)
- || "gmail.com".equals(serviceName)
- || "googlemail.com".equals(serviceName)) {
+ || "gmail.com".equals(serviceName)
+ || "googlemail.com".equals(serviceName)) {
login = jid;
}
try {
@@ -476,7 +493,8 @@
String phost = settings.getString(BeemApplication.PROXY_SERVER_KEY, "");
String puser = settings.getString(BeemApplication.PROXY_USERNAME_KEY, "");
String ppass = settings.getString(BeemApplication.PROXY_PASSWORD_KEY, "");
- int pport = Integer.parseInt(settings.getString(BeemApplication.PROXY_PORT_KEY, "1080"));
+ String spport = settings.getString(BeemApplication.PROXY_PORT_KEY, "1080");
+ int pport = parseInt(spport, 1080);
ProxyInfo.ProxyType type = ProxyType.valueOf(stype);
proxyinfo = new ProxyInfo(type, phost, pport, puser, ppass);
}
--- a/app/src/main/java/com/beem/project/beem/ui/wizard/CreateAccountFragment.java Mon Jun 15 17:00:36 2015 +0200
+++ b/app/src/main/java/com/beem/project/beem/ui/wizard/CreateAccountFragment.java Mon Jun 15 19:33:26 2015 +0200
@@ -121,7 +121,7 @@
createButton.setOnClickListener(this);
serverEdit = (AutoCompleteTextView) v.findViewById(R.id.xmpp_server);
ArrayAdapter<CharSequence> completeAdapter = ArrayAdapter.createFromResource(
- getActivity(), R.array.xmpp_server_list, R.layout.simple_combobox_item);
+ getActivity(), R.array.xmpp_server_list, R.layout.simple_combobox_item);
serverEdit.setAdapter(completeAdapter);
serverEdit.addTextChangedListener(mTextWatcher);
@@ -240,6 +240,22 @@
}
/**
+ * Parse an integer.
+ * Return the default value if a NumberFormatException occurs
+ *
+ * @param value the value to parse
+ * @param defaultValue value to returns on parsing error
+ * @return the value at a int or defaultValue
+ */
+ private int parseInt(String value, int defaultValue) {
+ try {
+ return Integer.parseInt(value);
+ } catch (NumberFormatException e) {
+ return defaultValue;
+ }
+ }
+
+ /**
* AsyncTask use to create an XMPP account on a server.
*/
private class CreateAccountTask extends AsyncTask<String, Void, Boolean> {
@@ -317,7 +333,8 @@
String phost = settings.getString(BeemApplication.PROXY_SERVER_KEY, "");
String puser = settings.getString(BeemApplication.PROXY_USERNAME_KEY, "");
String ppass = settings.getString(BeemApplication.PROXY_PASSWORD_KEY, "");
- int pport = Integer.parseInt(settings.getString(BeemApplication.PROXY_PORT_KEY, "1080"));
+ String spport = settings.getString(BeemApplication.PROXY_PORT_KEY, "1080");
+ int pport = parseInt(spport, 1080);
ProxyInfo.ProxyType type = ProxyType.valueOf(stype);
proxyinfo = new ProxyInfo(type, phost, pport, puser, ppass);
}
@@ -381,9 +398,9 @@
@Override
public void afterTextChanged(Editable s) {
boolean enable = !(TextUtils.isEmpty(username.getText())
- || TextUtils.isEmpty(serverEdit.getText())
- || TextUtils.isEmpty(password.getText())
- || TextUtils.isEmpty(confirmPassword.getText()));
+ || TextUtils.isEmpty(serverEdit.getText())
+ || TextUtils.isEmpty(password.getText())
+ || TextUtils.isEmpty(confirmPassword.getText()));
createButton.setEnabled(enable);
}