wizard confirmation popup improved

This commit is contained in:
Sylvain Berfini 2012-02-08 11:28:35 +01:00
parent ff5672fae4
commit 34014bbfb1
3 changed files with 118 additions and 7 deletions

View file

@ -36,6 +36,8 @@
<string name="pref_domain_key">pref_domain_key</string> <string name="pref_domain_key">pref_domain_key</string>
<string name="pref_passwd_key">pref_passwd_key</string> <string name="pref_passwd_key">pref_passwd_key</string>
<string name="pref_username_key">pref_username_key</string> <string name="pref_username_key">pref_username_key</string>
<string name="pref_wizard_key">pref_wizard_key</string>
<string name="pref_activated_key">pref_activated_key</string>
<string name="pref_debug_key">pref_debug_key</string> <string name="pref_debug_key">pref_debug_key</string>
<string name="first_launch_suceeded_once_key">first_launch_suceeded_once_key</string> <string name="first_launch_suceeded_once_key">first_launch_suceeded_once_key</string>

View file

@ -33,11 +33,19 @@ import org.linphone.ui.CallButton;
import org.linphone.ui.EraseButton; import org.linphone.ui.EraseButton;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Adapter; import android.widget.Adapter;
import android.widget.Button;
import android.widget.ListAdapter; import android.widget.ListAdapter;
import android.widget.ListView; import android.widget.ListView;
import android.widget.SimpleAdapter; import android.widget.SimpleAdapter;
@ -68,10 +76,16 @@ public class DialerActivity extends Activity implements LinphoneGuiListener {
private static DialerActivity instance; private static DialerActivity instance;
private boolean mPreventDoubleCallOnRotation; private boolean mPreventDoubleCallOnRotation;
private AlertDialog wizardDialog;
protected String username;
private String key;
private static final String CURRENT_ADDRESS = "org.linphone.current-address"; private static final String CURRENT_ADDRESS = "org.linphone.current-address";
private static final String CURRENT_DISPLAYNAME = "org.linphone.current-displayname"; private static final String CURRENT_DISPLAYNAME = "org.linphone.current-displayname";
private static final String PREVENT_DOUBLE_CALL = "prevent_call_on_phone_rotation"; private static final String PREVENT_DOUBLE_CALL = "prevent_call_on_phone_rotation";
private static final int CONFIRM_ID = 0x668;
/** /**
* @return null if not ready yet * @return null if not ready yet
*/ */
@ -112,6 +126,68 @@ public class DialerActivity extends Activity implements LinphoneGuiListener {
} }
} }
protected Dialog onCreateDialog (int id) {
if (id == CONFIRM_ID) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.wizard_confirmation);
final LayoutInflater inflater = LayoutInflater.from(this);
View v = inflater.inflate(R.layout.wizard_confirm, null);
builder.setView(v);
Button check = (Button) v.findViewById(R.id.wizardCheckAccount);
check.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
wizardDialog.dismiss();
if (LinphonePreferencesActivity.isAccountVerified(username)) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(DialerActivity.this);
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean(getString(R.string.pref_activated_key) + key, true);
editor.commit();
} else {
showDialog(CONFIRM_ID);
}
}
});
Button cancel = (Button) v.findViewById(R.id.wizardCancel);
cancel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
wizardDialog.dismiss();
}
});
wizardDialog = builder.create();
return wizardDialog;
}
return null;
}
private void verifiyAccountsActivated() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
int nbAccounts = prefs.getInt(getString(R.string.pref_extra_accounts), 0);
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
String username = prefs.getString(getString(R.string.pref_username_key) + key, "");
activated = LinphonePreferencesActivity.isAccountVerified(username);
if (activated) {
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean(getString(R.string.pref_activated_key) + key, true);
editor.commit();
} else {
this.username = username;
this.key = key;
showDialog(CONFIRM_ID);
}
}
}
}
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.dialer); setContentView(R.layout.dialer);
@ -155,6 +231,9 @@ public class DialerActivity extends Activity implements LinphoneGuiListener {
instance = this; instance = this;
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
verifiyAccountsActivated();
displayRegisterStatus(); displayRegisterStatus();
} }

View file

