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:layout_height="match_parent"
android:orientation="vertical" > 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> </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="default_domain">sip.linphone.org</string>
<string name="wizard_url">https://www.linphone.org/wizard.php</string>
<!-- Interface settings --> <!-- Interface settings -->
<bool name="hide_camera_settings">false</bool> <bool name="hide_camera_settings">false</bool>

View file

@ -313,4 +313,8 @@
<string name="setup_apply">Apply</string> <string name="setup_apply">Apply</string>
<string name="setup_username_hint">username</string> <string name="setup_username_hint">username</string>
<string name="setup_password_hint">password</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> </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) { public void registrationStateChanged(final RegistrationState state) {
if (!isAttached) if (!isAttached)
return; return;
@ -84,12 +90,16 @@ public class StatusFragment extends Fragment {
mHandler.post(new Runnable() { mHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
if (state == RegistrationState.RegistrationOk) { try {
statusLed.setImageResource(R.drawable.connected_led); if (state == RegistrationState.RegistrationOk) {
statusText.setText(getString(R.string.status_connected)); statusLed.setImageResource(R.drawable.connected_led);
} else { statusText.setText(getString(R.string.status_connected));
statusLed.setImageResource(R.drawable.not_connected_led); } else {
statusText.setText(getString(R.string.status_not_connected)); 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.preference.PreferenceManager;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
@ -80,8 +79,7 @@ public class SetupActivity extends FragmentActivity implements OnClickListener {
private void changeFragment(Fragment newFragment) { private void changeFragment(Fragment newFragment) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.addToBackStack("Add to back stack"); // transaction.addToBackStack("");
getSupportFragmentManager().popBackStack("Add to back stack", FragmentManager.POP_BACK_STACK_INCLUSIVE);
transaction.replace(R.id.fragmentContainer, newFragment); transaction.replace(R.id.fragmentContainer, newFragment);
transaction.commitAllowingStateLoss(); transaction.commitAllowingStateLoss();
@ -94,12 +92,16 @@ public class SetupActivity extends FragmentActivity implements OnClickListener {
if (id == R.id.setup_cancel) { if (id == R.id.setup_cancel) {
finish(); finish();
} else if (id == R.id.setup_next) { } else if (id == R.id.setup_next) {
MenuFragment fragment = new MenuFragment(); if (currentFragment == SetupFragments.WELCOME) {
changeFragment(fragment); MenuFragment fragment = new MenuFragment();
currentFragment = SetupFragments.MENU; changeFragment(fragment);
currentFragment = SetupFragments.MENU;
next.setVisibility(View.GONE);
back.setVisibility(View.VISIBLE); next.setVisibility(View.GONE);
back.setVisibility(View.VISIBLE);
} else if (currentFragment == SetupFragments.WIZARD_CONFIRM) {
finish();
}
} else if (id == R.id.setup_back) { } else if (id == R.id.setup_back) {
if (currentFragment == SetupFragments.MENU) { if (currentFragment == SetupFragments.MENU) {
WelcomeFragment fragment = new WelcomeFragment(); WelcomeFragment fragment = new WelcomeFragment();
@ -120,11 +122,7 @@ public class SetupActivity extends FragmentActivity implements OnClickListener {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), 0); imm.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), 0);
writePreference(R.string.pref_username_key, username); saveCreatedAccount(username, password, domain);
writePreference(R.string.pref_passwd_key, password);
writePreference(R.string.pref_domain_key, domain);
writePreference(R.string.pref_extra_accounts, 1);
LinphoneManager.getInstance().initializePayloads(); LinphoneManager.getInstance().initializePayloads();
try { try {
@ -144,6 +142,10 @@ public class SetupActivity extends FragmentActivity implements OnClickListener {
mPref.edit().putString(getString(key), value).commit(); 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) { private void writePreference(int key, int value) {
mPref.edit().putInt(getString(key), value).commit(); mPref.edit().putInt(getString(key), value).commit();
} }
@ -169,4 +171,29 @@ public class SetupActivity extends FragmentActivity implements OnClickListener {
changeFragment(fragment); changeFragment(fragment);
currentFragment = SetupFragments.WIZARD; 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, WELCOME,
MENU, MENU,
WIZARD, WIZARD,
WIZARD_CONFIRM,
LINPHONE_LOGIN, LINPHONE_LOGIN,
GENERIC_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 java.net.URL;
import org.linphone.PreferencesActivity;
import org.linphone.R; import org.linphone.R;
import android.app.AlertDialog;
import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
@ -31,8 +28,8 @@ import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
@ -45,12 +42,12 @@ import de.timroes.axmlrpc.XMLRPCServerException;
*/ */
public class WizardFragment extends Fragment { public class WizardFragment extends Fragment {
private Handler mHandler = new Handler(); private Handler mHandler = new Handler();
private EditText username, password, passwordConfirm, email;
private boolean usernameOk = false; private boolean usernameOk = false;
private boolean passwordOk = false; private boolean passwordOk = false;
private boolean emailOk = false; private boolean emailOk = false;
private AlertDialog wizardDialog; private ImageView createAccount;
private Button createAccount;
private TextView errorMessage; private TextView errorMessage;
@Override @Override
@ -58,334 +55,236 @@ public class WizardFragment extends Fragment {
Bundle savedInstanceState) { Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.setup_wizard, container, false); 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; return view;
} }
// protected Dialog onCreateDialog (int id) { private boolean isUsernameCorrect(String username) {
// if (id == WIZARD_ID) { return username.matches("^[a-zA-Z]+[a-zA-Z0-9.\\-_]{2,}$");
// AlertDialog.Builder builder = new AlertDialog.Builder(PreferencesActivity.this); }
// LayoutInflater inflater = LayoutInflater.from(PreferencesActivity.this);
// View v = inflater.inflate(R.layout.wizard, null); private void isUsernameRegistred(String username, final ImageView icon) {
// builder.setView(v); final Runnable runNotReachable = new Runnable() {
// public void run() {
// final EditText username = (EditText) v.findViewById(R.id.wizardUsername); errorMessage.setText(R.string.wizard_server_unavailable);
// ImageView usernameOkIV = (ImageView) v.findViewById(R.id.wizardUsernameOk); usernameOk = false;
// addXMLRPCUsernameHandler(username, usernameOkIV); icon.setImageResource(R.drawable.wizard_notok);
// createAccount.setEnabled(usernameOk && passwordOk && emailOk);
// 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); try {
// XMLRPCClient client = new XMLRPCClient(new URL(getString(R.string.wizard_url)));
// final EditText email = (EditText) v.findViewById(R.id.wizardEmail);
// ImageView emailOkIV = (ImageView) v.findViewById(R.id.wizardEmailOk); XMLRPCCallback listener = new XMLRPCCallback() {
// addXMLRPCEmailHandler(email, emailOkIV); Runnable runNotOk = new Runnable() {
// public void run() {
// errorMessage = (TextView) v.findViewById(R.id.wizardErrorMessage); errorMessage.setText(R.string.wizard_username_unavailable);
// usernameOk = false;
// Button cancel = (Button) v.findViewById(R.id.wizardCancel); icon.setImageResource(R.drawable.wizard_notok);
// cancel.setOnClickListener(new OnClickListener() { createAccount.setEnabled(usernameOk && passwordOk && emailOk);
// public void onClick(View v) { }
// wizardDialog.dismiss(); };
// }
// }); Runnable runOk = new Runnable() {
// public void run() {
// createAccount = (Button) v.findViewById(R.id.wizardCreateAccount); errorMessage.setText("");
// createAccount.setOnClickListener(new OnClickListener() { icon.setImageResource(R.drawable.wizard_ok);
// public void onClick(View v) { usernameOk = true;
// createAccount(username.getText().toString(), password.getText().toString(), email.getText().toString(), false); createAccount.setEnabled(usernameOk && passwordOk && emailOk);
// } }
// }); };
// createAccount.setEnabled(false);
// public void onResponse(long id, Object result) {
// builder.setTitle(getString(R.string.wizard_title)); int answer = (Integer) result;
// wizardDialog = builder.create(); if (answer != 0) {
// return wizardDialog; mHandler.post(runNotOk);
// } }
// else if (id == CONFIRM_ID) { else {
// AlertDialog.Builder builder = new AlertDialog.Builder(PreferencesActivity.this); mHandler.post(runOk);
// builder.setTitle(R.string.wizard_confirmation); }
// }
// final LayoutInflater inflater = LayoutInflater.from(PreferencesActivity.this);
// View v = inflater.inflate(R.layout.wizard_confirm, null); public void onError(long id, XMLRPCException error) {
// builder.setView(v); mHandler.post(runNotReachable);
// }
// Button check = (Button) v.findViewById(R.id.wizardCheckAccount);
// check.setOnClickListener(new OnClickListener() { public void onServerError(long id, XMLRPCServerException error) {
// public void onClick(View v) { mHandler.post(runNotReachable);
// wizardDialog.dismiss(); }
// if (isAccountVerified(username)) { };
// SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
// SharedPreferences.Editor editor = prefs.edit(); client.callAsync(listener, "check_account", username);
// editor.putBoolean(getString(R.string.pref_activated_key) + (nbAccounts - 1), true); }
// editor.commit(); catch(Exception ex) {
// } else { mHandler.post(runNotReachable);
// showDialog(CONFIRM_ID); }
// } }
// }
// }); private boolean isEmailCorrect(String email) {
// return email.matches("^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\\.-][a-z0-9]+)*)+\\.[a-z]{2,}$");
// Button cancel = (Button) v.findViewById(R.id.wizardCancel); }
// cancel.setOnClickListener(new OnClickListener() {
// public void onClick(View v) { private boolean isPasswordCorrect(String password) {
// wizardDialog.dismiss(); return password.length() >= 6;
// } }
// });
// private void createAccount(final String username, final String password, String email, boolean suscribe) {
// wizardDialog = builder.create(); final Runnable runNotReachable = new Runnable() {
// return wizardDialog; public void run() {
// } errorMessage.setText(R.string.wizard_server_unavailable);
// return null; }
//} };
//
// private boolean isUsernameCorrect(String username) { try {
// return username.matches("^[a-zA-Z]+[a-zA-Z0-9.\\-_]{2,}$"); XMLRPCClient client = new XMLRPCClient(new URL(getString(R.string.wizard_url)));
// }
// XMLRPCCallback listener = new XMLRPCCallback() {
// static boolean isAccountVerified(String username) { Runnable runNotOk = new Runnable() {
// try { public void run() {
// XMLRPCClient client = new XMLRPCClient(new URL("https://www.linphone.org/wizard.php")); errorMessage.setText(R.string.wizard_failed);
// Object resultO = client.call("check_account_validated", "sip:" + username + "@sip.linphone.org"); }
// Integer result = Integer.parseInt(resultO.toString()); };
//
// return result == 1; Runnable runOk = new Runnable() {
// } catch(Exception ex) { public void run() {
// SetupActivity.instance().saveCreatedAccount(username, password, getString(R.string.default_domain));
// } SetupActivity.instance().displayWizardConfirm();
// return false; }
// } };
//
// private void isUsernameRegistred(String username, final ImageView icon) { public void onResponse(long id, Object result) {
// final Runnable runNotReachable = new Runnable() { int answer = (Integer) result;
// public void run() { if (answer != 0) {
// errorMessage.setText(R.string.wizard_server_unavailable); mHandler.post(runNotOk);
// usernameOk = false; } else {
// icon.setImageResource(R.drawable.wizard_notok); mHandler.post(runOk);
// createAccount.setEnabled(usernameOk && passwordOk && emailOk); }
// } }
// };
// public void onError(long id, XMLRPCException error) {
// try { mHandler.post(runNotReachable);
// XMLRPCClient client = new XMLRPCClient(new URL("https://www.linphone.org/wizard.php")); }
//
// XMLRPCCallback listener = new XMLRPCCallback() { public void onServerError(long id, XMLRPCServerException error) {
// Runnable runNotOk = new Runnable() { mHandler.post(runNotReachable);
// public void run() { }
// errorMessage.setText(R.string.wizard_username_unavailable); };
// usernameOk = false;
// icon.setImageResource(R.drawable.wizard_notok); client.callAsync(listener, "create_account", username, password, email, suscribe ? 1 : 0);
// createAccount.setEnabled(usernameOk && passwordOk && emailOk); }
// } catch(Exception ex) {
// }; mHandler.post(runNotReachable);
// }
// Runnable runOk = new Runnable() { }
// public void run() {
// errorMessage.setText(""); private void addXMLRPCUsernameHandler(final EditText field, final ImageView icon) {
// icon.setImageResource(R.drawable.wizard_ok); field.addTextChangedListener(new TextWatcher() {
// usernameOk = true; public void afterTextChanged(Editable arg0) {
// createAccount.setEnabled(usernameOk && passwordOk && emailOk);
// } }
// };
// public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
// public void onResponse(long id, Object result) {
// int answer = (Integer) result; }
// if (answer != 0) {
// mHandler.post(runNotOk); public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3)
// } {
// else { usernameOk = false;
// mHandler.post(runOk); if (isUsernameCorrect(field.getText().toString()))
// } {
// } isUsernameRegistred(field.getText().toString(), icon);
// }
// public void onError(long id, XMLRPCException error) { else {
// mHandler.post(runNotReachable); errorMessage.setText(R.string.wizard_username_incorrect);
// } icon.setImageResource(R.drawable.wizard_notok);
// }
// public void onServerError(long id, XMLRPCServerException error) { }
// mHandler.post(runNotReachable); });
// } }
// };
// private void addXMLRPCEmailHandler(final EditText field, final ImageView icon) {
// client.callAsync(listener, "check_account", username); field.addTextChangedListener(new TextWatcher() {
// } public void afterTextChanged(Editable arg0) {
// catch(Exception ex) {
// mHandler.post(runNotReachable); }
// }
// } public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
//
// private boolean isEmailCorrect(String email) { }
// return email.matches("^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\\.-][a-z0-9]+)*)+\\.[a-z]{2,}$");
// } public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3)
// {
// private boolean isPasswordCorrect(String password) { emailOk = false;
// return password.length() >= 6; if (isEmailCorrect(field.getText().toString())) {
// } icon.setImageResource(R.drawable.wizard_ok);
// emailOk = true;
// private void createAccount(final String username, final String password, String email, boolean suscribe) { errorMessage.setText("");
// final Runnable runNotReachable = new Runnable() { }
// public void run() { else {
// errorMessage.setText(R.string.wizard_server_unavailable); errorMessage.setText(R.string.wizard_email_incorrect);
// } 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() { private void addXMLRPCPasswordHandler(final EditText field1, final EditText field2, final ImageView icon) {
// public void run() { TextWatcher passwordListener = new TextWatcher() {
// errorMessage.setText(R.string.wizard_failed); public void afterTextChanged(Editable arg0) {
// }
// }; }
//
// Runnable runOk = new Runnable() { public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
// public void run() {
// addExtraAccountPreferencesButton(accounts, nbAccounts, true); }
// PreferencesActivity.this.username = username;
// fillLinphoneAccount(nbAccounts, username, password, true); public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3)
// nbAccounts++; {
// createDynamicAccountsPreferences(); passwordOk = false;
// wizardDialog.dismiss(); if (isPasswordCorrect(field1.getText().toString()) && field1.getText().toString().equals(field2.getText().toString())) {
// passwordOk = true;
// showDialog(CONFIRM_ID); icon.setImageResource(R.drawable.wizard_ok);
// } errorMessage.setText("");
// }; }
// else {
// public void onResponse(long id, Object result) { if (isPasswordCorrect(field1.getText().toString())) {
// int answer = (Integer) result; errorMessage.setText(R.string.wizard_passwords_unmatched);
// if (answer != 0) { }
// mHandler.post(runNotOk); else {
// } else { errorMessage.setText(R.string.wizard_password_incorrect);
// mHandler.post(runOk); }
// } icon.setImageResource(R.drawable.wizard_notok);
// } }
// createAccount.setEnabled(usernameOk && passwordOk && emailOk);
// public void onError(long id, XMLRPCException error) { }
// mHandler.post(runNotReachable); };
// }
// field1.addTextChangedListener(passwordListener);
// public void onServerError(long id, XMLRPCServerException error) { field2.addTextChangedListener(passwordListener);
// 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);
// }
// }
// }
// }
} }