Wizard for Android

This commit is contained in:
Sylvain Berfini 2012-02-02 10:34:29 +01:00
parent 1e9bef5a9d
commit 0d575d5557
11 changed files with 467 additions and 4 deletions

View file

@ -7,5 +7,6 @@
<classpathentry kind="src" path="submodules/linphone/coreapi/help/java"/> <classpathentry kind="src" path="submodules/linphone/coreapi/help/java"/>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="lib" path="libs/aXMLRPC.jar"/>
<classpathentry kind="output" path="bin/classes"/> <classpathentry kind="output" path="bin/classes"/>
</classpath> </classpath>

BIN
libs/aXMLRPC.jar Normal file

Binary file not shown.

BIN
res/.DS_Store vendored Normal file

Binary file not shown.

BIN
res/drawable/.DS_Store vendored Normal file

Binary file not shown.

BIN
res/drawable/notok.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB

BIN
res/drawable/ok.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

115
res/layout/wizard.xml Normal file
View file

@ -0,0 +1,115 @@
<?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/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/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/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

@ -227,4 +227,20 @@
<string name="pref_extra_accounts">pref_nb_accounts_extra</string> <string name="pref_extra_accounts">pref_nb_accounts_extra</string>
<string name="pref_default_account">pref_default_account</string> <string name="pref_default_account">pref_default_account</string>
<string name="pref_sipaccounts">SIP Accounts</string> <string name="pref_sipaccounts">SIP Accounts</string>
<string name="wizard_username_hint">Username</string>
<string name="wizard_password_hint">Password</string>
<string name="wizard_password_confirm_hint">Confirmation</string>
<string name="wizard_email_hint">Email</string>
<string name="wizard_title">Account Wizard</string>
<string name="wizard_create_account">Create Account</string>
<string name="wizard_cancel">Cancel</string>
<string name="wizard_failed">An error occurred, try again later.</string>
<string name="wizard_server_unavailable">Server unreachable, verify your internet connection.</string>
<string name="wizard_username_unavailable">This username is already in use.</string>
<string name="wizard_username_incorrect">Your username is not valid.</string>
<string name="wizard_email_incorrect">Your email is not valid.</string>
<string name="wizard_password_incorrect">Your password is not valid (6 characters min).</string>
<string name="wizard_passwords_unmatched">Passwords entered are different.</string>
<string name="wizard_need_activation">You need to activate your account with the link that was send to your email.</string>
</resources> </resources>

View file

@ -21,6 +21,7 @@
</PreferenceCategory> </PreferenceCategory>
<Preference android:title="Add Account"></Preference> <Preference android:title="Add Account"></Preference>
<Preference android:title="@string/wizard_title"></Preference>
<PreferenceCategory android:key="@string/pref_tunnel_key" android:title="@string/pref_tunnel"> <PreferenceCategory android:key="@string/pref_tunnel_key" android:title="@string/pref_tunnel">
<EditTextPreference android:title="@string/pref_tunnel_host" <EditTextPreference android:title="@string/pref_tunnel_host"

View file