@ -184,7 +184,7 @@ public class LinphonePreferencesActivity extends PreferenceActivity implements E
parent.addPreference(me); parent.addPreference(me);
} }
private void fillLinphoneAccount(int i, String username, String password) { private void fillLinphoneAccount(int i, String username, String password, boolean createdByWizard) {
SharedPreferences prefs = getPreferenceManager().getSharedPreferences(); SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
SharedPreferences.Editor editor = prefs.edit(); SharedPreferences.Editor editor = prefs.edit();
@ -192,6 +192,8 @@ public class LinphonePreferencesActivity extends PreferenceActivity implements E
editor.putString(getString(R.string.pref_passwd_key) + i, password); 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_domain_key) + i, "sip.linphone.org");
editor.putString(getString(R.string.pref_proxy_key) + i, ""); editor.putString(getString(R.string.pref_proxy_key) + i, "");
editor.putBoolean(getString(R.string.pref_wizard_key) + i, createdByWizard);
editor.putBoolean(getString(R.string.pref_activated_key) + i, false);
editor.putBoolean(getString(R.string.pref_enable_outbound_proxy_key) + i, false); editor.putBoolean(getString(R.string.pref_enable_outbound_proxy_key) + i, false);
editor.commit(); editor.commit();
@ -217,7 +219,7 @@ public class LinphonePreferencesActivity extends PreferenceActivity implements E
} }
} }
private void addWizardAccount() { private void addWizardPreferenceButton() {
Preference wizard = (Preference) getPreferenceScreen().getPreference(2); Preference wizard = (Preference) getPreferenceScreen().getPreference(2);
wizard.setOnPreferenceClickListener(new OnPreferenceClickListener() { wizard.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) { public boolean onPreferenceClick(Preference preference) {
@ -272,15 +274,21 @@ public class LinphonePreferencesActivity extends PreferenceActivity implements E
AlertDialog.Builder builder = new AlertDialog.Builder(LinphonePreferencesActivity.this); AlertDialog.Builder builder = new AlertDialog.Builder(LinphonePreferencesActivity.this);
builder.setTitle(R.string.wizard_confirmation); builder.setTitle(R.string.wizard_confirmation);
LayoutInflater inflater = LayoutInflater.from(LinphonePreferencesActivity.this); final LayoutInflater inflater = LayoutInflater.from(LinphonePreferencesActivity.this);
View v = inflater.inflate(R.layout.wizard_confirm, null); View v = inflater.inflate(R.layout.wizard_confirm, null);
builder.setView(v); builder.setView(v);
Button check = (Button) v.findViewById(R.id.wizardCheckAccount); Button check = (Button) v.findViewById(R.id.wizardCheckAccount);
check.setOnClickListener(new OnClickListener() { check.setOnClickListener(new OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
wizardDialog.dismiss();
if (isAccountVerified(username)) { if (isAccountVerified(username)) {
wizardDialog.dismiss(); SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean(getString(R.string.pref_activated_key) + (nbAccounts - 1), true);
editor.commit();
} else {
showDialog(CONFIRM_ID);
} }
} }
}); });
@ -302,7 +310,7 @@ public class LinphonePreferencesActivity extends PreferenceActivity implements E
return username.matches("^[a-zA-Z]+[a-zA-Z0-9.\\-_]{2,}$"); return username.matches("^[a-zA-Z]+[a-zA-Z0-9.\\-_]{2,}$");
} }
private boolean isAccountVerified(String username) { static boolean isAccountVerified(String username) {
try { try {
XMLRPCClient client = new XMLRPCClient(new URL("https://www.linphone.org/wizard.php")); XMLRPCClient client = new XMLRPCClient(new URL("https://www.linphone.org/wizard.php"));
Object resultO = client.call("check_account_validated", "sip:" + username + "@sip.linphone.org"); Object resultO = client.call("check_account_validated", "sip:" + username + "@sip.linphone.org");
@ -402,7 +410,7 @@ public class LinphonePreferencesActivity extends PreferenceActivity implements E
public void run() { public void run() {
addExtraAccountPreferencesButton(accounts, nbAccounts, true); addExtraAccountPreferencesButton(accounts, nbAccounts, true);
LinphonePreferencesActivity.this.username = username; LinphonePreferencesActivity.this.username = username;
fillLinphoneAccount(nbAccounts, username, password); fillLinphoneAccount(nbAccounts, username, password, true);
nbAccounts++; nbAccounts++;
createDynamicAccountsPreferences(); createDynamicAccountsPreferences();
wizardDialog.dismiss(); wizardDialog.dismiss();
@ -529,6 +537,26 @@ public class LinphonePreferencesActivity extends PreferenceActivity implements E
field2.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);
}
}
}
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -536,9 +564,11 @@ public class LinphonePreferencesActivity extends PreferenceActivity implements E
addPreferencesFromResource(R.xml.preferences); addPreferencesFromResource(R.xml.preferences);
createDynamicAccountsPreferences(); createDynamicAccountsPreferences();
addWizardAccount(); addWizardPreferenceButton();
addTransportChecboxesListener(); addTransportChecboxesListener();
verifiyAccountsActivated();
ecCalibratePref = (CheckBoxPreference) findPreference(pref_echo_canceller_calibration_key); ecCalibratePref = (CheckBoxPreference) findPreference(pref_echo_canceller_calibration_key);
ecCalibratePref.setOnPreferenceClickListener(new OnPreferenceClickListener() { ecCalibratePref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) { public boolean onPreferenceClick(Preference preference) {