# HG changeset patch # User nikita@nikita-rack # Date 1239127950 -7200 # Node ID ff92a9c95c78c5899bd4e7fd3e2f3e0150e195a0 # Parent b99c01522c62c2f05bcf5fb4ab7281adecf457db# Parent eb9112a00b024f176cb9cf8ce8a676727ca03370 merge avec beem-ui diff -r eb9112a00b02 -r ff92a9c95c78 res/values/strings.xml --- a/res/values/strings.xml Tue Apr 07 19:07:41 2009 +0200 +++ b/res/values/strings.xml Tue Apr 07 20:12:30 2009 +0200 @@ -17,6 +17,15 @@ host Jabber IDloginpassword port + proxy_host + proxy_port + use_proxy + proxy_type + proxy_user + proxy_password + HTTP + SOCKS4 + SOCKS5 says :\n diff -r eb9112a00b02 -r ff92a9c95c78 src/com/beem/project/beem/BeemService.java --- a/src/com/beem/project/beem/BeemService.java Tue Apr 07 19:07:41 2009 +0200 +++ b/src/com/beem/project/beem/BeemService.java Tue Apr 07 20:12:30 2009 +0200 @@ -1,20 +1,19 @@ package com.beem.project.beem; +import org.jivesoftware.smack.ConnectionConfiguration; +import org.jivesoftware.smack.proxy.ProxyInfo; +import org.jivesoftware.smack.proxy.ProxyInfo.ProxyType; import android.app.Notification; import android.app.NotificationManager; -import android.app.PendingIntent; import android.app.Service; import android.content.Intent; import android.content.SharedPreferences; import android.os.IBinder; import android.os.RemoteException; -import android.widget.Toast; - import com.beem.project.beem.service.XmppConnectionAdapter; import com.beem.project.beem.service.XmppFacade; -import com.beem.project.beem.service.aidl.IBeemConnectionListener; +import com.beem.project.beem.service.aidl.IXmppConnection; import com.beem.project.beem.service.aidl.IXmppFacade; -import com.beem.project.beem.service.aidl.IXmppConnection; /** * This class is for the Beem service. @@ -35,8 +34,9 @@ private String mLogin; private String mPassword; private String mHost; - - + private ConnectionConfiguration mConnectionConfiguration; + private ProxyInfo mProxyInfo; + private boolean mUseProxy; private IXmppFacade.Stub mBind; /** @@ -65,12 +65,36 @@ mLogin = mSettings.getString(getString(R.string.PreferenceLoginKey), ""); mPassword = mSettings.getString(getString(R.string.PreferencePasswordKey), ""); mHost = mSettings.getString(getString(R.string.PreferenceHostKey), ""); + mHost = "10.0.2.2"; + initConnectionConfig(); mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); - mConnection = new XmppConnectionAdapter("10.0.2.2", mLogin, mPassword); // address + mConnection = new XmppConnectionAdapter(mConnectionConfiguration, mLogin, mPassword); mBind = new XmppFacade(mConnection, this); } /** + * Initialise la configuration de la connexion. + */ + private void initConnectionConfig() { + //TODO mettre a false par defaut et remplacer les valeurs par defaut + mUseProxy = mSettings.getBoolean(getString(R.string.PreferenceUseProxy), false); + if (mUseProxy) { + String stype = mSettings.getString(getString(R.string.PreferenceProxyType), + getString(R.string.PreferenceProxyTypeHttp)); + String phost = mSettings.getString(getString(R.string.PreferenceProxyHost), ""); + String puser = mSettings.getString(getString(R.string.PreferenceProxyUser), ""); + String ppass = mSettings.getString(getString(R.string.PreferenceProxyPassword), ""); + int pport = mSettings.getInt(getString(R.string.PreferenceProxyPort), 3128); + ProxyInfo.ProxyType type = ProxyType.valueOf(stype); + mProxyInfo = new ProxyInfo(type, phost, pport, puser, ppass); + mConnectionConfiguration = new ConnectionConfiguration(mHost, mProxyInfo); + } else { + mConnectionConfiguration = new ConnectionConfiguration(mHost); + } + mConnectionConfiguration.setSendPresence(false); + } + + /** * {@inheritDoc} */ @Override diff -r eb9112a00b02 -r ff92a9c95c78 src/com/beem/project/beem/service/Contact.java --- a/src/com/beem/project/beem/service/Contact.java Tue Apr 07 19:07:41 2009 +0200 +++ b/src/com/beem/project/beem/service/Contact.java Tue Apr 07 20:12:30 2009 +0200 @@ -20,12 +20,36 @@ */ public class Contact implements Parcelable { + /** + * Status of a disconnected contact. + */ public static final int CONTACT_STATUS_DISCONNECT = 100; + + /** + * Status of a unavailable (long away) contact. + */ public static final int CONTACT_STATUS_UNAVAILABLE = 200; + + /** + * Status of a away contact. + */ public static final int CONTACT_STATUS_AWAY = 300; + + /** + * Status of a busy contact. + */ public static final int CONTACT_STATUS_BUSY = 400; + + /** + * Status of a available contact. + */ public static final int CONTACT_STATUS_AVAILABLE = 500; + + /** + * Status of a available for chat contact. + */ public static final int CONTACT_STATUS_AVAILABLE_FOR_CHAT = 600; + private static final String TAG = "Contact"; private int mID; @@ -51,9 +75,26 @@ }; /** + * Constructor. + */ + public Contact() { + // TODO Auto-generated constructor stub + } + + /** + * Constructor. + * @param jid JID of the contact + */ + public Contact(final String jid) { + mJID = jid; + mStatus = Contact.CONTACT_STATUS_DISCONNECT; + mRes = new ArrayList(); + mRes.add("none"); + } + + /** * Construct a contact from a parcel. - * @param in - * parcel to use for construction + * @param in parcel to use for construction */ private Contact(final Parcel in) { mID = in.readInt(); @@ -86,25 +127,7 @@ } /** - * Constructor. - */ - public Contact() { - // TODO Auto-generated constructor stub - } - - /** - * Constructor. - * @param jid - * JID of the contact - */ - public Contact(final String jid) { - mJID = jid; - mStatus = Contact.CONTACT_STATUS_DISCONNECT; - mRes = new ArrayList(); - mRes.add("none"); - } - - /** + * Get the id of the contact on the phone contact list. * @return the mID */ public int getID() { @@ -112,14 +135,15 @@ } /** - * @param mid - * the mID to set + * set the id of te contact on the phone contact list. + * @param mid the mID to set */ public void setID(int mid) { mID = mid; } /** + * Get the status of the contact. * @return the mStatus */ public int getStatus() { @@ -127,22 +151,22 @@ } /** - * @param status - * the mStatus to set + * Set the status of the contact. + * @param status the mStatus to set */ public void setStatus(int status) { mStatus = status; } /** - * @param presence - * the presence containing status + * Set the status of the contact using a presence packet. + * @param presence the presence containing status */ public void setStatus(Presence presence) { - Log.i(TAG, "NIKITAAAA"); - /* presence.isAvailable() !?!? */ - if (presence.getType().equals(Presence.Type.available)) { - mStatus = Contact.CONTACT_STATUS_AVAILABLE; + if (presence.getType().equals(Presence.Type.unavailable)) { + Log.d(TAG, "Presence pas dispo"); + mStatus = Contact.CONTACT_STATUS_DISCONNECT; + } else { Log.d(TAG, "Presence OK"); Mode mode = presence.getMode(); switch (mode) { @@ -163,27 +187,25 @@ break; default: Log.e("RosterAdapter", "Status mode non gere"); - mStatus = Contact.CONTACT_STATUS_AVAILABLE; + mStatus = Contact.CONTACT_STATUS_DISCONNECT; break; } - } else { - Log.d(TAG, "Presence pas dispo"); - mStatus = Contact.CONTACT_STATUS_DISCONNECT; } } /** - * @return the mMsgState + * Get the message status of the contact. + * @return the message status of the contact. */ - public String getMMsgState() { + public String getMsgState() { return mMsgState; } /** - * @param msgState - * the mMsgState to set + * Set the message status of the contact. + * @param msgState the message status of the contact to set */ - public void setMMsgState(String msgState) { + public void setMsgState(String msgState) { mMsgState = msgState; } @@ -197,25 +219,31 @@ /** * Set the Jabber ID of the contact. - * @param mjid - * the jabber ID to set + * @param mjid the jabber ID to set */ public void setJID(String mjid) { mJID = mjid; } + /** + * + * @param res + */ public void addRes(String res) { if (!mRes.contains(res)) mRes.add(res); } + /** + * + * @param res + */ public void delRes(String res) { mRes.remove(res); } /** - * @param mRes - * the mRes to set + * @param mRes the mRes to set */ public void setMRes(List mRes) { this.mRes = mRes; diff -r eb9112a00b02 -r ff92a9c95c78 src/com/beem/project/beem/service/RosterAdapter.java --- a/src/com/beem/project/beem/service/RosterAdapter.java Tue Apr 07 19:07:41 2009 +0200 +++ b/src/com/beem/project/beem/service/RosterAdapter.java Tue Apr 07 20:12:30 2009 +0200 @@ -46,16 +46,22 @@ roster.addRosterListener(mRosterListener); for (RosterEntry entry : roster.getEntries()) { String user = StringUtils.parseBareAddress(entry.getUser()); - if ( !mContacts.containsKey(user)) + if (!mContacts.containsKey(user)) mContacts.put(user, new Contact(user)); } } + /** + * {@inheritDoc} + */ @Override public void createGroup(String groupname) throws RemoteException { mAdaptee.createGroup(groupname); } + /** + * {@inheritDoc} + */ @Override public Contact addContact(String user, String name, String[] groups) throws RemoteException { try { @@ -76,18 +82,27 @@ mContacts.remove(contact.getJID()); } + /** + * {@inheritDoc} + */ @Override public void addConnectionListener(IBeemRosterListener listen) throws RemoteException { if (listen != null) mRemoteRosListeners.register(listen); } + /** + * {@inheritDoc} + */ @Override public void removeConnectionListener(IBeemRosterListener listen) throws RemoteException { if (listen != null) mRemoteRosListeners.unregister(listen); } + /** + * {@inheritDoc} + */ @Override public Contact getContact(String jid) throws RemoteException { return mContacts.get(jid); @@ -103,8 +118,24 @@ return res; } + /** + * Listener for the roster events. + * It will call the remote listeners registered. + * @author darisk + * + */ private class RosterListenerAdapter implements RosterListener { + /** + * Constructor. + */ + public RosterListenerAdapter() { + // TODO Auto-generated constructor stub + } + + /** + * {@inheritDoc} + */ @Override public void entriesAdded(Collection addresses) { Log.i(TAG, "Ajout de l'entry"); @@ -125,6 +156,9 @@ mRemoteRosListeners.finishBroadcast(); } + /** + * {@inheritDoc} + */ @Override public void entriesDeleted(Collection addresses) { Log.i(TAG, "Suppression de l'entry"); @@ -142,9 +176,12 @@ Log.w(TAG, "Error while deleting roster entries", e); } } - mRemoteRosListeners.finishBroadcast(); + mRemoteRosListeners.finishBroadcast(); } + /** + * {@inheritDoc} + */ @Override public void entriesUpdated(Collection addresses) { Log.i(TAG, "Update de l'entry"); @@ -162,15 +199,18 @@ Log.w(TAG, "Error while updating roster entries", e); } } - mRemoteRosListeners.finishBroadcast(); + mRemoteRosListeners.finishBroadcast(); } + /** + * {@inheritDoc} + */ @Override public void presenceChanged(Presence presence) { Log.i(TAG, "Changement de Presence"); /* gestion du roster coter sedirvice */ String user = StringUtils.parseBareAddress(presence.getFrom()); - Log.d(TAG, "User : "+user); + Log.d(TAG, "User : " + user); Contact c = mContacts.get(StringUtils.parseBareAddress(user)); if (c == null) { c = new Contact(user); @@ -191,7 +231,7 @@ Log.w(TAG, "Error while updating roster entries", e); } } - mRemoteRosListeners.finishBroadcast(); + mRemoteRosListeners.finishBroadcast(); } } diff -r eb9112a00b02 -r ff92a9c95c78 src/com/beem/project/beem/service/XmppConnectionAdapter.java --- a/src/com/beem/project/beem/service/XmppConnectionAdapter.java Tue Apr 07 19:07:41 2009 +0200 +++ b/src/com/beem/project/beem/service/XmppConnectionAdapter.java Tue Apr 07 20:12:30 2009 +0200 @@ -73,20 +73,21 @@ */ @Override public boolean connectSync() throws RemoteException { - try { - mAdaptee.connect(); - mAdaptee.addConnectionListener(mConListener); - mAdaptee.login(mLogin, mPassword, "BEEM"); - mChatManager = new BeemChatManager(mAdaptee.getChatManager()); - // TODO find why this cause a null pointer exception - // this.initFeatures(); // pour declarer les features xmpp qu'on supporte - mLastException = null; - triggerAsynchronousConnectEvent(); - return true; - } catch (XMPPException e) { - mLastException = new BeemException(e); - } - return false; + try { + mAdaptee.connect(); + mAdaptee.addConnectionListener(mConListener); + mAdaptee.login(mLogin, mPassword, "BEEM"); + mChatManager = new BeemChatManager(mAdaptee.getChatManager()); + // TODO find why this cause a null pointer exception + // this.initFeatures(); // pour declarer les features xmpp qu'on supporte + mLastException = null; + triggerAsynchronousConnectEvent(); + return true; + } catch (XMPPException e) { + Log.e(TAG, "Error while connecting", e); + mLastException = new BeemException(e); + } + return false; } /** @@ -106,10 +107,10 @@ public IRoster getRoster() throws RemoteException { if (mRoster != null) return mRoster; - Roster adap = mAdaptee.getRoster(); - if (adap == null) - return null; - mRoster = new RosterAdapter(adap); + Roster adap = mAdaptee.getRoster(); + if (adap == null) + return null; + mRoster = new RosterAdapter(adap); return mRoster; } @@ -264,6 +265,7 @@ } catch (RemoteException e) { // The RemoteCallbackList will take care of removing the // dead listeners. + Log.w(TAG, "Error while triggering remote connection listeners", e); } } mRemoteConnListeners.finishBroadcast(); @@ -311,7 +313,11 @@ } - public boolean isAuthentificated() throws RemoteException { + /** + * Returns true if currently authenticated by successfully calling the login method. + * @return true when successfully authenticated + */ + public boolean isAuthentificated() { return mAdaptee.isAuthenticated(); } diff -r eb9112a00b02 -r ff92a9c95c78 src/com/beem/project/beem/ui/ContactList.java --- a/src/com/beem/project/beem/ui/ContactList.java Tue Apr 07 19:07:41 2009 +0200 +++ b/src/com/beem/project/beem/ui/ContactList.java Tue Apr 07 20:12:30 2009 +0200 @@ -291,7 +291,7 @@ */ v = (TextView) view.findViewById(to[2]); if (v != null) { - v.setText(c.getMMsgState()); + v.setText(c.getMsgState()); } /*