Fix exit issue + wizard account creation working

This commit is contained in:
Sylvain Berfini 2012-06-21 17:34:35 +02:00
parent 1ae90b9629
commit d10ad9a98b
11 changed files with 504 additions and 501 deletions

View file

@ -4,5 +4,146 @@
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:paddingTop="40dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/setup_title_assistant"/>
<TextView
android:paddingTop="10dp"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/setup_error"
android:textColor="#ffff0000"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="40dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:gravity="center"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/setup_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/setup_username_hint"
android:inputType="textEmailAddress"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"
android:textColor="@android:color/black" />
<ImageView
android:id="@+id/setup_username_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dp"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:src="@drawable/wizard_ok"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/setup_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/setup_password_hint"
android:inputType="textPassword"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"
android:textColor="@android:color/black" />
<EditText
android:id="@+id/setup_password_confirm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/setup_password"
android:hint="@string/setup_password_confirm_hint"
android:inputType="textPassword"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"
android:textColor="@android:color/black" />
<ImageView
android:id="@+id/setup_password_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/wizard_ok"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/setup_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/setup_email_hint"
android:inputType="textEmailAddress"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"
android:textColor="@android:color/black" />
<ImageView
android:id="@+id/setup_email_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dp"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:src="@drawable/wizard_ok"/>
</RelativeLayout>
<RelativeLayout
android:paddingTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/setup_create"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/button"
android:layout_centerInParent="true" />
<TextView
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/setup_create"
android:textColor="@android:color/black"/>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:paddingRight="10dp" />
</LinearLayout>
</LinearLayout>

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/setup_validate_account"
android:textColor="@android:color/black" />
</LinearLayout>

View file

@ -1,115 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<EditText
android:id="@+id/wizardUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="textPersonName"
android:hint="@string/wizard_username_hint" >
<requestFocus />
</EditText>
<ImageView
android:id="@+id/wizardUsernameOk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/wizard_notok" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:layout_weight="1">
<EditText
android:id="@+id/wizardPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:hint="@string/wizard_password_hint" />
<EditText
android:id="@+id/wizardPasswordConfirm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:hint="@string/wizard_password_confirm_hint" />
</LinearLayout>
<ImageView
android:id="@+id/wizardPasswordOk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/wizard_notok" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<EditText
android:id="@+id/wizardEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="textEmailAddress"
android:hint="@string/wizard_email_hint" />
<ImageView
android:id="@+id/wizardEmailOk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/wizard_notok" />
</LinearLayout>
<TextView
android:id="@+id/wizardErrorMessage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#FF0000"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center">
<Button
android:id="@+id/wizardCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/wizard_cancel"/>
<Button
android:id="@+id/wizardCreateAccount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/wizard_create_account"/>
</LinearLayout>
</LinearLayout>

View file

@ -1,33 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:id="@+id/wizardConfirm"
android:text="@string/wizard_need_activation"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center">
<Button
android:id="@+id/wizardCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/wizard_cancel"/>
<Button
android:id="@+id/wizardCheckAccount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/wizard_verify_account"/>
</LinearLayout>
</LinearLayout>

View file

@ -3,6 +3,7 @@
<string name="default_domain">sip.linphone.org</string>
<string name="wizard_url">https://www.linphone.org/wizard.php</string>
<!-- Interface settings -->
<bool name="hide_camera_settings">false</bool>

View file

@ -313,4 +313,8 @@
<string name="setup_apply">Apply</string>
<string name="setup_username_hint">username</string>
<string name="setup_password_hint">password</string>
<string name="setup_password_confirm_hint">confirm password</string>
<string name="setup_email_hint">email</string>
<string name="setup_create">Create Account</string>
<string name="setup_validate_account">Waiting for account activation</string>
</resources>

View file

@ -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,6 +90,7 @@ public class StatusFragment extends Fragment {
mHandler.post(new Runnable() {
@Override
public void run() {
try {
if (state == RegistrationState.RegistrationOk) {
statusLed.setImageResource(R.drawable.connected_led);
statusText.setText(getString(R.string.status_connected));
@ -91,6 +98,9 @@ public class StatusFragment extends Fragment {
statusLed.setImageResource(R.drawable.not_connected_led);
statusText.setText(getString(R.string.status_not_connected));
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

View file

@ -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) {
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);
}
}

View file

@ -24,6 +24,7 @@ public enum SetupFragments {
WELCOME,
MENU,
WIZARD,
WIZARD_CONFIRM,
LINPHONE_LOGIN,
GENERIC_LOGIN;
}

View file

@ -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;
}
}

View file

@ -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);
}
}