# HG changeset patch # User Nikita Kozlov # Date 1268523325 -3600 # Node ID bbd54153f92c18c376e9a87e1028cecbda2b6ce9 # Parent d80ac2c011f870e931c3f233ff8c626eb464cb9b Bug #249 and a small debug on AccountConfigure.java diff -r d80ac2c011f8 -r bbd54153f92c src/com/beem/project/beem/BeemApplication.java --- a/src/com/beem/project/beem/BeemApplication.java Sat Mar 13 21:52:35 2010 +0100 +++ b/src/com/beem/project/beem/BeemApplication.java Sun Mar 14 00:35:25 2010 +0100 @@ -70,7 +70,9 @@ public void onCreate() { super.onCreate(); mSettings = PreferenceManager.getDefaultSharedPreferences(this); - mIsAccountConfigured = mSettings.getBoolean("PreferenceIsConfigured", false); + String login = mSettings.getString("settings_key_account_username", ""); + String password = mSettings.getString("settings_key_account_password", ""); + mIsAccountConfigured = !("".equals(login) || "".equals(password)); mSettings.registerOnSharedPreferenceChangeListener(mPreferenceListener); } @@ -118,8 +120,10 @@ @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { - if ("PreferenceIsConfigured".equals(key)) { - mIsAccountConfigured = mSettings.getBoolean("PreferenceIsConfigured", false); + if ("settings_key_account_username".equals(key) || "settings_key_account_password".equals(key)) { + String login = mSettings.getString("settings_key_account_username", ""); + String password = mSettings.getString("settings_key_account_password", ""); + mIsAccountConfigured = !("".equals(login) || "".equals(password)); } } } diff -r d80ac2c011f8 -r bbd54153f92c src/com/beem/project/beem/BeemService.java --- a/src/com/beem/project/beem/BeemService.java Sat Mar 13 21:52:35 2010 +0100 +++ b/src/com/beem/project/beem/BeemService.java Sun Mar 14 00:35:25 2010 +0100 @@ -187,7 +187,10 @@ mPassword = mSettings.getString("settings_key_account_password", ""); mPort = DEFAULT_XMPP_PORT; mService = StringUtils.parseServer(tmpJid); - mHost = StringUtils.parseServer(tmpJid); + mHost = mService; + + if ("".equals(mLogin)) + mLogin = mService; if (mSettings.getBoolean("settings_key_specific_server", false)) { mHost = mSettings.getString("settings_key_xmpp_server", ""); diff -r d80ac2c011f8 -r bbd54153f92c src/com/beem/project/beem/ui/Login.java --- a/src/com/beem/project/beem/ui/Login.java Sat Mar 13 21:52:35 2010 +0100 +++ b/src/com/beem/project/beem/ui/Login.java Sun Mar 14 00:35:25 2010 +0100 @@ -48,32 +48,28 @@ import android.app.Application; import android.content.DialogInterface; import android.content.Intent; +import android.content.pm.PackageInfo; import android.content.pm.PackageManager; -import android.content.pm.PackageInfo; -import android.content.SharedPreferences; import android.os.Bundle; -import android.preference.PreferenceManager; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.widget.TextView; import android.widget.Toast; +import com.beem.project.beem.BeemApplication; import com.beem.project.beem.R; +import com.beem.project.beem.ui.wizard.Account; import com.beem.project.beem.utils.BeemConnectivity; -import com.beem.project.beem.BeemApplication; -import com.beem.project.beem.ui.wizard.Account; /** * This class is the main Activity for the Beem project. - * @author Da Risk + * @author Da Risk */ public class Login extends Activity { private static final int LOGIN_REQUEST_CODE = 1; - private SharedPreferences mSettings; private TextView mTextView; - private boolean mIsConfigured; private boolean mIsResult; private BeemApplication mBeemApplication; @@ -99,15 +95,13 @@ } setContentView(R.layout.login); mTextView = (TextView) findViewById(R.id.log_as_msg); - mSettings = PreferenceManager.getDefaultSharedPreferences(this); } @Override protected void onStart() { super.onStart(); - mIsConfigured = mSettings.getBoolean("PreferenceIsConfigured", false); - // TODO utiliser une options des preference plutot. - if (mIsConfigured && !mIsResult && BeemConnectivity.isConnected(getApplicationContext())) { + if (mBeemApplication.isAccountConfigured() && !mIsResult + && BeemConnectivity.isConnected(getApplicationContext())) { mTextView.setText(""); Intent i = new Intent(this, LoginAnim.class); startActivityForResult(i, LOGIN_REQUEST_CODE); @@ -156,7 +150,7 @@ result = true; break; case R.id.login_menu_login: - if (testConnectivity()) { + if (mBeemApplication.isAccountConfigured()) { Intent i = new Intent(this, LoginAnim.class); startActivityForResult(i, LOGIN_REQUEST_CODE); } @@ -170,18 +164,6 @@ } /** - * Test the connectivity of the phone. - * @return true if we are connected to a network. - */ - private boolean testConnectivity() { - if (!BeemConnectivity.isConnected(getApplicationContext())) { - Toast.makeText(Login.this, R.string.login_no_connectivity, Toast.LENGTH_SHORT).show(); - return false; - } - return true; - } - - /** * Create an about "BEEM" dialog. */ private void createAboutDialog() { diff -r d80ac2c011f8 -r bbd54153f92c src/com/beem/project/beem/ui/wizard/AccountConfigure.java --- a/src/com/beem/project/beem/ui/wizard/AccountConfigure.java Sat Mar 13 21:52:35 2010 +0100 +++ b/src/com/beem/project/beem/ui/wizard/AccountConfigure.java Sun Mar 14 00:35:25 2010 +0100 @@ -70,6 +70,7 @@ */ public class AccountConfigure extends Activity implements OnClickListener { + private static final int MANUAL_CONFIGURATION = 1; private Button mNextButton; private Button mManualConfigButton; private EditText mAccountJID; @@ -114,13 +115,27 @@ if (v == mNextButton) { configureAccount(); i = new Intent(this, Login.class); - } else if (v == mManualConfigButton) { - i = new Intent(this, Settings.class); - } - if (i != null) { i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i); finish(); + } else if (v == mManualConfigButton) { + i = new Intent(this, Settings.class); + i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + startActivityForResult(i, MANUAL_CONFIGURATION); + } + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode == MANUAL_CONFIGURATION) { + SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); + String login = settings.getString("settings_key_account_username", ""); + String password = settings.getString("settings_key_account_password", ""); + mAccountJID.setText(login); + mAccountPassword.setText(password); + checkUsername(login); + checkPassword(password); + mNextButton.setEnabled(mValidJid && mValidPassword); } } @@ -137,6 +152,30 @@ } /** + * check username. + * @param username . + */ + private void checkUsername(String username) { + String server = StringUtils.parseServer(username.toString()); + if (server == null || "".equals(server)) { + mValidJid = false; + } else { + mValidJid = true; + } + } + + /** + * check password. + * @param password . + */ + private void checkPassword(String password) { + if (password.length() > 0) + mValidPassword = true; + else + mValidPassword = false; + } + + /** * Text watcher to test the existence of a password. */ private class PasswordTextWatcher implements TextWatcher { @@ -149,10 +188,7 @@ @Override public void afterTextChanged(Editable s) { - if (s.length() > 0) - mValidPassword = true; - else - mValidPassword = false; + checkPassword(s.toString()); mNextButton.setEnabled(mValidJid && mValidPassword); } @@ -178,13 +214,7 @@ @Override public void afterTextChanged(Editable s) { - String name = StringUtils.parseName(s.toString()); - String server = StringUtils.parseServer(s.toString()); - if (name == null || "".equals(name) || server == null || "".equals(server)) { - mValidJid = false; - } else { - mValidJid = true; - } + checkUsername(s.toString()); mNextButton.setEnabled(mValidJid && mValidPassword); }