Add errors in assistant

This commit is contained in:
Margaux Clerc 2015-10-26 19:07:13 +01:00
parent 57f8e5dc68
commit b9f6cbd3b7
11 changed files with 337 additions and 150 deletions

View file

@ -22,14 +22,6 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content"/> android:layout_height="wrap_content"/>
<TextView
android:id="@+id/assistant_error"
android:textColor="@color/colorI"
android:paddingTop="10dp"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -38,86 +30,145 @@
android:gravity="center" android:gravity="center"
android:orientation="vertical"> android:orientation="vertical">
<TextView <LinearLayout
android:text="@string/username" android:orientation="vertical"
style="@style/font13"
android:textAllCaps="true"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"/> android:layout_height="wrap_content">
<EditText <TextView
android:id="@+id/assistant_username" android:id="@+id/username_label"
android:background="@drawable/resizable_textfield" android:text="@string/username"
android:textColor="@color/colorB" style="@style/font13"
android:textCursorDrawable="@null" android:textAllCaps="true"
android:inputType="textEmailAddress" android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/username"
android:background="@drawable/resizable_textfield"
android:textColor="@color/colorB"
android:inputType="text|textEmailAddress"
android:textCursorDrawable="@null"
android:layout_width="match_parent"
android:layout_height="40dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"/>
<TextView
android:id="@+id/username_error"
android:text="@string/error"
style="@style/font20"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="invisible"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="40dp" android:layout_height="wrap_content">
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"/>
<TextView <TextView
android:text="@string/password" android:id="@+id/password_label"
style="@style/font13" style="@style/font13"
android:textAllCaps="true" android:text="@string/password"
android:paddingTop="10dp" android:textAllCaps="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/password"
android:background="@drawable/resizable_textfield"
android:textColor="@color/colorB"
android:inputType="textPassword"
android:textCursorDrawable="@null"
android:layout_width="match_parent"
android:layout_height="40dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"/>
<TextView
android:id="@+id/password_error"
android:text="@string/error"
style="@style/font20"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="invisible"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"/> android:layout_height="wrap_content">
<TextView
android:id="@+id/confirm_password_label"
android:text="@string/confirm_password"
style="@style/font13"
android:textAllCaps="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText <EditText
android:id="@+id/assistant_password" android:id="@+id/confirm_password"
android:background="@drawable/resizable_textfield" android:background="@drawable/resizable_textfield"
android:textColor="@color/colorB" android:textColor="@color/colorB"
android:textCursorDrawable="@null" android:inputType="textPassword"
android:inputType="textPassword" android:textCursorDrawable="@null"
android:layout_width="match_parent"
android:layout_height="40dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"/>
<TextView
android:id="@+id/confirm_password_error"
android:text="@string/error"
style="@style/font20"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="invisible"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="40dp" android:layout_height="wrap_content">
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"/>
<TextView <TextView
android:text="@string/assistant_password_confirm" android:id="@+id/email_label"
style="@style/font13" android:text="@string/email"
android:textAllCaps="true" style="@style/font13"
android:paddingTop="10dp" android:textAllCaps="true"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"/> android:layout_height="wrap_content"/>
<EditText
android:id="@+id/email"
android:background="@drawable/resizable_textfield"
android:textColor="@color/colorB"
android:inputType="text|textEmailAddress"
android:textCursorDrawable="@null"
android:layout_width="match_parent"
android:layout_height="40dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"/>
<EditText <TextView
android:id="@+id/assistant_password_confirm" android:id="@+id/email_error"
android:background="@drawable/resizable_textfield" android:text="@string/error"
android:textColor="@color/colorB" style="@style/font20"
android:textCursorDrawable="@null" android:layout_width="match_parent"
android:inputType="textPassword" android:layout_height="wrap_content"
android:layout_width="match_parent" android:visibility="invisible"/>
android:layout_height="40dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"/>
<TextView </LinearLayout>
android:text="@string/email"
style="@style/font13"
android:textAllCaps="true"
android:paddingTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/assistant_email"
android:background="@drawable/resizable_textfield"
android:textColor="@color/colorB"
android:textCursorDrawable="@null"
android:inputType="text"
android:layout_width="match_parent"
android:layout_height="40dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"/>
<Button <Button
android:id="@+id/assistant_create" android:id="@+id/assistant_create"
@ -127,9 +178,9 @@
android:contentDescription="@string/content_description_validate" android:contentDescription="@string/content_description_validate"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="15dp" android:layout_margin="5dp"
android:layout_centerVertical="true"/> android:layout_centerVertical="true"/>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>