@ -19,7 +19,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
package org.linphone; package org.linphone;
import static org.linphone.R.string.ec_calibrating; import static org.linphone.R.string.ec_calibrating;
import static org.linphone.R.string.pref_codec_amr_key; import static org.linphone.R.string.pref_codec_amr_key;
import static org.linphone.R.string.pref_codec_amrwb_key; import static org.linphone.R.string.pref_codec_amrwb_key;
@ -31,6 +30,7 @@ import static org.linphone.R.string.pref_echo_limiter_key;
import static org.linphone.R.string.pref_media_encryption_key; import static org.linphone.R.string.pref_media_encryption_key;
import static org.linphone.R.string.pref_video_enable_key; import static org.linphone.R.string.pref_video_enable_key;
import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -46,6 +46,8 @@ import org.linphone.mediastream.Version;
import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration; import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration;
import org.linphone.mediastream.video.capture.hwconf.Hacks; import org.linphone.mediastream.video.capture.hwconf.Hacks;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
@ -58,6 +60,20 @@ import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity; import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory; import android.preference.PreferenceCategory;
import android.preference.PreferenceScreen; import android.preference.PreferenceScreen;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import de.timroes.axmlrpc.XMLRPCCallback;
import de.timroes.axmlrpc.XMLRPCClient;
import de.timroes.axmlrpc.XMLRPCException;
import de.timroes.axmlrpc.XMLRPCServerException;
public class LinphonePreferencesActivity extends PreferenceActivity implements EcCalibrationListener { public class LinphonePreferencesActivity extends PreferenceActivity implements EcCalibrationListener {
private Handler mHandler = new Handler(); private Handler mHandler = new Handler();
@ -66,7 +82,18 @@ public class LinphonePreferencesActivity extends PreferenceActivity implements E
private CheckBoxPreference ecPref; private CheckBoxPreference ecPref;
private ListPreference mencPref; private ListPreference mencPref;
private int nbAccounts = 1; private int nbAccounts = 1;
// Wizard fields
private boolean usernameOk = false;
private boolean passwordOk = false;
private boolean emailOk = false;
private AlertDialog wizardDialog;
private Button createAccount;
private TextView errorMessage;
private PreferenceCategory accounts;
private static final int ADD_SIP_ACCOUNT = 0x666; private static final int ADD_SIP_ACCOUNT = 0x666;
private static final int WIZARD_ID = 0x667;
private SharedPreferences prefs() { private SharedPreferences prefs() {
return getPreferenceManager().getSharedPreferences(); return getPreferenceManager().getSharedPreferences();
@ -93,7 +120,7 @@ public class LinphonePreferencesActivity extends PreferenceActivity implements E
PreferenceScreen root = getPreferenceScreen(); PreferenceScreen root = getPreferenceScreen();
// Get the good preference screen // Get the good preference screen
final PreferenceCategory accounts = (PreferenceCategory) root.getPreference(0); accounts = (PreferenceCategory) root.getPreference(0);
accounts.removeAll(); accounts.removeAll();
Preference addAccount = (Preference) root.getPreference(1); Preference addAccount = (Preference) root.getPreference(1);
addAccount.setOnPreferenceClickListener(new OnPreferenceClickListener() { addAccount.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@ -110,7 +137,7 @@ public class LinphonePreferencesActivity extends PreferenceActivity implements E
// Get already configured extra accounts // Get already configured extra accounts
SharedPreferences prefs = getPreferenceManager().getSharedPreferences(); SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
nbAccounts = prefs.getInt(getString(R.string.pref_extra_accounts), 1); nbAccounts = prefs.getInt(getString(R.string.pref_extra_accounts), 0);
for (int i = 0; i < nbAccounts; i++) { for (int i = 0; i < nbAccounts; i++) {
// For each, add menus to configure it // For each, add menus to configure it
addExtraAccountPreferencesButton(accounts, i, false); addExtraAccountPreferencesButton(accounts, i, false);
@ -155,6 +182,19 @@ public class LinphonePreferencesActivity extends PreferenceActivity implements E
parent.addPreference(me); parent.addPreference(me);
} }
private void fillLinphoneAccount(int i, String username, String password) {
SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
SharedPreferences.Editor editor = prefs.edit();
editor.putString(getString(R.string.pref_username_key) + i, username);
editor.putString(getString(R.string.pref_passwd_key) + i, password);
editor.putString(getString(R.string.pref_domain_key) + i, "sip.linphone.org");
editor.putString(getString(R.string.pref_proxy_key) + i, "");
editor.putBoolean(getString(R.string.pref_enable_outbound_proxy_key) + i, false);
editor.commit();
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
if (requestCode == ADD_SIP_ACCOUNT) { if (requestCode == ADD_SIP_ACCOUNT) {
@ -162,6 +202,277 @@ public class LinphonePreferencesActivity extends PreferenceActivity implements E
} }
} }
private void addWizardAccount() {
Preference wizard = (Preference) getPreferenceScreen().getPreference(2);
wizard.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
showDialog(WIZARD_ID);
return true;
}
});
}
protected Dialog onCreateDialog (int id) {
if (id == WIZARD_ID) {
AlertDialog.Builder builder = new AlertDialog.Builder(LinphonePreferencesActivity.this);
LayoutInflater inflater = LayoutInflater.from(LinphonePreferencesActivity.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;
}
return null;
}
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.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.notok);
createAccount.setEnabled(usernameOk && passwordOk && emailOk);
}
};
Runnable runOk = new Runnable() {
public void run() {
errorMessage.setText("");
icon.setImageResource(R.drawable.ok);
usernameOk = true;
createAccount.setEnabled(usernameOk && passwordOk && emailOk);
}
};
public void onResponse(long id, Object result) {
int answer = (Integer) result;
if (answer != 0) {
runOnUiThread(runNotOk);
}
else {
runOnUiThread(runOk);
}
}
public void onError(long id, XMLRPCException error) {
runOnUiThread(runNotReachable);
}
public void onServerError(long id, XMLRPCServerException error) {
runOnUiThread(runNotReachable);
}
};
client.callAsync(listener, "check_account", username);
}
catch(Exception ex) {
runOnUiThread(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);
fillLinphoneAccount(nbAccounts, username, password);
nbAccounts++;
createDynamicAccountsPreferences();
wizardDialog.dismiss();
Toast.makeText(LinphonePreferencesActivity.this, R.string.wizard_need_activation, Toast.LENGTH_LONG).show();
}
};
public void onResponse(long id, Object result) {
int answer = (Integer) result;
if (answer != 0) {
runOnUiThread(runNotOk);
} else {
runOnUiThread(runOk);
}
}
public void onError(long id, XMLRPCException error) {
runOnUiThread(runNotReachable);
}
public void onServerError(long id, XMLRPCServerException error) {
runOnUiThread(runNotReachable);
}
};
client.callAsync(listener, "create_account", username, password, email, suscribe ? 1 : 0);
}
catch(Exception ex) {
runOnUiThread(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.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.ok);
emailOk = true;
errorMessage.setText("");
}
else {
errorMessage.setText(R.string.wizard_email_incorrect);
icon.setImageResource(R.drawable.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.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.notok);
}
createAccount.setEnabled(usernameOk && passwordOk && emailOk);
}
};
field1.addTextChangedListener(passwordListener);
field2.addTextChangedListener(passwordListener);
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -169,6 +480,7 @@ public class LinphonePreferencesActivity extends PreferenceActivity implements E
addPreferencesFromResource(R.xml.preferences); addPreferencesFromResource(R.xml.preferences);
createDynamicAccountsPreferences(); createDynamicAccountsPreferences();
addWizardAccount();
addTransportChecboxesListener(); addTransportChecboxesListener();
ecCalibratePref = (CheckBoxPreference) findPreference(pref_echo_canceller_calibration_key); ecCalibratePref = (CheckBoxPreference) findPreference(pref_echo_canceller_calibration_key);

View file

@ -1,4 +1,22 @@
package org.linphone; package org.linphone;
/*
LinphonePreferencesSIPAccountActivity.java
Copyright (C) 2011 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 org.linphone.core.Log; import org.linphone.core.Log;
@ -64,7 +82,7 @@ public class LinphonePreferencesSIPAccountActivity extends PreferenceActivity {
delete.setTitle("Delete this account"); delete.setTitle("Delete this account");
delete.setOnPreferenceClickListener(new OnPreferenceClickListener() { delete.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) { public boolean onPreferenceClick(Preference preference) {
int nbAccounts = prefs.getInt(getString(R.string.pref_extra_accounts), 1); int nbAccounts = prefs.getInt(getString(R.string.pref_extra_accounts), 0);
SharedPreferences.Editor editor = prefs.edit(); SharedPreferences.Editor editor = prefs.edit();
for (int i = n; i < nbAccounts - 1; i++) { for (int i = n; i < nbAccounts - 1; i++) {