Reconnection
authorMarseille
Wed, 01 Jul 2009 17:51:06 +0200
changeset 326 c5f000965df8
parent 325 cb5293558d3c
child 327 eb633aedfdba
child 330 52e3cbc03730
Reconnection
res/layout/sendim.xml
src/com/beem/project/beem/BeemService.java
src/com/beem/project/beem/ui/ContactList.java
src/com/beem/project/beem/ui/CreateAccount.java
src/com/beem/project/beem/ui/EditSettings.java
src/com/beem/project/beem/ui/Login.java
src/com/beem/project/beem/ui/SendIM.java
--- a/res/layout/sendim.xml	Wed Jul 01 16:21:16 2009 +0200
+++ b/res/layout/sendim.xml	Wed Jul 01 17:51:06 2009 +0200
@@ -15,8 +15,7 @@
 			android:layout_width="fill_parent" android:layout_height="wrap_content">
 			<TextView android:id="@+id/sendimlogin"
 				android:layout_width="fill_parent" android:layout_height="wrap_content"
-				android:lines="1"
-				android:paddingLeft="10sp" />
+				android:lines="1" android:paddingLeft="10sp" />
 			<TextView android:id="@+id/sendimchatstate"
 				android:layout_width="fill_parent" android:layout_height="wrap_content"
 				android:lines="1" android:scrollHorizontally="true"
@@ -24,7 +23,8 @@
 			<TextView android:id="@+id/sendimstatus"
 				android:layout_width="fill_parent" android:layout_height="wrap_content"
 				android:lines="1" android:scrollHorizontally="true"
-				android:hint="@string/SendIMNoStatusSet" android:paddingLeft="15sp" />
+				android:hint="@string/SendIMNoStatusSet" android:paddingLeft="15sp"
+				android:autoLink="all" />
 		</LinearLayout>
 	</LinearLayout>
 
@@ -37,7 +37,7 @@
 		<TextView android:id="@+id/sendimlist" android:paddingLeft="10px"
 			android:paddingRight="10px" android:paddingTop="10px"
 			android:layout_width="fill_parent" android:layout_height="fill_parent"
-			android:singleLine="false"/>
+			android:singleLine="false" />
 
 	</ScrollView>
 
--- a/src/com/beem/project/beem/BeemService.java	Wed Jul 01 16:21:16 2009 +0200
+++ b/src/com/beem/project/beem/BeemService.java	Wed Jul 01 17:51:06 2009 +0200
@@ -11,6 +11,7 @@
 import org.jivesoftware.smack.packet.Presence;
 import org.jivesoftware.smack.proxy.ProxyInfo;
 import org.jivesoftware.smack.proxy.ProxyInfo.ProxyType;
+import org.jivesoftware.smack.util.StringUtils;
 
 import android.app.Notification;
 import android.app.NotificationManager;