View file

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">
<TextView
android:id="@+id/customText"
style="@style/font14"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="20dp"/>
<EditText
android:id="@+id/password"
android:background="@drawable/resizable_textfield"
android:textColor="@color/colorB"
android:inputType="textPassword"
android:hint="@string/password"
android:textCursorDrawable="@null"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_margin="20dp"
android:singleLine="true"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal">
<Button
android:id="@+id/cancel"
android:text="@string/cancel"
android:background="@drawable/resizable_cancel_button"
style="@style/font8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:padding="10dp"/>
<Button
android:id="@+id/retry"
android:text="@string/retry"
android:background="@drawable/resizable_confirm_delete_button"
style="@style/font15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:padding="10dp"/>
</LinearLayout>
</LinearLayout>

View file

@ -1,7 +1,7 @@
package org.linphone.assistant; package org.linphone.assistant;
/* /*
SetupActivity.java AssistantActivity.java
Copyright (C) 2012 Belledonne Communications, Grenoble, France Copyright (C) 2015 Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
@ -21,28 +21,39 @@ import org.linphone.LinphoneActivity;
import org.linphone.LinphoneManager; import org.linphone.LinphoneManager;
import org.linphone.LinphonePreferences; import org.linphone.LinphonePreferences;
import org.linphone.LinphonePreferences.AccountBuilder; import org.linphone.LinphonePreferences.AccountBuilder;
import org.linphone.LinphoneUtils;
import org.linphone.R; import org.linphone.R;
import org.linphone.StatusFragment; import org.linphone.StatusFragment;
import org.linphone.core.LinphoneAddress; import org.linphone.core.LinphoneAddress;
import org.linphone.core.LinphoneAddress.TransportType; import org.linphone.core.LinphoneAddress.TransportType;
import org.linphone.core.LinphoneAuthInfo;
import org.linphone.core.LinphoneCore; import org.linphone.core.LinphoneCore;
import org.linphone.core.LinphoneCore.RegistrationState; import org.linphone.core.LinphoneCore.RegistrationState;
import org.linphone.core.LinphoneCoreException; import org.linphone.core.LinphoneCoreException;
import org.linphone.core.LinphoneCoreFactory; import org.linphone.core.LinphoneCoreFactory;
import org.linphone.core.LinphoneCoreListenerBase; import org.linphone.core.LinphoneCoreListenerBase;
import org.linphone.core.LinphoneProxyConfig; import org.linphone.core.LinphoneProxyConfig;
import org.linphone.mediastream.Log;
import android.app.Activity; import android.app.Activity;
import android.app.Dialog;
import android.app.Fragment; import android.app.Fragment;
import android.app.FragmentTransaction; import android.app.FragmentTransaction;
import android.content.Context; import android.content.Context;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
/** /**
* @author Sylvain Berfini * @author Sylvain Berfini
@ -70,7 +81,7 @@ public class AssistantActivity extends Activity implements OnClickListener {
initUI(); initUI();
firstFragment = getResources().getBoolean(R.bool.assistant_use_linphone_login_as_first_fragment) ? firstFragment = getResources().getBoolean(R.bool.assistant_use_linphone_login_as_first_fragment) ?
AssistantFragmentsEnum.LINPHONE_LOGIN : AssistantFragmentsEnum.MENU; AssistantFragmentsEnum.LINPHONE_LOGIN : AssistantFragmentsEnum.WELCOME;
if (findViewById(R.id.fragmentContainer) != null) { if (findViewById(R.id.fragmentContainer) != null) {
if (savedInstanceState == null) { if (savedInstanceState == null) {
display(firstFragment); display(firstFragment);
@ -87,10 +98,12 @@ public class AssistantActivity extends Activity implements OnClickListener {
if(address != null && address.asString().equals(cfg.getIdentity()) ) { if(address != null && address.asString().equals(cfg.getIdentity()) ) {
if (state == RegistrationState.RegistrationOk) { if (state == RegistrationState.RegistrationOk) {
if (LinphoneManager.getLc().getDefaultProxyConfig() != null) { if (LinphoneManager.getLc().getDefaultProxyConfig() != null) {
launchEchoCancellerCalibration(true); //launchEchoCancellerCalibration(true);
success();
} }
} else if (state == RegistrationState.RegistrationFailed) { } else if (state == RegistrationState.RegistrationFailed) {
Toast.makeText(AssistantActivity.this, getString(R.string.first_launch_bad_login_password), Toast.LENGTH_LONG).show(); //showDialog(cfg);
//Toast.makeText(AssistantActivity.this, getString(R.string.first_launch_bad_login_password), Toast.LENGTH_LONG).show();
} }
} }
} }
@ -174,15 +187,15 @@ public class AssistantActivity extends Activity implements OnClickListener {
setResult(Activity.RESULT_CANCELED); setResult(Activity.RESULT_CANCELED);
finish(); finish();
} }
} else if (currentFragment == AssistantFragmentsEnum.GENERIC_LOGIN } else if (currentFragment == AssistantFragmentsEnum.LOGIN
|| currentFragment == AssistantFragmentsEnum.LINPHONE_LOGIN || currentFragment == AssistantFragmentsEnum.LINPHONE_LOGIN
|| currentFragment == AssistantFragmentsEnum.CREATE_ACCOUNT || currentFragment == AssistantFragmentsEnum.CREATE_ACCOUNT
|| currentFragment == AssistantFragmentsEnum.REMOTE_PROVISIONING) { || currentFragment == AssistantFragmentsEnum.REMOTE_PROVISIONING) {
WelcomeFragment fragment = new WelcomeFragment(); WelcomeFragment fragment = new WelcomeFragment();
changeFragment(fragment); changeFragment(fragment);
currentFragment = AssistantFragmentsEnum.MENU; currentFragment = AssistantFragmentsEnum.WELCOME;
back.setVisibility(View.GONE); back.setVisibility(View.GONE);
} else if (currentFragment == AssistantFragmentsEnum.MENU) { } else if (currentFragment == AssistantFragmentsEnum.WELCOME) {
finish(); finish();
} }
} }
@ -198,7 +211,7 @@ public class AssistantActivity extends Activity implements OnClickListener {
back.setVisibility(View.VISIBLE); back.setVisibility(View.VISIBLE);
cancel.setEnabled(false); cancel.setEnabled(false);
} else { } else {
success();
} }
} }
@ -211,7 +224,7 @@ public class AssistantActivity extends Activity implements OnClickListener {
saveCreatedAccount(username, password, displayName, domain); saveCreatedAccount(username, password, displayName, domain);
if (LinphoneManager.getLc().getDefaultProxyConfig() != null) { if (LinphoneManager.getLc().getDefaultProxyConfig() != null) {
launchEchoCancellerCalibration(sendEcCalibrationResult); //launchEchoCancellerCalibration(sendEcCalibrationResult);
} }
} }
@ -233,12 +246,12 @@ public class AssistantActivity extends Activity implements OnClickListener {
private void display(AssistantFragmentsEnum fragment) { private void display(AssistantFragmentsEnum fragment) {
switch (fragment) { switch (fragment) {
case MENU: case WELCOME:
displayMenu(); displayMenu();
break; break;
case LINPHONE_LOGIN: case LINPHONE_LOGIN:
displayLoginLinphone(); displayLoginLinphone();
break; break;
default: default:
throw new IllegalStateException("Can't handle " + fragment); throw new IllegalStateException("Can't handle " + fragment);
} }
@ -247,14 +260,14 @@ public class AssistantActivity extends Activity implements OnClickListener {
public void displayMenu() { public void displayMenu() {
fragment = new WelcomeFragment(); fragment = new WelcomeFragment();
changeFragment(fragment); changeFragment(fragment);
currentFragment = AssistantFragmentsEnum.MENU; currentFragment = AssistantFragmentsEnum.WELCOME;
back.setVisibility(View.GONE); back.setVisibility(View.GONE);
} }
public void displayLoginGeneric() { public void displayLoginGeneric() {
fragment = new LoginFragment(); fragment = new LoginFragment();
changeFragment(fragment); changeFragment(fragment);
currentFragment = AssistantFragmentsEnum.GENERIC_LOGIN; currentFragment = AssistantFragmentsEnum.LOGIN;
back.setVisibility(View.VISIBLE); back.setVisibility(View.VISIBLE);
} }
@ -265,8 +278,6 @@ public class AssistantActivity extends Activity implements OnClickListener {
//LinphoneManager.getInstance().resetLinphoneCore(this); //LinphoneManager.getInstance().resetLinphoneCore(this);
//Log.w(LinphoneManager.getLc().getConfig().getString("proxy_default_values","reg_proxy","loool"));
changeFragment(fragment); changeFragment(fragment);
currentFragment = AssistantFragmentsEnum.LINPHONE_LOGIN; currentFragment = AssistantFragmentsEnum.LINPHONE_LOGIN;
back.setVisibility(View.VISIBLE); back.setVisibility(View.VISIBLE);
@ -285,6 +296,15 @@ public class AssistantActivity extends Activity implements OnClickListener {
currentFragment = AssistantFragmentsEnum.REMOTE_PROVISIONING; currentFragment = AssistantFragmentsEnum.REMOTE_PROVISIONING;
back.setVisibility(View.VISIBLE); back.setVisibility(View.VISIBLE);
} }
public void retryLogin(LinphoneProxyConfig proxy, String password){
LinphoneAuthInfo info = LinphoneManager.getLc().findAuthInfo(LinphoneUtils.getUsernameFromAddress(proxy.getIdentity()),proxy.getRealm(),proxy.getDomain());
if(info != null) {
info.setPassword(password);
LinphoneManager.getLc().addAuthInfo(info);
}
LinphoneManager.getLc().refreshRegisters();
}
public void saveCreatedAccount(String username, String password, String displayName, String domain) { public void saveCreatedAccount(String username, String password, String displayName, String domain) {
if (accountCreated) if (accountCreated)
@ -317,6 +337,7 @@ public class AssistantActivity extends Activity implements OnClickListener {
AccountBuilder builder = new AccountBuilder(LinphoneManager.getLc()) AccountBuilder builder = new AccountBuilder(LinphoneManager.getLc())
.setUsername(username) .setUsername(username)
.setDomain(domain) .setDomain(domain)
.setDisplayName(displayName)
.setPassword(password); .setPassword(password);
if (isMainAccountLinphoneDotOrg && useLinphoneDotOrgCustomPorts) { if (isMainAccountLinphoneDotOrg && useLinphoneDotOrgCustomPorts) {
@ -342,7 +363,7 @@ public class AssistantActivity extends Activity implements OnClickListener {
mPrefs.setStunServer(getString(R.string.default_stun)); mPrefs.setStunServer(getString(R.string.default_stun));
mPrefs.setIceEnabled(true); mPrefs.setIceEnabled(true);
} else { } else {
String forcedProxy = getResources().getString(R.string.setup_forced_proxy); String forcedProxy = "";
if (!TextUtils.isEmpty(forcedProxy)) { if (!TextUtils.isEmpty(forcedProxy)) {
builder.setProxy(forcedProxy) builder.setProxy(forcedProxy)
.setOutboundProxyEnabled(true) .setOutboundProxyEnabled(true)
@ -375,20 +396,60 @@ public class AssistantActivity extends Activity implements OnClickListener {
fragment.setArguments(extras); fragment.setArguments(extras);
changeFragment(fragment); changeFragment(fragment);
currentFragment = AssistantFragmentsEnum.CREATE_ACCOUNT_CONFIRM; currentFragment = AssistantFragmentsEnum.CREATE_ACCOUNT_ACTIVATION;
back.setVisibility(View.GONE); back.setVisibility(View.GONE);
} }
public void isAccountVerified(String username) { public void isAccountVerified(String username) {
Toast.makeText(this, getString(R.string.setup_account_validated), Toast.LENGTH_LONG).show(); Toast.makeText(this, getString(R.string.setup_account_validated), Toast.LENGTH_LONG).show();
LinphoneManager.getLcIfManagerNotDestroyedOrNull().refreshRegisters(); LinphoneManager.getLcIfManagerNotDestroyedOrNull().refreshRegisters();
launchEchoCancellerCalibration(true); //launchEchoCancellerCalibration(true);
} }
public void isEchoCalibrationFinished() { public void isEchoCalibrationFinished() {
mPrefs.setAccountEnabled(mPrefs.getAccountCount() - 1, true); mPrefs.setAccountEnabled(mPrefs.getAccountCount() - 1, true);
success(); success();
} }
public Dialog displayWrongPasswordDialog(){
Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
Drawable d = new ColorDrawable(getResources().getColor(R.color.colorC));
d.setAlpha(200);
dialog.setContentView(R.layout.input_dialog);
dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,WindowManager.LayoutParams.MATCH_PARENT);
dialog.getWindow().setBackgroundDrawable(d);
TextView customText = (TextView) dialog.findViewById(R.id.customText);
customText.setText(getString(R.string.error_bad_credentials));
return dialog;
}
public void showDialog(final LinphoneProxyConfig proxy){
final Dialog dialog = displayWrongPasswordDialog();
Button retry = (Button) dialog.findViewById(R.id.retry);
Button cancel = (Button) dialog.findViewById(R.id.cancel);
retry.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
String newPassword = ((EditText) dialog.findViewById(R.id.password)).getText().toString();
retryLogin(proxy, newPassword);
dialog.dismiss();
}
});
cancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
success();
dialog.dismiss();
}
});
dialog.show();
}
public void success() { public void success() {
mPrefs.firstLaunchSuccessful(); mPrefs.firstLaunchSuccessful();

View file

@ -1,7 +1,7 @@
package org.linphone.assistant; package org.linphone.assistant;
/* /*
SetupFragments.java AssistantFragmentsEnum.java
Copyright (C) 2012 Belledonne Communications, Grenoble, France Copyright (C) 2015 Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
@ -21,11 +21,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* @author Sylvain Berfini * @author Sylvain Berfini
*/ */
public enum AssistantFragmentsEnum { public enum AssistantFragmentsEnum {
MENU, WELCOME,
CREATE_ACCOUNT, CREATE_ACCOUNT,
CREATE_ACCOUNT_CONFIRM, CREATE_ACCOUNT_ACTIVATION,
LINPHONE_LOGIN, LINPHONE_LOGIN,
GENERIC_LOGIN, LOGIN,
REMOTE_PROVISIONING, REMOTE_PROVISIONING,
ECHO_CANCELLER_CALIBRATION; ECHO_CANCELLER_CALIBRATION;
} }

