# HG changeset patch # User Vincent Veronis # Date 1259833784 -3600 # Node ID a560f82d48b0eef3178ba0b52dba2d82c0b22a5f # Parent b3a34023b8c8f7856e48bae3be03a464bf036a43# Parent 5a2e5cf7c8c1ce00f6b916cbac9270ed62466f2b Merge. Javadoc + Clean Code (Login.java + LoginAnim.java) diff -r 5a2e5cf7c8c1 -r a560f82d48b0 AndroidManifest.xml diff -r 5a2e5cf7c8c1 -r a560f82d48b0 res/values-fr/strings.xml --- a/res/values-fr/strings.xml Thu Dec 03 01:37:47 2009 +0100 +++ b/res/values-fr/strings.xml Thu Dec 03 10:49:44 2009 +0100 @@ -177,21 +177,7 @@ --> Créer un compte Gérer mes listes privées - Les paramètres ont été enregistrés avec succès. - - - beem_account_username - beem_account_password - beem_xmpp_server - beem_xmpp_port - beem_xmpp_tls_use - beem_xmpp_proxy_use - beem_xmpp_proxy_server - beem_xmpp_proxy_port - beem_xmpp_proxy_username - beem_xmpp_proxy_password - beem_xmpp_proxy_type - settings_key_hidden_contact + Les paramètres ont été enregistrés avec succès. Préférences de l\'application @@ -246,7 +232,7 @@ Créer un compte - Erreur Changer mes paramètres Fermer - A été créé avec succès + L\'utilisateur %s a été créé avec succès Mauvais JabberID Les mots de passe ne correspondent pas Nom d\'utilisateur diff -r 5a2e5cf7c8c1 -r a560f82d48b0 res/values/strings.xml --- a/res/values/strings.xml Thu Dec 03 01:37:47 2009 +0100 +++ b/res/values/strings.xml Thu Dec 03 10:49:44 2009 +0100 @@ -167,18 +167,7 @@ Manage my privacy lists The settings have been saved successfully. - beem_account_username - beem_account_password - beem_xmpp_server - beem_xmpp_port - beem_xmpp_tls_use - beem_xmpp_proxy_use - beem_xmpp_proxy_server - beem_xmpp_proxy_port - beem_xmpp_proxy_username - beem_xmpp_proxy_password - beem_xmpp_proxy_type - settings_key_hidden_contact + General preferences @@ -231,7 +220,7 @@ Create an account - Error Change my settings Close - has been created successfully + account %s has been created successfully Bad JabberID Passwords do not match. Username diff -r 5a2e5cf7c8c1 -r a560f82d48b0 src/com/beem/project/beem/BeemService.java --- a/src/com/beem/project/beem/BeemService.java Thu Dec 03 01:37:47 2009 +0100 +++ b/src/com/beem/project/beem/BeemService.java Thu Dec 03 10:49:44 2009 +0100 @@ -79,7 +79,6 @@ private ProxyInfo mProxyInfo; private boolean mUseProxy; private IXmppFacade.Stub mBind; - private ProviderManager mProviderManager; /** * Constructor. diff -r 5a2e5cf7c8c1 -r a560f82d48b0 src/com/beem/project/beem/ui/CreateAccount.java --- a/src/com/beem/project/beem/ui/CreateAccount.java Thu Dec 03 01:37:47 2009 +0100 +++ b/src/com/beem/project/beem/ui/CreateAccount.java Thu Dec 03 10:49:44 2009 +0100 @@ -15,7 +15,6 @@ import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; -import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; @@ -66,12 +65,12 @@ private boolean createAccount(String username, String password) { XMPPConnection xmppConnection = null; ConnectionConfiguration connectionConfiguration = null; - - if (getRegisteredProxy() != null) { - connectionConfiguration = new ConnectionConfiguration(getXMPPServer(), DEFAULT_XMPP_PORT, - getRegisteredProxy()); + ProxyInfo pi = null; + if ((pi = getRegisteredProxy()) != null) { + connectionConfiguration = new ConnectionConfiguration(getXMPPServer(), getXMPPPort(), + pi); } else { - connectionConfiguration = new ConnectionConfiguration(getXMPPServer(), DEFAULT_XMPP_PORT); + connectionConfiguration = new ConnectionConfiguration(getXMPPServer(), getXMPPPort()); } if (getRegisteredXMPPTLSUse()) connectionConfiguration.setSecurityMode(ConnectionConfiguration.SecurityMode.required); @@ -81,11 +80,9 @@ xmppConnection.connect(); AccountManager accountManager = new AccountManager(xmppConnection); accountManager.createAccount(username, password); - Toast toast = Toast.makeText(getApplicationContext(), "Account " + username + " " - + getString(R.string.create_account_successfull_after), NOTIFICATION_DURATION); + Toast toast = Toast.makeText(getApplicationContext(), String.format(getString(R.string.create_account_successfull_after),username), NOTIFICATION_DURATION); toast.show(); } catch (XMPPException e) { - Log.e(getString(R.string.create_account_tag), e.getMessage()); createErrorDialog(e.getMessage()); return false; } @@ -98,7 +95,6 @@ * @param errMsg the error message */ private void createErrorDialog(String errMsg) { - Log.v(getString(R.string.create_account_tag), errMsg); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.create_account_err_dialog_title).setMessage(errMsg).setCancelable(false); builder.setNeutralButton(R.string.create_account_close_dialog_button, new DialogInterface.OnClickListener() { @@ -130,7 +126,7 @@ * @return Registered proxy password */ private String getRegisteredProxyPassword() { - return mSettings.getString(getString(R.string.settings_key_proxy_password), DEFAULT_STRING_VALUE); + return mSettings.getString("settings_key_proxy_password", DEFAULT_STRING_VALUE); } /** @@ -139,7 +135,7 @@ */ private int getRegisteredProxyPort() { return Integer - .parseInt(mSettings.getString(getString(R.string.settings_key_proxy_port), DEFAULT_STRING_VALUE)); + .parseInt(mSettings.getString("settings_key_proxy_port", DEFAULT_STRING_VALUE)); } /** @@ -147,7 +143,7 @@ * @return Registered proxy server */ private String getRegisteredProxyServer() { - return mSettings.getString(getString(R.string.settings_key_proxy_server), DEFAULT_STRING_VALUE); + return mSettings.getString("settings_key_proxy_server", DEFAULT_STRING_VALUE); } /** @@ -156,7 +152,7 @@ */ private ProxyInfo.ProxyType getRegisteredProxyType() { ProxyInfo.ProxyType result; - switch (mSettings.getInt(getString(R.string.settings_key_proxy_type), DEFAULT_INT_VALUE)) { + switch (mSettings.getInt("settings_key_proxy_type", DEFAULT_INT_VALUE)) { case 0: result = ProxyInfo.ProxyType.HTTP; break; @@ -164,12 +160,11 @@ result = ProxyInfo.ProxyType.SOCKS4; break; case 2: - Log.i(getString(R.string.create_account_tag), "SOCKS5 PROXY"); result = ProxyInfo.ProxyType.SOCKS5; break; default: result = ProxyInfo.ProxyType.NONE; - break; + break; } return result; } @@ -179,7 +174,7 @@ * @return Registered proxy use */ private boolean getRegisteredProxyUse() { - return mSettings.getBoolean(getString(R.string.settings_key_proxy_use), DEFAULT_BOOLEAN_VALUE); + return mSettings.getBoolean("settings_key_proxy_use", DEFAULT_BOOLEAN_VALUE); } /** @@ -187,7 +182,18 @@ * @return Registered proxy username */ private String getRegisteredProxyUsername() { - return mSettings.getString(getString(R.string.settings_key_proxy_username), DEFAULT_STRING_VALUE); + return mSettings.getString("settings_key_proxy_username", DEFAULT_STRING_VALUE); + } + + /** + * Retrieve xmpp port from the preferences. + * @return Registered xmpp port + */ + private int getXMPPPort() { + int port = DEFAULT_XMPP_PORT; + if (mSettings.getBoolean("settings_key_specific_server", false)) + port = Integer.parseInt(mSettings.getString("settings_key_xmpp_port", "5222")); + return port; } /** @@ -196,7 +202,11 @@ */ private String getXMPPServer() { TextView xmppServerTextView = (TextView) findViewById(R.id.create_account_username); - String xmppServer = StringUtils.parseServer(xmppServerTextView.getText().toString()); + String xmppServer = ""; + if (mSettings.getBoolean("settings_key_specific_server", false)) + xmppServer = mSettings.getString("settings_key_xmpp_server", ""); + else + xmppServer = StringUtils.parseServer(xmppServerTextView.getText().toString()); return xmppServer; } @@ -205,7 +215,7 @@ * @return Registered TLS use */ private boolean getRegisteredXMPPTLSUse() { - return mSettings.getBoolean(getString(R.string.settings_key_xmpp_tls_use), DEFAULT_BOOLEAN_VALUE); + return mSettings.getBoolean("settings_key_xmpp_tls_use", DEFAULT_BOOLEAN_VALUE); } /** @@ -215,7 +225,7 @@ private boolean checkPasswords() { final String passwordFieldValue = ((EditText) findViewById(R.id.create_account_password)).getText().toString(); final String passwordConfirmFielddValue = ((EditText) findViewById(R.id.create_account_confirm_password)) - .getText().toString(); + .getText().toString(); return passwordFieldValue.equals(passwordConfirmFielddValue); } @@ -237,9 +247,9 @@ mCreateAccountButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String usernameFieldValue = ((EditText) findViewById(R.id.create_account_username)).getText() - .toString(); + .toString(); String passwordFieldValue = ((EditText) findViewById(R.id.create_account_password)).getText() - .toString(); + .toString(); String username = StringUtils.parseName(usernameFieldValue); if (!checkEmail()) createErrorDialog(getString(R.string.create_account_err_username)); @@ -256,10 +266,10 @@ createAccountLoginButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String usernameFieldValue = ((EditText) findViewById(R.id.create_account_username)).getText() - .toString(); + .toString(); String username = StringUtils.parseName(usernameFieldValue); String passwordFieldValue = ((EditText) findViewById(R.id.create_account_password)).getText() - .toString(); + .toString(); if (!checkEmail()) createErrorDialog(getString(R.string.create_account_err_username)); else if (!checkPasswords()) @@ -268,10 +278,10 @@ if (createAccount(username, passwordFieldValue)) { SharedPreferences.Editor settingsEditor = mSettings.edit(); settingsEditor - .putString(getString(R.string.settings_key_account_username), usernameFieldValue); + .putString("settings_key_account_username", usernameFieldValue); settingsEditor - .putString(getString(R.string.settings_key_account_password), passwordFieldValue); - settingsEditor.putBoolean(getString(R.string.PreferenceIsConfigured), true); + .putString("settings_key_account_password", passwordFieldValue); + settingsEditor.putBoolean("PreferenceIsConfigured", true); settingsEditor.commit(); finish(); } diff -r 5a2e5cf7c8c1 -r a560f82d48b0 src/com/beem/project/beem/ui/Login.java --- a/src/com/beem/project/beem/ui/Login.java Thu Dec 03 01:37:47 2009 +0100 +++ b/src/com/beem/project/beem/ui/Login.java Thu Dec 03 10:49:44 2009 +0100 @@ -7,7 +7,6 @@ import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; -import android.util.Log; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; @@ -22,7 +21,6 @@ */ public class Login extends Activity { - private static final String TAG = "Login2"; private SharedPreferences mSettings; private TextView mTextView; private boolean mIsConfigured; @@ -38,7 +36,7 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.login); - mTextView = (TextView)findViewById(R.id.log_as_msg); + mTextView = (TextView) findViewById(R.id.log_as_msg); mSettings = PreferenceManager.getDefaultSharedPreferences(this); } @@ -60,15 +58,11 @@ if (requestCode == 42) { mIsResult = true; if (resultCode == Activity.RESULT_OK) { - Log.d(TAG, "Connected !!! Launch contact list"); startActivity(new Intent(this, ContactList.class)); finish(); - } else if (resultCode == Activity.RESULT_CANCELED) { // or error ? - // Set an intent with data in like the error msg - Log.d(TAG, "NOT Connected !!!"); + } else if (resultCode == Activity.RESULT_CANCELED) { if (data != null) { String tmp = data.getExtras().getString("message"); - Log.d(TAG, tmp); Toast.makeText(Login.this, tmp, Toast.LENGTH_SHORT).show(); mTextView.setText(tmp); } @@ -76,9 +70,6 @@ } } - /** - * {@inheritDoc} - */ @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); @@ -87,9 +78,6 @@ return true; } - /** - * {@inheritDoc} - */ @Override public final boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { @@ -124,5 +112,4 @@ AlertDialog aboutDialog = builder.create(); aboutDialog.show(); } - } diff -r 5a2e5cf7c8c1 -r a560f82d48b0 src/com/beem/project/beem/ui/LoginAnim.java --- a/src/com/beem/project/beem/ui/LoginAnim.java Thu Dec 03 01:37:47 2009 +0100 +++ b/src/com/beem/project/beem/ui/LoginAnim.java Thu Dec 03 10:49:44 2009 +0100 @@ -48,6 +48,42 @@ } @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.login_anim); + mLogo = (ImageView) findViewById(R.id.loginanim_logo_anim); + mRotateAnim = AnimationUtils.loadAnimation(this, R.anim.rotate_and_scale); + mCancelBt = (Button) findViewById(R.id.loginanim_cancel_button); + mCancelBt.setOnClickListener(new ClickListener()); + mProgressBar = (ProgressBar) findViewById(R.id.loginanim_progressbar); + mProgressBar.setIndeterminate(true); + } + + @Override + protected void onStart() { + super.onStart(); + mLogo.startAnimation(mRotateAnim); + } + + @Override + protected void onResume() { + super.onResume(); + if (mTask == null) + mTask = new LoginTask(); + if (mXmppFacade == null) + bindService(LoginAnim.SERVICE_INTENT, mServConn, BIND_AUTO_CREATE); + } + + @Override + protected void onPause() { + super.onPause(); + if (mXmppFacade != null) { // and async task not en cours + unbindService(mServConn); + mXmppFacade = null; + } + } + + @Override public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO use onBackPressed on Eclair (2.0) if (keyCode == KeyEvent.KEYCODE_BACK && mTask.getStatus() != AsyncTask.Status.FINISHED) { @@ -60,53 +96,15 @@ } /** - * {@inheritDoc} + * Click event listener on cancel button. */ - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.login_anim); - mLogo = (ImageView) findViewById(R.id.loginanim_logo_anim); - mRotateAnim = AnimationUtils.loadAnimation(this, R.anim.rotate_and_scale); - mCancelBt = (Button) findViewById(R.id.loginanim_cancel_button); - mCancelBt.setOnClickListener(new ClickListener()); - mProgressBar = (ProgressBar) findViewById(R.id.loginanim_progressbar); - mProgressBar.setIndeterminate(true); - } - - /** - * {@inheritDoc} - */ - @Override - protected void onStart() { - super.onStart(); - mLogo.startAnimation(mRotateAnim); - } + private class ClickListener implements OnClickListener { - /** - * {@inheritDoc} - */ - @Override - protected void onResume() { - super.onResume(); - if (mTask == null) { - mTask = new LoginTask(); - } - if (mXmppFacade == null) { - bindService(LoginAnim.SERVICE_INTENT, mServConn, BIND_AUTO_CREATE); + /** + * Constructor. + */ + ClickListener() { } - } - - @Override - protected void onPause() { - super.onPause(); - if (mXmppFacade != null) { // and async task not en cours - unbindService(mServConn); - mXmppFacade = null; - } - } - - private class ClickListener implements OnClickListener { @Override public void onClick(View v) { @@ -120,14 +118,22 @@ } } + /** + * Asynchronous class for connection. + */ class LoginTask extends AsyncTask { private IXmppConnection mConnection; private String mMsg; + /** + * Constructor. + */ + LoginTask() { + } + @Override protected Boolean doInBackground(IXmppFacade... params) { - Log.d(TAG, "Launch the task"); boolean result = true; IXmppFacade facade = params[0]; try { @@ -138,20 +144,17 @@ mMsg = mConnection.getErrorMessage(); } } catch (RemoteException e) { - Log.d(TAG, "Error while connecting", e); mMsg = "Exception during connection"; result = false; } - Log.d(TAG, "Connection result? " + result); return result; } @Override protected void onPostExecute(Boolean result) { - if (result == null || !result) { // Task cancelled on exception - Log.d(TAG, "Exception or cancelation of the connection"); - if (result == false) { + if (result == null || !result) { // Task cancelled or exception + if (!result) { Intent i = new Intent(); i.putExtra("message", mMsg); LoginAnim.this.setResult(Activity.RESULT_CANCELED, i); @@ -159,6 +162,7 @@ LoginAnim.this.setResult(Activity.RESULT_CANCELED); LoginAnim.this.finish(); } else { + mCancelBt.setEnabled(false); LoginAnim.this.startService(LoginAnim.SERVICE_INTENT); LoginAnim.this.setResult(Activity.RESULT_OK); LoginAnim.this.finish(); @@ -179,8 +183,14 @@ } + /** + * The service connection used to connect to the Beem service. + */ private class LoginServiceConnection implements ServiceConnection { + /** + * Constructor. + */ public LoginServiceConnection() { } @@ -193,7 +203,6 @@ @Override public void onServiceDisconnected(ComponentName name) { - Log.d(TAG, "Service disconnected."); mXmppFacade = null; } } diff -r 5a2e5cf7c8c1 -r a560f82d48b0 src/com/beem/project/beem/utils/BeemConnectivity.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/utils/BeemConnectivity.java Thu Dec 03 10:49:44 2009 +0100 @@ -0,0 +1,46 @@ +package com.beem.project.beem.utils; + +import android.content.Context; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; +import android.net.NetworkInfo.DetailedState; +import android.net.wifi.WifiInfo; +import android.net.wifi.WifiManager; +import android.telephony.TelephonyManager; + +public class BeemConnectivity { + static public boolean isConnected(Context ctx) { + ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo ni = cm.getActiveNetworkInfo(); + return ni.isConnected(); + } + + public static boolean isWifi(Context ctx) { + WifiManager wm = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE); + WifiInfo wi = wm.getConnectionInfo(); + if (wi != null) + return false; + if (wi != null + && (WifiInfo.getDetailedStateOf(wi.getSupplicantState()) == DetailedState.OBTAINING_IPADDR || WifiInfo + .getDetailedStateOf(wi.getSupplicantState()) == DetailedState.CONNECTED)) { + return false; + } + return false; + } + + public static boolean isUmts(Context ctx) { + TelephonyManager tm = (TelephonyManager)ctx.getSystemService(Context.TELEPHONY_SERVICE); + if (tm.getNetworkType() >= TelephonyManager.NETWORK_TYPE_UMTS) + return true; + return false; + } + + public static boolean isEdge(Context ctx) { + TelephonyManager tm = (TelephonyManager)ctx.getSystemService(Context.TELEPHONY_SERVICE); + if (tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_EDGE) + return true; + return false; + } + + +}