@@ -31,9 +32,8 @@
 import com.beem.project.beem.ui.Subscription;
 
 /**
- * This class is for the Beem service. The connection to the xmpp server will be made asynchronously
- * when the service will start.
- * 
+ * This class is for the Beem service. The connection to the xmpp server will be made asynchronously when the service
+ * will start.
  * @author darisk
  */
 public class BeemService extends Service {
@@ -41,20 +41,20 @@
     /**
      * The id to use for status notification.
      */
-    public static final int         NOTIFICATION_STATUS_ID = 100;
+    public static final int NOTIFICATION_STATUS_ID = 100;
 
-    private NotificationManager     mNotificationManager;
-    private XmppConnectionAdapter   mConnection;
-    private SharedPreferences       mSettings;
-    private String                  mLogin;
-    private String                  mPassword;
-    private String                  mHost;
-    private String                  mService;
-    private int                     mPort;
+    private NotificationManager mNotificationManager;
+    private XmppConnectionAdapter mConnection;
+    private SharedPreferences mSettings;
+    private String mLogin;
+    private String mPassword;
+    private String mHost;
+    private String mService;
+    private int mPort;
     private ConnectionConfiguration mConnectionConfiguration;
-    private ProxyInfo               mProxyInfo;
-    private boolean                 mUseProxy;
-    private IXmppFacade.Stub        mBind;
+    private ProxyInfo mProxyInfo;
+    private boolean mUseProxy;
+    private IXmppFacade.Stub mBind;
 
     /**
      * Constructor.
@@ -157,10 +157,8 @@
 			    notif.flags = Notification.FLAG_AUTO_CANCEL;
 			    Intent intent = new Intent(BeemService.this, Subscription.class);
 			    intent.putExtra("from", from);
-			    notif
-			    .setLatestEventInfo(BeemService.this, from, "demande d'ajout de " + from,
-				PendingIntent.getActivity(BeemService.this, 0, intent,
-				    PendingIntent.FLAG_ONE_SHOT));
+			    notif.setLatestEventInfo(BeemService.this, from, "demande d'ajout de " + from,
+				PendingIntent.getActivity(BeemService.this, 0, intent, PendingIntent.FLAG_ONE_SHOT));
 			    int id = packet.hashCode();
 			    sendNotification(id, notif);
 			}
@@ -238,12 +236,17 @@
 	mPort = Integer.parseInt(mSettings.getString(getString(R.string.settings_key_xmpp_port), "5222"));
 
 	Log.i("BEEEMSERVICE", mLogin);
-	if (mHost.equals("talk.google.com"))
-	    mService = "gmail.com";
-	else
+	/*
+	 * Gestion pour gmail.
+	 */
+	if ("".equals(mHost)) {
+	    mHost = StringUtils.parseServer(mLogin);
 	    mService = null;
+	    mLogin = StringUtils.parseName(mLogin);
+	} else
+	    mService = StringUtils.parseServer(mLogin);
 	initConnectionConfig();
-	mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);	
+	mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
 	mConnection = new XmppConnectionAdapter(mConnectionConfiguration, mLogin, mPassword, this);
 	initRosterRequestListener();
 	mBind = new XmppFacade(mConnection, this);
