diff --git a/res/layout/setup_wizard.xml b/res/layout/setup_wizard.xml
index 8b3027f3d..f0fd0fba1 100644
--- a/res/layout/setup_wizard.xml
+++ b/res/layout/setup_wizard.xml
@@ -4,5 +4,146 @@
android:layout_height="match_parent"
android:orientation="vertical" >
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/setup_wizard_confirm.xml b/res/layout/setup_wizard_confirm.xml
new file mode 100644
index 000000000..e6e7b43c1
--- /dev/null
+++ b/res/layout/setup_wizard_confirm.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/wizard.xml b/res/layout/wizard.xml
deleted file mode 100644
index e73d10124..000000000
--- a/res/layout/wizard.xml
+++ /dev/null
@@ -1,115 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/res/layout/wizard_confirm.xml b/res/layout/wizard_confirm.xml
deleted file mode 100644
index c3020b989..000000000
--- a/res/layout/wizard_confirm.xml
+++ /dev/null
@@ -1,33 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/res/values/non_localizable_custom.xml b/res/values/non_localizable_custom.xml
index 338f18d10..9efce7351 100644
--- a/res/values/non_localizable_custom.xml
+++ b/res/values/non_localizable_custom.xml
@@ -3,6 +3,7 @@
sip.linphone.org
+ https://www.linphone.org/wizard.php
false
diff --git a/res/values/strings.xml b/res/values/strings.xml
index bc43eb8ca..4e6a551fb 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -313,4 +313,8 @@
Apply
username
password
+confirm password
+email
+Create Account
+Waiting for account activation
diff --git a/src/org/linphone/StatusFragment.java b/src/org/linphone/StatusFragment.java
index 1ed8ce8c8..ff88c3e30 100644
--- a/src/org/linphone/StatusFragment.java
+++ b/src/org/linphone/StatusFragment.java
@@ -77,6 +77,12 @@ public class StatusFragment extends Fragment {
}
}
+ @Override
+ public void onDetach() {
+ super.onDetach();
+ isAttached = false;
+ }
+
public void registrationStateChanged(final RegistrationState state) {
if (!isAttached)
return;
@@ -84,12 +90,16 @@ public class StatusFragment extends Fragment {
mHandler.post(new Runnable() {
@Override
public void run() {
- if (state == RegistrationState.RegistrationOk) {
- statusLed.setImageResource(R.drawable.connected_led);
- statusText.setText(getString(R.string.status_connected));
- } else {
- statusLed.setImageResource(R.drawable.not_connected_led);
- statusText.setText(getString(R.string.status_not_connected));
+ try {
+ if (state == RegistrationState.RegistrationOk) {
+ statusLed.setImageResource(R.drawable.connected_led);
+ statusText.setText(getString(R.string.status_connected));
+ } else {
+ statusLed.setImageResource(R.drawable.not_connected_led);
+ statusText.setText(getString(R.string.status_not_connected));
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
}
}
});
diff --git a/src/org/linphone/setup/SetupActivity.java b/src/org/linphone/setup/SetupActivity.java
index c63e4b2c5..679f464aa 100644
--- a/src/org/linphone/setup/SetupActivity.java
+++ b/src/org/linphone/setup/SetupActivity.java
@@ -27,7 +27,6 @@ import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
-import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.View.OnClickListener;
@@ -80,8 +79,7 @@ public class SetupActivity extends FragmentActivity implements OnClickListener {
private void changeFragment(Fragment newFragment) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
- transaction.addToBackStack("Add to back stack");
- getSupportFragmentManager().popBackStack("Add to back stack", FragmentManager.POP_BACK_STACK_INCLUSIVE);
+// transaction.addToBackStack("");
transaction.replace(R.id.fragmentContainer, newFragment);
transaction.commitAllowingStateLoss();
@@ -94,12 +92,16 @@ public class SetupActivity extends FragmentActivity implements OnClickListener {
if (id == R.id.setup_cancel) {
finish();
} else if (id == R.id.setup_next) {
- MenuFragment fragment = new MenuFragment();
- changeFragment(fragment);
- currentFragment = SetupFragments.MENU;
-
- next.setVisibility(View.GONE);
- back.setVisibility(View.VISIBLE);
+ if (currentFragment == SetupFragments.WELCOME) {
+ MenuFragment fragment = new MenuFragment();
+ changeFragment(fragment);
+ currentFragment = SetupFragments.MENU;
+
+ next.setVisibility(View.GONE);
+ back.setVisibility(View.VISIBLE);
+ } else if (currentFragment == SetupFragments.WIZARD_CONFIRM) {
+ finish();
+ }
} else if (id == R.id.setup_back) {
if (currentFragment == SetupFragments.MENU) {
WelcomeFragment fragment = new WelcomeFragment();
@@ -120,11 +122,7 @@ public class SetupActivity extends FragmentActivity implements OnClickListener {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), 0);
- writePreference(R.string.pref_username_key, username);
- writePreference(R.string.pref_passwd_key, password);
- writePreference(R.string.pref_domain_key, domain);
- writePreference(R.string.pref_extra_accounts, 1);
-
+ saveCreatedAccount(username, password, domain);
LinphoneManager.getInstance().initializePayloads();
try {
@@ -144,6 +142,10 @@ public class SetupActivity extends FragmentActivity implements OnClickListener {
mPref.edit().putString(getString(key), value).commit();
}
+ private void writePreference(String key, String value) {
+ mPref.edit().putString(key, value).commit();
+ }
+
private void writePreference(int key, int value) {
mPref.edit().putInt(getString(key), value).commit();
}
@@ -169,4 +171,29 @@ public class SetupActivity extends FragmentActivity implements OnClickListener {
changeFragment(fragment);
currentFragment = SetupFragments.WIZARD;
}
+
+ public void saveCreatedAccount(String username, String password, String domain) {
+ int newAccountId = mPref.getInt(getString(R.string.pref_extra_accounts), 0);
+ writePreference(R.string.pref_extra_accounts, newAccountId+1);
+
+ if (newAccountId == 0) {
+ writePreference(R.string.pref_username_key, username);
+ writePreference(R.string.pref_passwd_key, password);
+ writePreference(R.string.pref_domain_key, domain);
+ } else {
+ writePreference(getString(R.string.pref_username_key) + newAccountId, username);
+ writePreference(getString(R.string.pref_passwd_key) + newAccountId, password);
+ writePreference(getString(R.string.pref_domain_key) + newAccountId, domain);
+ }
+ }
+
+ public void displayWizardConfirm() {
+ WizardConfirmFragment fragment = new WizardConfirmFragment();
+ changeFragment(fragment);
+ currentFragment = SetupFragments.WIZARD_CONFIRM;
+
+ next.setVisibility(View.VISIBLE);
+ next.setEnabled(false);
+ back.setVisibility(View.GONE);
+ }
}
diff --git a/src/org/linphone/setup/SetupFragments.java b/src/org/linphone/setup/SetupFragments.java
index 0b19f3559..966ab5863 100644
--- a/src/org/linphone/setup/SetupFragments.java
+++ b/src/org/linphone/setup/SetupFragments.java
@@ -24,6 +24,7 @@ public enum SetupFragments {
WELCOME,
MENU,
WIZARD,
+ WIZARD_CONFIRM,
LINPHONE_LOGIN,
GENERIC_LOGIN;
}
diff --git a/src/org/linphone/setup/WizardConfirmFragment.java b/src/org/linphone/setup/WizardConfirmFragment.java
new file mode 100644
index 000000000..bad6ea4e9
--- /dev/null
+++ b/src/org/linphone/setup/WizardConfirmFragment.java
@@ -0,0 +1,55 @@
+package org.linphone.setup;
+/*
+WizardConfirmFragment.java
+Copyright (C) 2012 Belledonne Communications, Grenoble, France
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+import java.net.URL;
+
+import org.linphone.R;
+
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import de.timroes.axmlrpc.XMLRPCClient;
+/**
+ * @author Sylvain Berfini
+ */
+public class WizardConfirmFragment extends Fragment {
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.setup_wizard_confirm, container, false);
+
+ return view;
+ }
+
+ private boolean isAccountVerified(String username) {
+ try {
+ XMLRPCClient client = new XMLRPCClient(new URL(getString(R.string.wizard_url)));
+ Object resultO = client.call("check_account_validated", "sip:" + username + "@" + getString(R.string.default_domain));
+ Integer result = Integer.parseInt(resultO.toString());
+
+ return result == 1;
+ } catch(Exception ex) {
+
+ }
+ return false;
+ }
+}
diff --git a/src/org/linphone/setup/WizardFragment.java b/src/org/linphone/setup/WizardFragment.java
index e02c2a22c..edb45e752 100644
--- a/src/org/linphone/setup/WizardFragment.java
+++ b/src/org/linphone/setup/WizardFragment.java
@@ -19,11 +19,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
import java.net.URL;
-import org.linphone.PreferencesActivity;
import org.linphone.R;
-import android.app.AlertDialog;
-import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
@@ -31,8 +28,8 @@ import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
+import android.view.View.OnClickListener;
import android.view.ViewGroup;
-import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
@@ -45,12 +42,12 @@ import de.timroes.axmlrpc.XMLRPCServerException;
*/
public class WizardFragment extends Fragment {
private Handler mHandler = new Handler();
+ private EditText username, password, passwordConfirm, email;
private boolean usernameOk = false;
private boolean passwordOk = false;
private boolean emailOk = false;
- private AlertDialog wizardDialog;
- private Button createAccount;
+ private ImageView createAccount;
private TextView errorMessage;
@Override
@@ -58,334 +55,236 @@ public class WizardFragment extends Fragment {
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.setup_wizard, container, false);
+ username = (EditText) view.findViewById(R.id.setup_username);
+ ImageView usernameOkIV = (ImageView) view.findViewById(R.id.setup_username_ok);
+ addXMLRPCUsernameHandler(username, usernameOkIV);
+
+ password = (EditText) view.findViewById(R.id.setup_password);
+ passwordConfirm = (EditText) view.findViewById(R.id.setup_password_confirm);
+
+ ImageView passwordOkIV = (ImageView) view.findViewById(R.id.setup_password_ok);
+ addXMLRPCPasswordHandler(password, passwordConfirm, passwordOkIV);
+
+ email = (EditText) view.findViewById(R.id.setup_email);
+ ImageView emailOkIV = (ImageView) view.findViewById(R.id.setup_email_ok);
+ addXMLRPCEmailHandler(email, emailOkIV);
+
+ errorMessage = (TextView) view.findViewById(R.id.setup_error);
+
+ createAccount = (ImageView) view.findViewById(R.id.setup_create);
+ createAccount.setEnabled(false);
+ createAccount.setOnClickListener(new OnClickListener() {
+ public void onClick(View v) {
+ createAccount(username.getText().toString(), password.getText().toString(), email.getText().toString(), false);
+ }
+ });
+
return view;
}
-// protected Dialog onCreateDialog (int id) {
-// if (id == WIZARD_ID) {
-// AlertDialog.Builder builder = new AlertDialog.Builder(PreferencesActivity.this);
-// LayoutInflater inflater = LayoutInflater.from(PreferencesActivity.this);
-// View v = inflater.inflate(R.layout.wizard, null);
-// builder.setView(v);
-//
-// final EditText username = (EditText) v.findViewById(R.id.wizardUsername);
-// ImageView usernameOkIV = (ImageView) v.findViewById(R.id.wizardUsernameOk);
-// addXMLRPCUsernameHandler(username, usernameOkIV);
-//
-// final EditText password = (EditText) v.findViewById(R.id.wizardPassword);
-// EditText passwordConfirm = (EditText) v.findViewById(R.id.wizardPasswordConfirm);
-// ImageView passwordOkIV = (ImageView) v.findViewById(R.id.wizardPasswordOk);
-// addXMLRPCPasswordHandler(password, passwordConfirm, passwordOkIV);
-//
-// final EditText email = (EditText) v.findViewById(R.id.wizardEmail);
-// ImageView emailOkIV = (ImageView) v.findViewById(R.id.wizardEmailOk);
-// addXMLRPCEmailHandler(email, emailOkIV);
-//
-// errorMessage = (TextView) v.findViewById(R.id.wizardErrorMessage);
-//
-// Button cancel = (Button) v.findViewById(R.id.wizardCancel);
-// cancel.setOnClickListener(new OnClickListener() {
-// public void onClick(View v) {
-// wizardDialog.dismiss();
-// }
-// });
-//
-// createAccount = (Button) v.findViewById(R.id.wizardCreateAccount);
-// createAccount.setOnClickListener(new OnClickListener() {
-// public void onClick(View v) {
-// createAccount(username.getText().toString(), password.getText().toString(), email.getText().toString(), false);
-// }
-// });
-// createAccount.setEnabled(false);
-//
-// builder.setTitle(getString(R.string.wizard_title));
-// wizardDialog = builder.create();
-// return wizardDialog;
-// }
-// else if (id == CONFIRM_ID) {
-// AlertDialog.Builder builder = new AlertDialog.Builder(PreferencesActivity.this);
-// builder.setTitle(R.string.wizard_confirmation);
-//
-// final LayoutInflater inflater = LayoutInflater.from(PreferencesActivity.this);
-// View v = inflater.inflate(R.layout.wizard_confirm, null);
-// builder.setView(v);
-//
-// Button check = (Button) v.findViewById(R.id.wizardCheckAccount);
-// check.setOnClickListener(new OnClickListener() {
-// public void onClick(View v) {
-// wizardDialog.dismiss();
-// if (isAccountVerified(username)) {
-// SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
-// SharedPreferences.Editor editor = prefs.edit();
-// editor.putBoolean(getString(R.string.pref_activated_key) + (nbAccounts - 1), true);
-// editor.commit();
-// } else {
-// showDialog(CONFIRM_ID);
-// }
-// }
-// });
-//
-// Button cancel = (Button) v.findViewById(R.id.wizardCancel);
-// cancel.setOnClickListener(new OnClickListener() {
-// public void onClick(View v) {
-// wizardDialog.dismiss();
-// }
-// });
-//
-// wizardDialog = builder.create();
-// return wizardDialog;
-// }
-// return null;
-//}
-//
-// private boolean isUsernameCorrect(String username) {
-// return username.matches("^[a-zA-Z]+[a-zA-Z0-9.\\-_]{2,}$");
-// }
-//
-// static boolean isAccountVerified(String username) {
-// try {
-// XMLRPCClient client = new XMLRPCClient(new URL("https://www.linphone.org/wizard.php"));
-// Object resultO = client.call("check_account_validated", "sip:" + username + "@sip.linphone.org");
-// Integer result = Integer.parseInt(resultO.toString());
-//
-// return result == 1;
-// } catch(Exception ex) {
-//
-// }
-// return false;
-// }
-//
-// private void isUsernameRegistred(String username, final ImageView icon) {
-// final Runnable runNotReachable = new Runnable() {
-// public void run() {
-// errorMessage.setText(R.string.wizard_server_unavailable);
-// usernameOk = false;
-// icon.setImageResource(R.drawable.wizard_notok);
-// createAccount.setEnabled(usernameOk && passwordOk && emailOk);
-// }
-// };
-//
-// try {
-// XMLRPCClient client = new XMLRPCClient(new URL("https://www.linphone.org/wizard.php"));
-//
-// XMLRPCCallback listener = new XMLRPCCallback() {
-// Runnable runNotOk = new Runnable() {
-// public void run() {
-// errorMessage.setText(R.string.wizard_username_unavailable);
-// usernameOk = false;
-// icon.setImageResource(R.drawable.wizard_notok);
-// createAccount.setEnabled(usernameOk && passwordOk && emailOk);
-// }
-// };
-//
-// Runnable runOk = new Runnable() {
-// public void run() {
-// errorMessage.setText("");
-// icon.setImageResource(R.drawable.wizard_ok);
-// usernameOk = true;
-// createAccount.setEnabled(usernameOk && passwordOk && emailOk);
-// }
-// };
-//
-// public void onResponse(long id, Object result) {
-// int answer = (Integer) result;
-// if (answer != 0) {
-// mHandler.post(runNotOk);
-// }
-// else {
-// mHandler.post(runOk);
-// }
-// }
-//
-// public void onError(long id, XMLRPCException error) {
-// mHandler.post(runNotReachable);
-// }
-//
-// public void onServerError(long id, XMLRPCServerException error) {
-// mHandler.post(runNotReachable);
-// }
-// };
-//
-// client.callAsync(listener, "check_account", username);
-// }
-// catch(Exception ex) {
-// mHandler.post(runNotReachable);
-// }
-// }
-//
-// private boolean isEmailCorrect(String email) {
-// return email.matches("^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\\.-][a-z0-9]+)*)+\\.[a-z]{2,}$");
-// }
-//
-// private boolean isPasswordCorrect(String password) {
-// return password.length() >= 6;
-// }
-//
-// private void createAccount(final String username, final String password, String email, boolean suscribe) {
-// final Runnable runNotReachable = new Runnable() {
-// public void run() {
-// errorMessage.setText(R.string.wizard_server_unavailable);
-// }
-// };
-//
-// try {
-// XMLRPCClient client = new XMLRPCClient(new URL("https://www.linphone.org/wizard.php"));
-//
-// XMLRPCCallback listener = new XMLRPCCallback() {
-// Runnable runNotOk = new Runnable() {
-// public void run() {
-// errorMessage.setText(R.string.wizard_failed);
-// }
-// };
-//
-// Runnable runOk = new Runnable() {
-// public void run() {
-// addExtraAccountPreferencesButton(accounts, nbAccounts, true);
-// PreferencesActivity.this.username = username;
-// fillLinphoneAccount(nbAccounts, username, password, true);
-// nbAccounts++;
-// createDynamicAccountsPreferences();
-// wizardDialog.dismiss();
-//
-// showDialog(CONFIRM_ID);
-// }
-// };
-//
-// public void onResponse(long id, Object result) {
-// int answer = (Integer) result;
-// if (answer != 0) {
-// mHandler.post(runNotOk);
-// } else {
-// mHandler.post(runOk);
-// }
-// }
-//
-// public void onError(long id, XMLRPCException error) {
-// mHandler.post(runNotReachable);
-// }
-//
-// public void onServerError(long id, XMLRPCServerException error) {
-// mHandler.post(runNotReachable);
-// }
-// };
-//
-// client.callAsync(listener, "create_account", username, password, email, suscribe ? 1 : 0);
-// }
-// catch(Exception ex) {
-// mHandler.post(runNotReachable);
-// }
-// }
-//
-// private void addXMLRPCUsernameHandler(final EditText field, final ImageView icon) {
-// field.addTextChangedListener(new TextWatcher() {
-// public void afterTextChanged(Editable arg0) {
-//
-// }
-//
-// public void beforeTextChanged(CharSequence arg0, int arg1,
-// int arg2, int arg3) {
-//
-// }
-//
-// public void onTextChanged(CharSequence arg0, int arg1, int arg2,
-// int arg3)
-// {
-// usernameOk = false;
-// if (isUsernameCorrect(field.getText().toString()))
-// {
-// isUsernameRegistred(field.getText().toString(), icon);
-// }
-// else {
-// errorMessage.setText(R.string.wizard_username_incorrect);
-// icon.setImageResource(R.drawable.wizard_notok);
-// }
-// }
-// });
-// }
-//
-// private void addXMLRPCEmailHandler(final EditText field, final ImageView icon) {
-// field.addTextChangedListener(new TextWatcher() {
-// public void afterTextChanged(Editable arg0) {
-//
-// }
-//
-// public void beforeTextChanged(CharSequence arg0, int arg1,
-// int arg2, int arg3) {
-//
-// }
-//
-// public void onTextChanged(CharSequence arg0, int arg1, int arg2,
-// int arg3)
-// {
-// emailOk = false;
-// if (isEmailCorrect(field.getText().toString())) {
-// icon.setImageResource(R.drawable.wizard_ok);
-// emailOk = true;
-// errorMessage.setText("");
-// }
-// else {
-// errorMessage.setText(R.string.wizard_email_incorrect);
-// icon.setImageResource(R.drawable.wizard_notok);
-// }
-// createAccount.setEnabled(usernameOk && passwordOk && emailOk);
-// }
-// });
-// }
-//
-// private void addXMLRPCPasswordHandler(final EditText field1, final EditText field2, final ImageView icon) {
-// TextWatcher passwordListener = new TextWatcher() {
-// public void afterTextChanged(Editable arg0) {
-//
-// }
-//
-// public void beforeTextChanged(CharSequence arg0, int arg1,
-// int arg2, int arg3) {
-//
-// }
-//
-// public void onTextChanged(CharSequence arg0, int arg1, int arg2,
-// int arg3)
-// {
-// passwordOk = false;
-// if (isPasswordCorrect(field1.getText().toString()) && field1.getText().toString().equals(field2.getText().toString())) {
-// passwordOk = true;
-// icon.setImageResource(R.drawable.wizard_ok);
-// errorMessage.setText("");
-// }
-// else {
-// if (isPasswordCorrect(field1.getText().toString())) {
-// errorMessage.setText(R.string.wizard_passwords_unmatched);
-// }
-// else {
-// errorMessage.setText(R.string.wizard_password_incorrect);
-// }
-// icon.setImageResource(R.drawable.wizard_notok);
-// }
-// createAccount.setEnabled(usernameOk && passwordOk && emailOk);
-// }
-// };
-//
-// field1.addTextChangedListener(passwordListener);
-// field2.addTextChangedListener(passwordListener);
-// }
-//
-// private void verifiyAccountsActivated() {
-// SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
-// for (int i = 0; i < nbAccounts; i++) {
-// String key = (i == 0 ? "" : Integer.toString(i));
-// boolean createdByWizard = prefs.getBoolean(getString(R.string.pref_wizard_key) + key, false);
-// boolean activated = prefs.getBoolean(getString(R.string.pref_activated_key) + key, true);
-// if (createdByWizard && !activated) {
-// //Check if account has been activated since
-// activated = isAccountVerified(prefs.getString(getString(R.string.pref_username_key) + key, ""));
-// if (activated) {
-// SharedPreferences.Editor editor = prefs.edit();
-// editor.putBoolean(getString(R.string.pref_activated_key) + key, true);
-// editor.commit();
-// } else {
-// showDialog(CONFIRM_ID);
-// }
-// }
-// }
-// }
+ private boolean isUsernameCorrect(String username) {
+ return username.matches("^[a-zA-Z]+[a-zA-Z0-9.\\-_]{2,}$");
+ }
+
+ private void isUsernameRegistred(String username, final ImageView icon) {
+ final Runnable runNotReachable = new Runnable() {
+ public void run() {
+ errorMessage.setText(R.string.wizard_server_unavailable);
+ usernameOk = false;
+ icon.setImageResource(R.drawable.wizard_notok);
+ createAccount.setEnabled(usernameOk && passwordOk && emailOk);
+ }
+ };
+
+ try {
+ XMLRPCClient client = new XMLRPCClient(new URL(getString(R.string.wizard_url)));
+
+ XMLRPCCallback listener = new XMLRPCCallback() {
+ Runnable runNotOk = new Runnable() {
+ public void run() {
+ errorMessage.setText(R.string.wizard_username_unavailable);
+ usernameOk = false;
+ icon.setImageResource(R.drawable.wizard_notok);
+ createAccount.setEnabled(usernameOk && passwordOk && emailOk);
+ }
+ };
+
+ Runnable runOk = new Runnable() {
+ public void run() {
+ errorMessage.setText("");
+ icon.setImageResource(R.drawable.wizard_ok);
+ usernameOk = true;
+ createAccount.setEnabled(usernameOk && passwordOk && emailOk);
+ }
+ };
+
+ public void onResponse(long id, Object result) {
+ int answer = (Integer) result;
+ if (answer != 0) {
+ mHandler.post(runNotOk);
+ }
+ else {
+ mHandler.post(runOk);
+ }
+ }
+
+ public void onError(long id, XMLRPCException error) {
+ mHandler.post(runNotReachable);
+ }
+
+ public void onServerError(long id, XMLRPCServerException error) {
+ mHandler.post(runNotReachable);
+ }
+ };
+
+ client.callAsync(listener, "check_account", username);
+ }
+ catch(Exception ex) {
+ mHandler.post(runNotReachable);
+ }
+ }
+
+ private boolean isEmailCorrect(String email) {
+ return email.matches("^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\\.-][a-z0-9]+)*)+\\.[a-z]{2,}$");
+ }
+
+ private boolean isPasswordCorrect(String password) {
+ return password.length() >= 6;
+ }
+
+ private void createAccount(final String username, final String password, String email, boolean suscribe) {
+ final Runnable runNotReachable = new Runnable() {
+ public void run() {
+ errorMessage.setText(R.string.wizard_server_unavailable);
+ }
+ };
+
+ try {
+ XMLRPCClient client = new XMLRPCClient(new URL(getString(R.string.wizard_url)));
+
+ XMLRPCCallback listener = new XMLRPCCallback() {
+ Runnable runNotOk = new Runnable() {
+ public void run() {
+ errorMessage.setText(R.string.wizard_failed);
+ }
+ };
+
+ Runnable runOk = new Runnable() {
+ public void run() {
+ SetupActivity.instance().saveCreatedAccount(username, password, getString(R.string.default_domain));
+ SetupActivity.instance().displayWizardConfirm();
+ }
+ };
+
+ public void onResponse(long id, Object result) {
+ int answer = (Integer) result;
+ if (answer != 0) {
+ mHandler.post(runNotOk);
+ } else {
+ mHandler.post(runOk);
+ }
+ }
+
+ public void onError(long id, XMLRPCException error) {
+ mHandler.post(runNotReachable);
+ }
+
+ public void onServerError(long id, XMLRPCServerException error) {
+ mHandler.post(runNotReachable);
+ }
+ };
+
+ client.callAsync(listener, "create_account", username, password, email, suscribe ? 1 : 0);
+ }
+ catch(Exception ex) {
+ mHandler.post(runNotReachable);
+ }
+ }
+
+ private void addXMLRPCUsernameHandler(final EditText field, final ImageView icon) {
+ field.addTextChangedListener(new TextWatcher() {
+ public void afterTextChanged(Editable arg0) {
+
+ }
+
+ public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
+
+ }
+
+ public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3)
+ {
+ usernameOk = false;
+ if (isUsernameCorrect(field.getText().toString()))
+ {
+ isUsernameRegistred(field.getText().toString(), icon);
+ }
+ else {
+ errorMessage.setText(R.string.wizard_username_incorrect);
+ icon.setImageResource(R.drawable.wizard_notok);
+ }
+ }
+ });
+ }
+
+ private void addXMLRPCEmailHandler(final EditText field, final ImageView icon) {
+ field.addTextChangedListener(new TextWatcher() {
+ public void afterTextChanged(Editable arg0) {
+
+ }
+
+ public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
+
+ }
+
+ public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3)
+ {
+ emailOk = false;
+ if (isEmailCorrect(field.getText().toString())) {
+ icon.setImageResource(R.drawable.wizard_ok);
+ emailOk = true;
+ errorMessage.setText("");
+ }
+ else {
+ errorMessage.setText(R.string.wizard_email_incorrect);
+ icon.setImageResource(R.drawable.wizard_notok);
+ }
+ createAccount.setEnabled(usernameOk && passwordOk && emailOk);
+ }
+ });
+ }
+
+ private void addXMLRPCPasswordHandler(final EditText field1, final EditText field2, final ImageView icon) {
+ TextWatcher passwordListener = new TextWatcher() {
+ public void afterTextChanged(Editable arg0) {
+
+ }
+
+ public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
+
+ }
+
+ public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3)
+ {
+ passwordOk = false;
+ if (isPasswordCorrect(field1.getText().toString()) && field1.getText().toString().equals(field2.getText().toString())) {
+ passwordOk = true;
+ icon.setImageResource(R.drawable.wizard_ok);
+ errorMessage.setText("");
+ }
+ else {
+ if (isPasswordCorrect(field1.getText().toString())) {
+ errorMessage.setText(R.string.wizard_passwords_unmatched);
+ }
+ else {
+ errorMessage.setText(R.string.wizard_password_incorrect);
+ }
+ icon.setImageResource(R.drawable.wizard_notok);
+ }
+ createAccount.setEnabled(usernameOk && passwordOk && emailOk);
+ }
+ };
+
+ field1.addTextChangedListener(passwordListener);
+ field2.addTextChangedListener(passwordListener);
+ }
}