# HG changeset patch # User Da Risk # Date 1239092740 -7200 # Node ID 29f0d6a23321a115c3881a2f1c1afd0f66717fcd # Parent 144e837ee4a60ad068b63690da240c21dc3545a6 Le proxy devrait marcher a peu pres. Ca se connecte par le proxy mais les serveurs que j'ai essayƩ ne repondent pas fixes #83 diff -r 144e837ee4a6 -r 29f0d6a23321 res/values/strings.xml --- a/res/values/strings.xml Tue Apr 07 01:18:19 2009 +0200 +++ b/res/values/strings.xml Tue Apr 07 10:25:40 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 144e837ee4a6 -r 29f0d6a23321 src/com/beem/project/beem/BeemService.java --- a/src/com/beem/project/beem/BeemService.java Tue Apr 07 01:18:19 2009 +0200 +++ b/src/com/beem/project/beem/BeemService.java Tue Apr 07 10:25:40 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 144e837ee4a6 -r 29f0d6a23321 src/com/beem/project/beem/service/Contact.java --- a/src/com/beem/project/beem/service/Contact.java Tue Apr 07 01:18:19 2009 +0200 +++ b/src/com/beem/project/beem/service/Contact.java Tue Apr 07 10:25:40 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,6 +75,24 @@ }; /** + * 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 */ @@ -60,7 +102,7 @@ mJID = in.readString(); mMsgState = in.readString(); mRes = new ArrayList(); - in.readStringList(mRes); + in.readStringList(mRes); } /** @@ -85,24 +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() { @@ -110,6 +135,7 @@ } /** + * set the id of te contact on the phone contact list. * @param mid the mID to set */ public void setID(int mid) { @@ -117,6 +143,7 @@ } /** + * Get the status of the contact. * @return the mStatus */ public int getStatus() { @@ -124,6 +151,7 @@ } /** + * Set the status of the contact. * @param status the mStatus to set */ public void setStatus(int status) { @@ -131,6 +159,7 @@ } /** + * Set the status of the contact using a presence packet. * @param presence the presence containing status */ public void setStatus(Presence presence) { @@ -138,7 +167,7 @@ Log.d(TAG, "Presence pas dispo"); mStatus = Contact.CONTACT_STATUS_DISCONNECT; } else { - Log.d(TAG,"Presence OK"); + Log.d(TAG, "Presence OK"); Mode mode = presence.getMode(); switch (mode) { case available: @@ -158,23 +187,25 @@ break; default: Log.e("RosterAdapter", "Status mode non gere"); - mStatus = Contact.CONTACT_STATUS_DISCONNECT; - break; + mStatus = Contact.CONTACT_STATUS_DISCONNECT; + break; } } } /** - * @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; } @@ -188,17 +219,25 @@ /** * 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); } diff -r 144e837ee4a6 -r 29f0d6a23321 src/com/beem/project/beem/service/RosterAdapter.java --- a/src/com/beem/project/beem/service/RosterAdapter.java Tue Apr 07 01:18:19 2009 +0200 +++ b/src/com/beem/project/beem/service/RosterAdapter.java Tue Apr 07 10:25:40 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 144e837ee4a6 -r 29f0d6a23321 src/com/beem/project/beem/service/XmppConnectionAdapter.java --- a/src/com/beem/project/beem/service/XmppConnectionAdapter.java Tue Apr 07 01:18:19 2009 +0200 +++ b/src/com/beem/project/beem/service/XmppConnectionAdapter.java Tue Apr 07 10:25:40 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 144e837ee4a6 -r 29f0d6a23321 src/com/beem/project/beem/ui/ContactList.java --- a/src/com/beem/project/beem/ui/ContactList.java Tue Apr 07 01:18:19 2009 +0200 +++ b/src/com/beem/project/beem/ui/ContactList.java Tue Apr 07 10:25:40 2009 +0200 @@ -276,7 +276,7 @@ */ v = (TextView) view.findViewById(to[2]); if (v != null) { - v.setText(c.getMMsgState()); + v.setText(c.getMsgState()); } /*