@@ -276,11 +279,8 @@
 
     /**
      * Show a notification.
-     * 
-     * @param id
-     *            the id of the notification.
-     * @param notif
-     *            the notification to show
+     * @param id the id of the notification.
+     * @param notif the notification to show
      */
     public void sendNotification(int id, Notification notif) {
 	mNotificationManager.notify(id, notif);
--- a/src/com/beem/project/beem/ui/ContactList.java	Wed Jul 01 16:21:16 2009 +0200
+++ b/src/com/beem/project/beem/ui/ContactList.java	Wed Jul 01 17:51:06 2009 +0200
@@ -19,6 +19,7 @@
 import android.os.Handler;
 import android.os.IBinder;
 import android.os.RemoteException;
+import android.provider.Settings.System;
 import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.Menu;
@@ -93,6 +94,7 @@
 	if (requestCode == REQUEST_CODE) {
 	    if (resultCode == 69) {
 		finish();
+		stopService(new Intent(this, BeemService.class));
 		startActivity(new Intent(this, Login.class));
 	    }
 	}
@@ -171,17 +173,17 @@
 
 	@Override
 	public void onEntriesAdded(List<String> addresses) throws RemoteException {
-	    //Log.d("CONTACTLIST", "DEBUG - ONENTRIESADDED()"+ addresses.size());
+	    // Log.d("CONTACTLIST", "DEBUG - ONENTRIESADDED()"+ addresses.size());
 	    for (String str : addresses) {
 		Contact curContact = mRoster.getContact(str);
-		//Log.d("CONTACTLIST", "DEBUG - ONENTRIESADDED() group size " + curContact.getGroups().size() );
+		// Log.d("CONTACTLIST", "DEBUG - ONENTRIESADDED() group size " + curContact.getGroups().size() );
 		for (String group : curContact.getGroups()) {
 		    if (!groupMap.containsKey(group)) {
 			groupMap.put(group, new ArrayList<Contact>());
 			groupName.add(group);
 		    }
 		    try {
-			//Log.d("CONTACTLIST", "DEBUG - ONENTRIESADD");
+			// Log.d("CONTACTLIST", "DEBUG - ONENTRIESADD");
 			groupMap.get(group).add(curContact);
 		    } catch (NullPointerException e) {
 			Log.e(TAG, "Failed to find group in groupMap", e);
@@ -193,7 +195,7 @@
 
 	@Override
 	public void onEntriesDeleted(List<String> addresses) throws RemoteException {
-	    //Log.d("CONTACTLIST", "DEBUG - ONENTRIESDELETED() " + addresses.get(0));
+	    // Log.d("CONTACTLIST", "DEBUG - ONENTRIESDELETED() " + addresses.get(0));
 	    for (String user : addresses) {
 		List<Contact> tmpListContact = groupMap.get(DEFAULT_GROUP);
 		for (Contact contact : tmpListContact) {
@@ -210,14 +212,14 @@
 
 	@Override
 	public void onEntriesUpdated(List<String> addresses) throws RemoteException {
-	   // Log.d("CONTACTLIST", "DEBUG - ONENTRIESUPDATED()");
+	    // Log.d("CONTACTLIST", "DEBUG - ONENTRIESUPDATED()");
 	    for (String str : addresses) {
 		Contact curContact = mRoster.getContact(str);
 		for (String group : curContact.getGroups()) {
 		    if (!groupMap.containsKey(group)) {
 			groupMap.put(group, new ArrayList<Contact>());
 			groupName.add(group);
-			//Log.d("CONTACTLIST", "DEBUG - ONENTRIESUPDATED() found");
+			// Log.d("CONTACTLIST", "DEBUG - ONENTRIESUPDATED() found");
 			groupMap.get(group).add(curContact);
 		    } else {
 			boolean found = false;
@@ -228,7 +230,7 @@
 			    }
 			}
 			if (!found) {
-			    //Log.d("CONTACTLIST", "DEBUG - ONENTRIESUPDATED() not found");
+			    // Log.d("CONTACTLIST", "DEBUG - ONENTRIESUPDATED() not found");
 			    groupMap.get(group).add(curContact);
 			}
 		    }
@@ -239,7 +241,7 @@
 
 	@Override
 	public void onPresenceChanged(PresenceAdapter presence) throws RemoteException {
-	    //Log.d("CONTACTLIST", "DEBUG - ONPRESENCECHANGED()");
+	    // Log.d("CONTACTLIST", "DEBUG - ONPRESENCECHANGED()");
 	    for (Contact curContact : mListContact) {
 		if (curContact.getJID().equals(StringUtils.parseBareAddress(presence.getFrom()))) {
 		    curContact.setStatus(mRoster.getPresence(StringUtils.parseBareAddress(presence.getFrom())));
@@ -258,7 +260,7 @@
 
 	@Override
 	public void onEntryDeleteFromGroup(String group, String jid) throws RemoteException {
-	    //Log.d("CONTACTLIST", "DEBUG - ONENTRYDELETEFROMGROUP()");
+	    // Log.d("CONTACTLIST", "DEBUG - ONENTRYDELETEFROMGROUP()");
 	    for (Contact contact : mListContact) {
 		if (jid.equals(contact.getJID())
 		    && (contact.getGroups().contains(group) || contact.getGroups().size() == 0)) {
@@ -357,10 +359,10 @@
 			break;
 		    default:
 			imageDrawable = getResources().getDrawable(R.drawable.error);
-		    break;
+			break;
 		}
 		imgV.setImageDrawable(imageDrawable);
-		
+
 		String mContactName = curContact.getName();
 		if ("".equals(mContactName)) {
 		    mContactName = curContact.getJID();
--- a/src/com/beem/project/beem/ui/CreateAccount.java	Wed Jul 01 16:21:16 2009 +0200
+++ b/src/com/beem/project/beem/ui/CreateAccount.java	Wed Jul 01 17:51:06 2009 +0200
@@ -239,7 +239,6 @@
 		String usernameFieldValue = ((EditText) findViewById(R.id.create_account_username)).getText()
 		    .toString();
 		String username = StringUtils.parseName(usernameFieldValue);
-		String server= StringUtils.parseServer(usernameFieldValue);
 		String passwordFieldValue = ((EditText) findViewById(R.id.create_account_password)).getText()
 		    .toString();
 		if (!checkEmail())
@@ -249,8 +248,7 @@
 		else {
 		    if (createAccount(username, passwordFieldValue)) {
 			SharedPreferences.Editor settingsEditor = settings.edit();
-			settingsEditor.putString(getString(R.string.settings_key_account_username), username);
-			settingsEditor.putString(getString(R.string.settings_account_server), server);
+			settingsEditor.putString(getString(R.string.settings_key_account_username), usernameFieldValue);
 			settingsEditor.putString(getString(R.string.settings_key_account_password), passwordFieldValue);
 			settingsEditor.commit();
 			finish();
--- a/src/com/beem/project/beem/ui/EditSettings.java	Wed Jul 01 16:21:16 2009 +0200
+++ b/src/com/beem/project/beem/ui/EditSettings.java	Wed Jul 01 17:51:06 2009 +0200
@@ -505,9 +505,8 @@
 	String password = accPasswordField.getText().toString();
 	String username = accUsernameField.getText().toString();
 	String port = xmppPortField.getText().toString();
-	String server = xmppServerField.getText().toString();
 	if("".equals(password) || "".equals(username)
-	    || "".equals(port) || "".equals(server))
+	    || "".equals(port))
 	    settingsEditor.putBoolean(getString(R.string.PreferenceIsConfigured), false);
 	else
 	    settingsEditor.putBoolean(getString(R.string.PreferenceIsConfigured), true);
--- a/src/com/beem/project/beem/ui/Login.java	Wed Jul 01 16:21:16 2009 +0200
+++ b/src/com/beem/project/beem/ui/Login.java	Wed Jul 01 17:51:06 2009 +0200
@@ -44,10 +44,10 @@
     private boolean mIsConnected = false;
     private final ServiceConnection mServConn = new BeemServiceConnection();
     private IXmppFacade xmppFacade = null;
-    
+
     private SharedPreferences settings = null;
     private boolean isConfigured = false;
-    
+
     private Button mButtonLogin = null;
 
     /**
@@ -111,10 +111,12 @@
 	super.onStart();
 	Log.e("LOGIN", "BINDSERVICE");
 	isConfigured = settings.getBoolean(getString(R.string.PreferenceIsConfigured), false);
+
 	if (isConfigured)
 	    bindService(Login.SERVICE_INTENT, mServConn, BIND_AUTO_CREATE);
 	else
 	    mButtonLogin.setEnabled(false);
+
     }
 
     private class BeemConnectionListener extends IBeemConnectionListener.Stub {
--- a/src/com/beem/project/beem/ui/SendIM.java	Wed Jul 01 16:21:16 2009 +0200
+++ b/src/com/beem/project/beem/ui/SendIM.java	Wed Jul 01 17:51:06 2009 +0200
@@ -42,8 +42,7 @@
 import com.beem.project.beem.service.aidl.IXmppFacade;
 
 /**
- * This activity class provides the view for instant messaging after selecting a
- * correspondant.
+ * This activity class provides the view for instant messaging after selecting a correspondant.
  * @author barbu
  */
 
@@ -220,7 +219,7 @@
     protected void onPause() {
 	super.onPause();
 	try {
-	    if (mChat!=null)
+	    if (mChat != null)
 		mChat.setOpen(false);
 	} catch (RemoteException e) {
 	    Log.d(TAG, "Error while closing chat", e);
@@ -234,8 +233,7 @@
     @Override
     protected void onResume() {
 	super.onResume();
-	bindService(new Intent(this, BeemService.class), mServConn,
-		BIND_AUTO_CREATE);
+	bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
 	mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
     }
 
@@ -272,9 +270,10 @@
 		if (mRoster != null) {
 		    mRoster.addRosterListener(mBeemRosterListener);
 		    // mContact.setStatus(mRoster.getPresence(mContact.getJID()));
-		    mContact = mRoster.getContact(mContact.getJID());
-		    mStatusText.setText(mContact.getMsgState());
-		    Linkify.addLinks(mStatusText, Linkify.WEB_URLS);
+		    if (mRoster.getContact(mContact.getJID()) != null) {
+			mContact = mRoster.getContact(mContact.getJID());
+			mStatusText.setText(mContact.getMsgState());
+		    }
 		}
 		switchChat(mContact);
 	    } catch (RemoteException e) {
@@ -294,9 +293,8 @@
     }
 
     /**
-     * Send a message to the contact over the XMPP connection. Also display it
-     * on activity view. TODO : Gerer l'exception si la connexion se coupe
-     * pendant la conversation
+     * Send a message to the contact over the XMPP connection. Also display it on activity view. TODO : Gerer
+     * l'exception si la connexion se coupe pendant la conversation
      */
     private void sendText() {
 	String text = mToSend.getText().toString();
@@ -324,8 +322,7 @@
 
     /**
      * Show the message history.
-     * @param messages
-     *            list of message to display
+     * @param messages list of message to display
      */
     private void showMessageList(List<Message> messages) {
 	mText.setText("");
@@ -351,10 +348,8 @@
 
     /**
      * Change the correspondant of the chat.
-     * @param newContact
-     *            New contact to chat with
-     * @throws RemoteException
-     *             if an errors occurs in the connection with the service
+     * @param newContact New contact to chat with
+     * @throws RemoteException if an errors occurs in the connection with the service
      */
     private void switchChat(Contact newContact) throws RemoteException {
 	if (mChat != null)
@@ -375,8 +370,7 @@
 	 * {@inheritDoc}
 	 */
 	@Override
-	public void chatCreated(IChat chat, boolean locally)
-		throws RemoteException {
+	public void chatCreated(IChat chat, boolean locally) throws RemoteException {
 	    Log.i("LOG", "chatCreated");
 	}
 
@@ -385,33 +379,27 @@
     private class BeemRosterListener extends IBeemRosterListener.Stub {
 
 	@Override
-	public void onEntriesAdded(List<String> addresses)
-		throws RemoteException {
-	    // TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public void onEntriesDeleted(List<String> addresses)
-		throws RemoteException {
+	public void onEntriesAdded(List<String> addresses) throws RemoteException {
 	    // TODO Auto-generated method stub
 
 	}
 
 	@Override
-	public void onEntriesUpdated(List<String> addresses)
-		throws RemoteException {
+	public void onEntriesDeleted(List<String> addresses) throws RemoteException {
 	    // TODO Auto-generated method stub
 
 	}
 
 	@Override
-	public void onPresenceChanged(PresenceAdapter presence)
-		throws RemoteException {
-	    if (mContact.getJID().equals(
-		    StringUtils.parseBareAddress(presence.getFrom()))) {
-		mContact.setStatus(mRoster.getPresence(StringUtils
-			.parseBareAddress(presence.getFrom())));
+	public void onEntriesUpdated(List<String> addresses) throws RemoteException {
+	    // TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void onPresenceChanged(PresenceAdapter presence) throws RemoteException {
+	    if (mContact.getJID().equals(StringUtils.parseBareAddress(presence.getFrom()))) {
+		mContact.setStatus(mRoster.getPresence(StringUtils.parseBareAddress(presence.getFrom())));
 		mHandler.post(new RunnableChange());
 	    }
 	}
@@ -425,8 +413,7 @@
 	}
 
 	@Override
-	public void onEntryDeleteFromGroup(String group, String jid)
-		throws RemoteException {
+	public void onEntryDeleteFromGroup(String group, String jid) throws RemoteException {
 	    // TODO Auto-generated method stub
 
 	}
@@ -443,8 +430,7 @@
 	 * {@inheritDoc}
 	 */
 	@Override
-	public void processMessage(IChat chat, Message msg)
-		throws RemoteException {
+	public void processMessage(IChat chat, Message msg) throws RemoteException {
 
 	    if (chat != mChat)
 		return;
@@ -478,8 +464,7 @@
 	    if (chat != mChat)
 		return;
 	    final String state = chat.getState();
-	    Log.d("ChatState", "Action du correspondant : <--- "
-		    + chat.getState() + " --->");
+	    Log.d("ChatState", "Action du correspondant : <--- " + chat.getState() + " --->");
 	    mHandler.post(new Runnable() {
 
 		@Override