View file

@ -1,7 +1,7 @@
package org.linphone.assistant; package org.linphone.assistant;
/* /*
WizardConfirmFragment.java CreateAccountActivationFragment.java
Copyright (C) 2012 Belledonne Communications, Grenoble, France Copyright (C) 2015 Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License

View file

@ -1,7 +1,7 @@
package org.linphone.assistant; package org.linphone.assistant;
/* /*
WizardFragment.java CreateAccountFragment.java
Copyright (C) 2012 Belledonne Communications, Grenoble, France Copyright (C) 2015 Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
@ -56,14 +56,14 @@ import de.timroes.axmlrpc.XMLRPCServerException;
*/ */
public class CreateAccountFragment extends Fragment { public class CreateAccountFragment extends Fragment {
private Handler mHandler = new Handler(); private Handler mHandler = new Handler();
private EditText username, password, passwordConfirm, email; private EditText usernameEdit, passwordEdit, passwordConfirmEdit, emailEdit;
private TextView usernameError, passwordError, passwordConfirmError, emailError;
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 boolean confirmPasswordOk = false; private boolean confirmPasswordOk = false;
private Button createAccount; private Button createAccount;
private TextView errorMessage;
private char[] acceptedChars = new char[]{ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', private char[] acceptedChars = new char[]{ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '_', '-' }; '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '_', '-' };
@ -71,7 +71,7 @@ public class CreateAccountFragment extends Fragment {
private String inputFilterCharacters; private String inputFilterCharacters;
private String getUsername() { private String getUsername() {
String username = this.username.getText().toString(); String username = usernameEdit.getText().toString();
if (getResources().getBoolean(R.bool.allow_only_phone_numbers_in_wizard)) { if (getResources().getBoolean(R.bool.allow_only_phone_numbers_in_wizard)) {
LinphoneProxyConfig lpc = LinphoneManager.getLc().createProxyConfig(); LinphoneProxyConfig lpc = LinphoneManager.getLc().createProxyConfig();
username = lpc.normalizePhoneNumber(username); username = lpc.normalizePhoneNumber(username);
@ -82,9 +82,20 @@ public class CreateAccountFragment extends Fragment {
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.assistant_account_creation, container, false); View view = inflater.inflate(R.layout.assistant_account_creation, container, false);
username = (EditText) view.findViewById(R.id.assistant_username); usernameError = (TextView) view.findViewById(R.id.username_error);
addXMLRPCUsernameHandler(username, null); usernameEdit = (EditText) view.findViewById(R.id.username);
passwordError = (TextView) view.findViewById(R.id.password_error);
passwordEdit = (EditText) view.findViewById(R.id.password);
passwordConfirmError = (TextView) view.findViewById(R.id.confirm_password_error);
passwordConfirmEdit = (EditText) view.findViewById(R.id.confirm_password);
emailError = (TextView) view.findViewById(R.id.email_error);
emailEdit = (EditText) view.findViewById(R.id.email);
addXMLRPCUsernameHandler(usernameEdit, null);
inputFilterCharacters = new String(acceptedChars); inputFilterCharacters = new String(acceptedChars);
if (getResources().getBoolean(R.bool.allow_only_phone_numbers_in_wizard)) { if (getResources().getBoolean(R.bool.allow_only_phone_numbers_in_wizard)) {
@ -103,19 +114,12 @@ public class CreateAccountFragment extends Fragment {
return null; return null;
} }
}; };
username.setFilters(new InputFilter[] { filter }); usernameEdit.setFilters(new InputFilter[] { filter });
password = (EditText) view.findViewById(R.id.assistant_password); addXMLRPCPasswordHandler(passwordEdit, null);
passwordConfirm = (EditText) view.findViewById(R.id.assistant_password_confirm); addXMLRPCConfirmPasswordHandler(passwordEdit, passwordConfirmEdit, null);
addXMLRPCEmailHandler(emailEdit, null);
addXMLRPCPasswordHandler(password, null);
addXMLRPCConfirmPasswordHandler(password, passwordConfirm, null);
email = (EditText) view.findViewById(R.id.assistant_email);
addXMLRPCEmailHandler(email, null);
errorMessage = (TextView) view.findViewById(R.id.assistant_error);
createAccount = (Button) view.findViewById(R.id.assistant_create); createAccount = (Button) view.findViewById(R.id.assistant_create);
createAccount.setEnabled(false); createAccount.setEnabled(false);
createAccount.setOnClickListener(new OnClickListener() { createAccount.setOnClickListener(new OnClickListener() {
@ -123,7 +127,7 @@ public class CreateAccountFragment extends Fragment {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() { builder.setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
createAccount(getUsername(), password.getText().toString(), email.getText().toString(), false); createAccount(getUsername(), passwordEdit.getText().toString(), emailEdit.getText().toString(), false);
} }
}); });
builder.setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() { builder.setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() {
@ -142,7 +146,7 @@ public class CreateAccountFragment extends Fragment {
for (Account account: accounts) { for (Account account: accounts) {
if (isEmailCorrect(account.name)) { if (isEmailCorrect(account.name)) {
String possibleEmail = account.name; String possibleEmail = account.name;
email.setText(possibleEmail); emailEdit.setText(possibleEmail);
break; break;
} }
} }
@ -150,6 +154,18 @@ public class CreateAccountFragment extends Fragment {
return view; return view;
} }
private void displayError(Boolean isOk, TextView error, EditText editText, String errorText){
if(isOk){
error.setVisibility(View.INVISIBLE);
error.setText(errorText);
editText.setBackgroundResource(R.drawable.resizable_textfield);
} else {
error.setVisibility(View.VISIBLE);
error.setText(errorText);
editText.setBackgroundResource(R.drawable.resizable_textfield_error);
}
}
private boolean isUsernameCorrect(String username) { private boolean isUsernameCorrect(String username) {
if (getResources().getBoolean(R.bool.allow_only_phone_numbers_in_wizard)) { if (getResources().getBoolean(R.bool.allow_only_phone_numbers_in_wizard)) {
@ -160,11 +176,11 @@ public class CreateAccountFragment extends Fragment {
} }
} }
private void isUsernameRegistred(String username, final ImageView icon) { private void isUsernameRegistred(final String username, final ImageView icon) {
final Runnable runNotReachable = new Runnable() { final Runnable runNotReachable = new Runnable() {
public void run() { public void run() {
errorMessage.setText(R.string.wizard_server_unavailable);
usernameOk = false; usernameOk = false;
displayError(usernameOk, usernameError, usernameEdit, getResources().getString(R.string.wizard_server_unavailable));
createAccount.setEnabled(usernameOk && passwordOk && confirmPasswordOk && emailOk); createAccount.setEnabled(usernameOk && passwordOk && confirmPasswordOk && emailOk);
} }
}; };
@ -175,16 +191,16 @@ public class CreateAccountFragment extends Fragment {
XMLRPCCallback listener = new XMLRPCCallback() { XMLRPCCallback listener = new XMLRPCCallback() {
Runnable runNotOk = new Runnable() { Runnable runNotOk = new Runnable() {
public void run() { public void run() {
errorMessage.setText(R.string.wizard_username_unavailable);
usernameOk = false; usernameOk = false;
displayError(usernameOk, usernameError, usernameEdit, getResources().getString(R.string.wizard_username_unavailable));
createAccount.setEnabled(usernameOk && passwordOk && confirmPasswordOk && emailOk); createAccount.setEnabled(usernameOk && passwordOk && confirmPasswordOk && emailOk);
} }
}; };
Runnable runOk = new Runnable() { Runnable runOk = new Runnable() {
public void run() { public void run() {
errorMessage.setText("");
usernameOk = true; usernameOk = true;
displayError(usernameOk, usernameError, usernameEdit, "");
createAccount.setEnabled(usernameOk && passwordOk && confirmPasswordOk && emailOk); createAccount.setEnabled(usernameOk && passwordOk && confirmPasswordOk && emailOk);
} }
}; };
@ -227,7 +243,7 @@ public class CreateAccountFragment extends Fragment {
private void createAccount(final String username, final String password, String email, boolean suscribe) { private void createAccount(final String username, final String password, String email, boolean suscribe) {
final Runnable runNotReachable = new Runnable() { final Runnable runNotReachable = new Runnable() {
public void run() { public void run() {
errorMessage.setText(R.string.wizard_server_unavailable); //TODO errorMessage.setText(R.string.wizard_server_unavailable);
} }
}; };
@ -239,7 +255,7 @@ public class CreateAccountFragment extends Fragment {
XMLRPCCallback listener = new XMLRPCCallback() { XMLRPCCallback listener = new XMLRPCCallback() {
Runnable runNotOk = new Runnable() { Runnable runNotOk = new Runnable() {
public void run() { public void run() {
errorMessage.setText(R.string.wizard_failed); //TODO errorMessage.setText(R.string.wizard_failed);
} }
}; };
@ -295,7 +311,7 @@ public class CreateAccountFragment extends Fragment {
} }
isUsernameRegistred(username, icon); isUsernameRegistred(username, icon);
} else { } else {
errorMessage.setText(R.string.wizard_username_incorrect); displayError(usernameOk, usernameError, usernameEdit, getResources().getString(R.string.wizard_username_incorrect));
} }
} }
}); });
@ -316,10 +332,10 @@ public class CreateAccountFragment extends Fragment {
emailOk = false; emailOk = false;
if (isEmailCorrect(field.getText().toString())) { if (isEmailCorrect(field.getText().toString())) {
emailOk = true; emailOk = true;
errorMessage.setText(""); displayError(emailOk, emailError, emailEdit, "");
} }
else { else {
errorMessage.setText(R.string.wizard_email_incorrect); displayError(emailOk, emailError, emailEdit, getString(R.string.wizard_email_incorrect));
} }
createAccount.setEnabled(usernameOk && passwordOk && confirmPasswordOk && emailOk); createAccount.setEnabled(usernameOk && passwordOk && confirmPasswordOk && emailOk);
} }
@ -341,10 +357,10 @@ public class CreateAccountFragment extends Fragment {
passwordOk = false; passwordOk = false;
if (isPasswordCorrect(field1.getText().toString())) { if (isPasswordCorrect(field1.getText().toString())) {
passwordOk = true; passwordOk = true;
errorMessage.setText(""); displayError(passwordOk, passwordError, passwordEdit, "");
} }
else { else {
errorMessage.setText(R.string.wizard_password_incorrect); displayError(passwordOk, passwordError, passwordEdit, getString(R.string.wizard_password_incorrect));
} }
createAccount.setEnabled(usernameOk && passwordOk && confirmPasswordOk && emailOk); createAccount.setEnabled(usernameOk && passwordOk && confirmPasswordOk && emailOk);
} }
@ -370,14 +386,14 @@ public class CreateAccountFragment extends Fragment {
confirmPasswordOk = true; confirmPasswordOk = true;
if (!isPasswordCorrect(field1.getText().toString())) { if (!isPasswordCorrect(field1.getText().toString())) {
errorMessage.setText(R.string.wizard_password_incorrect); displayError(passwordOk, passwordError, passwordEdit, getString(R.string.wizard_password_incorrect));
} }
else { else {
errorMessage.setText(""); displayError(confirmPasswordOk, passwordConfirmError, passwordConfirmEdit, "");
} }
} }
else { else {
errorMessage.setText(R.string.wizard_passwords_unmatched); displayError(confirmPasswordOk, passwordConfirmError, passwordConfirmEdit, getString(R.string.wizard_passwords_unmatched));
} }
createAccount.setEnabled(usernameOk && passwordOk && confirmPasswordOk && emailOk); createAccount.setEnabled(usernameOk && passwordOk && confirmPasswordOk && emailOk);
} }

View file

@ -2,7 +2,7 @@ package org.linphone.assistant;
/* /*
EchoCancellerCalibrationFragment.java EchoCancellerCalibrationFragment.java
Copyright (C) 2012 Belledonne Communications, Grenoble, France Copyright (C) 2015 Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License

View file

@ -1,7 +1,7 @@
package org.linphone.assistant; package org.linphone.assistant;
/* /*
LinphoneLoginFragment.java LinphoneLoginFragment.java
Copyright (C) 2012 Belledonne Communications, Grenoble, France Copyright (C) 2015 Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License

View file

@ -1,7 +1,7 @@
package org.linphone.assistant; package org.linphone.assistant;
/* /*
GenericLoginFragment.java LoginFragment.java
Copyright (C) 2012 Belledonne Communications, Grenoble, France Copyright (C) 2015 Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License

View file

@ -1,7 +1,7 @@
package org.linphone.assistant; package org.linphone.assistant;
/* /*
RemoteProvisioningFragment.java RemoteProvisioningFragment.java
Copyright (C) 2014 Belledonne Communications, Grenoble, France Copyright (C) 2015 Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License

View file

@ -1,7 +1,7 @@
package org.linphone.assistant; package org.linphone.assistant;
/* /*
MenuFragment.java WelcomeFragment.java
Copyright (C) 2012 Belledonne Communications, Grenoble, France Copyright (C) 2015 Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License