Merge.
authormarseille@marseille-desktop
Mon, 22 Jun 2009 15:38:20 +0200
changeset 259 a6c3ccc46968
parent 258 a5a823108e8b
child 260 0ce1e306fdd3
Merge.
src/com/beem/project/beem/ui/ContactList.java
src/com/beem/project/beem/ui/EditSettings.java
src/com/beem/project/beem/ui/Login.java
--- a/src/com/beem/project/beem/ui/ContactList.java	Mon Jun 22 15:37:33 2009 +0200
+++ b/src/com/beem/project/beem/ui/ContactList.java	Mon Jun 22 15:38:20 2009 +0200
@@ -53,6 +53,7 @@
     private Handler mHandler;
     private IXmppFacade xmppFacade = null;
     private final ServiceConnection mServConn = new BeemServiceConnection();
+    private int REQUEST_CODE = 1;
 
     /**
      * Callback for menu creation.
@@ -76,7 +77,7 @@
     public final boolean onOptionsItemSelected(MenuItem item) {
 	switch (item.getItemId()) {
 	    case R.id.contact_list_menu_settings:
-		startActivity(new Intent(this, EditSettings.class));
+		startActivityForResult(new Intent(this, EditSettings.class), REQUEST_CODE);
 		return true;
 	    case R.id.contact_list_menu_add_contact:
 		startActivity(new Intent(ContactList.this, AddContact.class));
@@ -85,6 +86,14 @@
 		return false;
 	}
     }
+    
+    @Override
+    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+	super.onActivityResult(requestCode, resultCode, data);
+	if (requestCode == REQUEST_CODE) {
+	    startActivity(new Intent(ContactList.this, Login.class));
+	}
+    }
 
     @Override
     protected void onCreate(Bundle saveBundle) {
--- a/src/com/beem/project/beem/ui/EditSettings.java	Mon Jun 22 15:37:33 2009 +0200
+++ b/src/com/beem/project/beem/ui/EditSettings.java	Mon Jun 22 15:38:20 2009 +0200
@@ -25,45 +25,42 @@
 
 /**
  * This class represents an activity which allows the user to change his account or proxy parameters
- * 
  * @author dasilvj
  */
 public class EditSettings extends Activity {
 
-    private final static String  LOG_MSG_SETTINGS_SAVED              = "Settings saved successfully.";
-    private final static String  LOG_MSG_XMPP_SETTINGS_REGISTERED    = "XMPP Settings has been registered.";
-    private final static String  LOG_MSG_ACCOUNT_SETTINGS_REGISTERED = "Account Settings has been registered.";
-    private final static String  LOG_MSG_PROXY_SETTINGS_REGISTERED   = "Proxy Settings has been registered.";
+    private final static String LOG_MSG_SETTINGS_SAVED = "Settings saved successfully.";
+    private final static String LOG_MSG_XMPP_SETTINGS_REGISTERED = "XMPP Settings has been registered.";
+    private final static String LOG_MSG_ACCOUNT_SETTINGS_REGISTERED = "Account Settings has been registered.";
+    private final static String LOG_MSG_PROXY_SETTINGS_REGISTERED = "Proxy Settings has been registered.";
 
-    private final static boolean DEFAULT_BOOLEAN_VALUE               = false;
-    private final static String  DEFAULT_STRING_VALUE                = "";
-    private final static int     DEFAULT_INT_VALUE                   = 0;
+    private final static boolean DEFAULT_BOOLEAN_VALUE = false;
+    private final static String DEFAULT_STRING_VALUE = "";
+    private final static int DEFAULT_INT_VALUE = 0;
 
-    private final static String  DEFAULT_XMPP_PORT                   = "5222";
+    private final static String DEFAULT_XMPP_PORT = "5222";
 
-    private final static int     NOTIFICATION_DURATION               = Toast.LENGTH_SHORT;
+    private final static int NOTIFICATION_DURATION = Toast.LENGTH_SHORT;
 
-    private SharedPreferences    settings                            = null;
+    private SharedPreferences settings = null;
 
-    private EditText             accUsernameField                    = null;
-    private EditText             accPasswordField                    = null;
+    private EditText accUsernameField = null;
+    private EditText accPasswordField = null;
 
-    private EditText             xmppServerField                     = null;
-    private EditText             xmppPortField                       = null;
-    private CheckBox             xmppUseTLSCheckBox                  = null;
+    private EditText xmppServerField = null;
+    private EditText xmppPortField = null;
+    private CheckBox xmppUseTLSCheckBox = null;
 
-    private CheckBox             proxyUseCheckBox                    = null;
-    private Spinner              proxyTypeSpinner                    = null;
-    private EditText             proxyServerField                    = null;
-    private EditText             proxyPortField                      = null;
-    private EditText             proxyUsernameField                  = null;
-    private EditText             proxyPasswordField                  = null;
+    private CheckBox proxyUseCheckBox = null;
+    private Spinner proxyTypeSpinner = null;
+    private EditText proxyServerField = null;
+    private EditText proxyPortField = null;
+    private EditText proxyUsernameField = null;
+    private EditText proxyPasswordField = null;
 
     /**
      * Add a labeled "Account" tab on the tabbed window view passed by parameter
-     * 
-     * @param tHost
-     *            a tabbed window view
+     * @param tHost a tabbed window view
      */
     private void addAccountTab(TabHost tHost) {
 	TabHost.TabSpec accountTab = tHost.newTabSpec(getString(R.string.settings_tab_tag_account));
@@ -74,9 +71,7 @@
 
     /**
      * Add a labeled "Proxy" tab on the tabbed window view passed by parameter
-     * 
-     * @param tHost
-     *            a tabbed window view
+     * @param tHost a tabbed window view
      */
     private void addProxyTab(TabHost tHost) {
 	TabHost.TabSpec proxyTab = tHost.newTabSpec(getString(R.string.settings_tab_tag_proxy));
@@ -87,9 +82,7 @@
 
     /**
      * Add a labeled "XMPP" tab on the tabbed window view passed by parameter
-     * 
-     * @param tHost
-     *            a tabbed window view
+     * @param tHost a tabbed window view
      */
     private void addXMPPTab(TabHost tHost) {
 	TabHost.TabSpec personalTab = tHost.newTabSpec(getString(R.string.settings_tab_tag_xmpp));
@@ -127,7 +120,6 @@
 
     /**
      * Retrieve the value of a CheckBox
-     * 
      * @param viewId
      * @return true if the CheckBox is checked, else false
      */
@@ -140,7 +132,6 @@
 
     /**
      * Retrieve account password from the preferences
-     * 
      * @return Registered account password
      */
     private String getRegisteredAccountPassword() {
@@ -149,7 +140,6 @@
 
     /**
      * Retrieve account username from the preferences
-     * 
      * @return Registered account username
      */
     private String getRegisteredAccountUsername() {
@@ -158,7 +148,6 @@
 
     /**
      * Retrieve proxy password from the preferences
-     * 
      * @return Registered proxy password
      */
     private String getRegisteredProxyPassword() {
@@ -167,7 +156,6 @@
 
     /**
      * Retrieve proxy port from the preferences
-     * 
      * @return Registered proxy port
      */
     private String getRegisteredProxyPort() {
@@ -176,7 +164,6 @@
 
     /**
      * Retrieve proxy server from the preferences
-     * 
      * @return Registered proxy server
      */
     private String getRegisteredProxyServer() {
@@ -185,7 +172,6 @@
 
     /**
      * Retrieve proxy type from the preferences
-     * 
      * @return Registered proxy type
      */
     private int getRegisteredProxyType() {
@@ -194,7 +180,6 @@
 
     /**
      * Retrieve proxy use from the preferences
-     * 
      * @return Registered proxy use
      */
     private boolean getRegisteredProxyUse() {
@@ -203,7 +188,6 @@
 
     /**
      * Retrieve proxy username from the preferences
-     * 
      * @return Registered proxy username
      */
     private String getRegisteredProxyUsername() {
@@ -212,7 +196,6 @@
 
     /**
      * Retrieve xmpp port from the preferences
-     * 
      * @return Registered xmpp port
      */
     private String getRegisteredXMPPPort() {
@@ -221,7 +204,6 @@
 
     /**
      * Retrieve xmpp server from the preferences
-     * 
      * @return Registered xmpp server
      */
     private String getRegisteredXMPPServer() {
@@ -230,7 +212,6 @@
 
     /**
      * Retrieve TLS use from the preferences
-     * 
      * @return Registered TLS use
      */
     private boolean getRegisteredXMPPTLSUse() {
@@ -271,7 +252,7 @@
      */
     private void initProxyTypesSpinner() {
 	ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.proxy_types,
-	        android.R.layout.simple_spinner_item);
+	    android.R.layout.simple_spinner_item);
 	adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
 	proxyTypeSpinner.setAdapter(adapter);
     }
@@ -370,6 +351,7 @@
 	    startActivity(i);
 	    return true;
 	case R.id.settings_menu_login:
+	    setResult(69);
 	    finish();
 	    return true;
 	}
@@ -432,7 +414,6 @@
 
     /**
      * Register account settings changes in SharedPreferences.Editor object passed by parameter
-     * 
      * @param settingsEditor
      */
     private void registerAccountSettingsChanges(SharedPreferences.Editor settingsEditor) {
@@ -448,7 +429,6 @@
 
     /**
      * Register proxy settings changes in SharedPreferences.Editor object passed by parameter
-     * 
      * @param settingsEditor
      */
     private void registerProxySettingsChanges(SharedPreferences.Editor settingsEditor) {
@@ -473,7 +453,6 @@
 
     /**
      * Register XMPP settings changes in SharedPreferences.Editor object passed by parameter
-     * 
      * @param settingsEditor
      */
     private void registerXMPPSettingsChanges(SharedPreferences.Editor settingsEditor) {
--- a/src/com/beem/project/beem/ui/Login.java	Mon Jun 22 15:37:33 2009 +0200
+++ b/src/com/beem/project/beem/ui/Login.java	Mon Jun 22 15:38:20 2009 +0200
@@ -42,6 +42,8 @@
     private final ServiceConnection mServConn = new BeemServiceConnection();
     private IXmppFacade xmppFacade = null;
 
+    private int REQUEST_CODE = 1;
+
     /**
      * Create an about "BEEM" dialog
      */
@@ -70,7 +72,7 @@
 
 	    @Override
 	    public void onClick(View v) {
-		startActivity(new Intent(Login.this, EditSettings.class));
+		startActivityForResult(new Intent(Login.this, EditSettings.class), REQUEST_CODE);
 	    }
 
 	});
@@ -88,7 +90,8 @@
     @Override
     protected void onDestroy() {
 	super.onDestroy();
-	unbindService(mServConn);
+	if (mIsConnected)
+	    unbindService(mServConn);
     }
 
     /**
@@ -122,33 +125,37 @@
 
 	@Override
 	public void connectionClosed() throws RemoteException {
-	    mIsConnected = false;
-	    Login.this.unbindService(mServConn);
-	    Login.this.stopService(SERVICE_INTENT);
+	    if (mIsConnected) {
+		mIsConnected = false;
+		Login.this.unbindService(mServConn);
+		Login.this.stopService(SERVICE_INTENT);
+	    }
 	}
 
 	@Override
 	public void connectionClosedOnError() throws RemoteException {
-	    mIsConnected = false;
-	    Login.this.unbindService(mServConn);
-	    Login.this.stopService(SERVICE_INTENT);
+	    if (mIsConnected) {
+		mIsConnected = false;
+		Login.this.unbindService(mServConn);
+		Login.this.stopService(SERVICE_INTENT);
+	    }
 	}
 
 	@Override
 	public void connectionFailed(String errorMsg) throws RemoteException {
-	    connectionHandler.post(new ErrorRunnable(errorMsg));
 	    mIsConnected = false;
 	    Login.this.unbindService(mServConn);
 	    Login.this.stopService(SERVICE_INTENT);
+	    connectionHandler.post(new ErrorRunnable(errorMsg));
 	    dismissProgressDialog();
 	    showToast(errorMsg);
 	}
-	
+
 	private void showToast(final String errorMsg) {
 	    connectionHandler.post(new Runnable() {
 		@Override
 		public void run() {
-		    Toast.makeText(Login.this, errorMsg, Toast.LENGTH_SHORT).show();		    
+		    Toast.makeText(Login.this, errorMsg, Toast.LENGTH_SHORT).show();
 		}
 	    });
 	}