Added bool to ensure account is valid in setup assistant + dynamic disable of options items while in call

This commit is contained in:
Sylvain Berfini 2013-06-11 11:26:51 +02:00
parent 84cd341efc
commit 11cffbda2b
5 changed files with 66 additions and 10 deletions

View file

@ -22,6 +22,7 @@
<string name="setup_forced_proxy"></string>
<bool name="setup_cancel_move_to_back">false</bool>
<bool name="setup_use_linphone_as_first_fragment">false</bool>
<bool name="setup_account_validation_mandatory">false</bool>
<bool name="hide_linphone_accounts_wizard">false</bool>
<bool name="hide_generic_accounts_wizard">false</bool>
<bool name="hide_accounts">false</bool>

View file

@ -333,16 +333,13 @@ public class InCallActivity extends FragmentActivity implements
mHandler.post(new Runnable() {
@Override
public void run() {
if (getResources().getBoolean(R.bool.disable_options_in_call)) {
options.setEnabled(false);
} else {
options.setEnabled(true);
}
addCall.setEnabled(LinphoneManager.getLc().getCallsNb() < LinphoneManager.getLc().getMaxCalls());
transfer.setEnabled(getResources().getBoolean(R.bool.allow_transfers));
options.setEnabled(!getResources().getBoolean(R.bool.disable_options_in_call) && (addCall.isEnabled() || transfer.isEnabled()));
video.setEnabled(true);
micro.setEnabled(true);
speaker.setEnabled(true);
addCall.setEnabled(true);
transfer.setEnabled(true);
pause.setEnabled(true);
dialer.setEnabled(true);

View file

@ -1637,7 +1637,7 @@ public class LinphoneManager implements LinphoneCoreListener {
public void onRegistrationStateChanged(RegistrationState state,
String message) {
if (serviceListener != null) serviceListener.onRegistrationStateChanged(state, message);
for (LinphoneOnRegistrationStateChangedListener listener : getSimpleListeners(LinphoneActivity.class)) {
for (LinphoneOnRegistrationStateChangedListener listener : getSimpleListeners(LinphoneOnRegistrationStateChangedListener.class)) {
listener.onRegistrationStateChanged(state);
}
}

View file

@ -58,7 +58,7 @@ public class LinphoneLoginFragment extends Fragment implements OnClickListener {
return;
}
SetupActivity.instance().linphoneLogIn(login.getText().toString(), password.getText().toString());
SetupActivity.instance().linphoneLogIn(login.getText().toString(), password.getText().toString(), getResources().getBoolean(R.bool.setup_account_validation_mandatory));
}
@Override

View file

@ -18,7 +18,9 @@ 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.LinphoneManager;
import org.linphone.LinphoneSimpleListener.LinphoneOnRegistrationStateChangedListener;
import org.linphone.R;
import org.linphone.core.LinphoneCore.RegistrationState;
import org.linphone.mediastream.Log;
import android.app.Activity;
@ -26,6 +28,7 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
@ -47,6 +50,7 @@ public class SetupActivity extends FragmentActivity implements OnClickListener {
private SetupFragmentsEnum firstFragment;
private Fragment fragment;
private boolean accountCreated = false;
private Handler mHandler = new Handler();
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -192,8 +196,54 @@ public class SetupActivity extends FragmentActivity implements OnClickListener {
}
}
public void linphoneLogIn(String username, String password) {
logIn(username, password, getString(R.string.default_domain), true);
private LinphoneOnRegistrationStateChangedListener registrationListener = new LinphoneOnRegistrationStateChangedListener() {
public void onRegistrationStateChanged(RegistrationState state) {
if (state == RegistrationState.RegistrationOk) {
LinphoneManager.removeListener(registrationListener);
if (LinphoneManager.getLc().getDefaultProxyConfig() != null) {
mHandler .post(new Runnable () {
public void run() {
launchEchoCancellerCalibration(true);
}
});
}
} else if (state == RegistrationState.RegistrationFailed) {
LinphoneManager.removeListener(registrationListener);
deleteCreatedAccount();
mHandler.post(new Runnable () {
public void run() {
Toast.makeText(SetupActivity.this, getString(R.string.first_launch_bad_login_password), Toast.LENGTH_LONG).show();
}
});
}
}
};
public void checkAccount(String username, String password, String domain) {
LinphoneManager.removeListener(registrationListener);
LinphoneManager.addListener(registrationListener);
saveCreatedAccount(username, password, domain);
LinphoneManager.getInstance().initializePayloads();
try {
LinphoneManager.getInstance().initFromConf();
} catch (Throwable e) {
LinphoneManager.removeListener(registrationListener);
deleteCreatedAccount();
Log.e(e, "Error while initializing from config in first login activity");
Toast.makeText(this, getString(R.string.error), Toast.LENGTH_LONG).show();
}
}
public void linphoneLogIn(String username, String password, boolean validate) {
if (validate) {
checkAccount(username, password, getString(R.string.default_domain));
} else {
logIn(username, password, getString(R.string.default_domain), true);
}
}
public void genericLogIn(String username, String password, String domain) {
@ -253,6 +303,14 @@ public class SetupActivity extends FragmentActivity implements OnClickListener {
currentFragment = SetupFragmentsEnum.WIZARD;
}
public void deleteCreatedAccount() {
if (!accountCreated)
return;
writePreference(R.string.pref_extra_accounts, 0);
accountCreated = false;
}
public void saveCreatedAccount(String username, String password, String domain) {
if (accountCreated)
return;