# HG changeset patch # User Da Risk # Date 1238088373 -3600 # Node ID c537c1ea363639a5012657e91af496f137eacfc1 # Parent abf9da2833775d1e4e8087f2e0566fef5143d8f4# Parent 5b42427793c53da4e392008949548edc089e631a Merge ui and xmpp diff -r 5b42427793c5 -r c537c1ea3636 AndroidManifest.xml diff -r 5b42427793c5 -r c537c1ea3636 Beem-ecipse-formatter.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Beem-ecipse-formatter.xml Thu Mar 26 18:26:13 2009 +0100 @@ -0,0 +1,267 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 5b42427793c5 -r c537c1ea3636 INSTALL --- a/INSTALL Thu Mar 26 16:55:37 2009 +0100 +++ b/INSTALL Thu Mar 26 18:26:13 2009 +0100 @@ -5,7 +5,7 @@ 2. ActivityCreator Use the script provides by the SDK to set the Android platform directory. - > $SDK_DIR/tools/activitycreator --out beem com.beem.project.beem.Beem + > $SDK_DIR/tools/activitycreator --out . com.beem.project.beem.Beem 3. Compile and install Use ant to compile and install the application on the Android emulator diff -r 5b42427793c5 -r c537c1ea3636 checkstyle.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/checkstyle.xml Thu Mar 26 18:26:13 2009 +0100 @@ -0,0 +1,229 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 5b42427793c5 -r c537c1ea3636 project.aidl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/project.aidl Thu Mar 26 18:26:13 2009 +0100 @@ -0,0 +1,6 @@ +// This file is auto-generated by the +// 'Create Aidl preprocess file for Parcelable classes' +// action. Do not modify! + +parcelable com.beem.project.beem.BeemException +parcelable com.beem.project.beem.service.Contact diff -r 5b42427793c5 -r c537c1ea3636 src/com/beem/project/beem/BeemException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/BeemException.java Thu Mar 26 18:26:13 2009 +0100 @@ -0,0 +1,67 @@ +/** + * + */ +package com.beem.project.beem; + +import android.os.Parcel; +import android.os.Parcelable; + +/** + * @author darisk + * + */ +public class BeemException extends Exception implements Parcelable { + + public static final Parcelable.Creator CREATOR = new Creator() { + + @Override + public BeemException[] newArray(int size) { + // TODO Auto-generated method stub + return new BeemException[size]; + } + + @Override + public BeemException createFromParcel(Parcel source) { + // TODO Auto-generated method stub + return new BeemException(source); + } + }; + + public BeemException() { + super(); + // TODO Auto-generated constructor stub + } + + public BeemException(String detailMessage, Throwable throwable) { + super(detailMessage, throwable); + // TODO Auto-generated constructor stub + } + + public BeemException(String detailMessage) { + super(detailMessage); + // TODO Auto-generated constructor stub + } + + public BeemException(Throwable throwable) { + super(throwable); + // TODO Auto-generated constructor stub + } + + private BeemException(Parcel parcel){ + this(parcel.readString()); + } + + @Override + public int describeContents() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + // TODO Auto-generated method stub + dest.writeString(getLocalizedMessage()); + } + + +} diff -r 5b42427793c5 -r c537c1ea3636 src/com/beem/project/beem/BeemService.java --- a/src/com/beem/project/beem/BeemService.java Thu Mar 26 16:55:37 2009 +0100 +++ b/src/com/beem/project/beem/BeemService.java Thu Mar 26 18:26:13 2009 +0100 @@ -3,8 +3,13 @@ */ package com.beem.project.beem; -import java.util.List; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; +import org.jivesoftware.smack.Roster; +import org.jivesoftware.smack.RosterListener; +import org.jivesoftware.smack.packet.Presence; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; @@ -15,41 +20,31 @@ import android.content.Intent; import android.content.SharedPreferences; import android.os.IBinder; +import android.os.Looper; import android.os.RemoteException; import android.widget.Toast; -import com.beem.project.beem.service.IXMPPFacade; - +import com.beem.project.beem.service.XMPPConnectionAdapter; +import com.beem.project.beem.service.XMPPFacade; +import com.beem.project.beem.service.aidl.IRoster; +import com.beem.project.beem.service.aidl.IXMPPConnection; +import com.beem.project.beem.service.aidl.IXMPPFacade; /** + * This class is for the Beem service. * @author darisk - * + * */ public class BeemService extends Service { private NotificationManager notificationManager; - private XMPPConnection connection; - + private IXMPPConnection connection; private SharedPreferences settings; - - private String login; - - private String password; - - private String host; + private String mLogin; + private String mPassword; + private String mHost; - private IXMPPFacade.Stub bind = new IXMPPFacade.Stub() { - - @Override - public List getContactList() throws RemoteException { - return null; - } - - @Override - public List getGroupList() throws RemoteException { - return null; - } - }; + private IXMPPFacade.Stub mBind; /* * (non-Javadoc) @@ -57,23 +52,25 @@ * @see android.app.Service#onBind(android.content.Intent) */ @Override - public IBinder onBind(Intent arg0) { - try { - connection = new XMPPConnection("10.0.2.2"); // address du pc host - // de l'emulateur - connection.connect(); - connection.login(login, password); - notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); - showBasicNotification(R.string.BeemServiceCreated); - } catch (XMPPException e) { - // TODO Auto-generated catch block - Toast toast = Toast.makeText(this, "ERREUR " + e.getMessage(), - Toast.LENGTH_LONG); - toast.show(); - notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); - showBasicNotification(R.string.PreferenceFileName); - } - return bind; + public IBinder onBind(Intent intent) { + showBasicNotification(R.string.BeemServiceCreated); + return mBind; + // to forbid a client to bind + // return null; + } + + @Override + public void onCreate() { + super.onCreate(); + settings = getSharedPreferences(getString(R.string.PreferenceFileName), + MODE_PRIVATE); + mLogin = settings.getString(getString(R.string.PreferenceLoginKey), ""); + mPassword = settings.getString( + getString(R.string.PreferencePasswordKey), ""); + mHost = settings.getString(getString(R.string.PreferenceHostKey), ""); + notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + connection = new XMPPConnectionAdapter("10.0.2.2", mLogin, mPassword); // address + mBind = new XMPPFacade((XMPPConnectionAdapter) connection); } private void showBasicNotification(int stringResource) { @@ -90,43 +87,29 @@ } @Override - public void onCreate() { - super.onCreate(); - settings = getSharedPreferences(getString(R.string.PreferenceFileName), - MODE_PRIVATE); - login = settings.getString(getString(R.string.PreferenceLoginKey), ""); - password = settings.getString( - getString(R.string.PreferencePasswordKey), ""); - host = settings.getString(getString(R.string.PreferenceHostKey), ""); - } - - @Override public void onStart(Intent intent, int startId) { - try { - connection = new XMPPConnection("10.0.2.2"); // address du pc host - // de l'emulateur - connection.connect(); - connection.login(login, password); - notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); - showBasicNotification(R.string.BeemServiceCreated); - } catch (XMPPException e) { - // TODO Auto-generated catch block - Toast toast = Toast.makeText(this, "ERREUR " + e.getMessage(), - Toast.LENGTH_LONG); - toast.show(); - notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); - showBasicNotification(R.string.PreferenceFileName); - } - } - - private void closeConnection() { - if (connection != null) - connection.disconnect(); + try { + connection.connectSync(); + } catch (RemoteException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } @Override public void onDestroy() { - closeConnection(); - } + closeConnection(); + showBasicNotification(R.string.BeemServiceDestroyed); + } + + private void closeConnection() { + if (connection != null) + try { + connection.disconnect(); + } catch (RemoteException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } } diff -r 5b42427793c5 -r c537c1ea3636 src/com/beem/project/beem/service/Contact.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/Contact.java Thu Mar 26 18:26:13 2009 +0100 @@ -0,0 +1,93 @@ +/** + * + */ +package com.beem.project.beem.service; + +import android.os.Parcel; +import android.os.Parcelable; + +/** + * This class contains informations on a jabber contact. + * @author darisk + */ +public class Contact implements Parcelable { + + /** + * Parcelable.Creator needs by Android. + */ + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + + @Override + public Contact createFromParcel(Parcel source) { + return new Contact(source); + } + + @Override + public Contact[] newArray(int size) { + return new Contact[size]; + } + }; + + private String mJID; + private int mID; + private int mStatus; + private String mMsgState; + + /** + * Constructor. + */ + public Contact() { + // TODO Auto-generated constructor stub + } + + /** + * Constructor. + * @param jid JID of the contact + */ + public Contact(final String jid) { + mJID = jid; + } + + /** + * Construct a contact from a parcel. + * @param in parcel to use for construction + */ + private Contact(final Parcel in) { + + } + + /** + * Get the Jabber ID of the contact. + * @return the Jabber ID + */ + public String getJID() { + return mJID; + } + + /** + * Set the Jabber ID of the contact. + * @param mjid the jabber ID to set + */ + public void setJID(String mjid) { + mJID = mjid; + } + + /** + * {@inheritDoc} + */ + @Override + public int describeContents() { + // TODO Auto-generated method stub + return 0; + } + + /** + * {@inheritDoc} + */ + @Override + public void writeToParcel(Parcel dest, int flags) { + // TODO Auto-generated method stub + } + + +} diff -r 5b42427793c5 -r c537c1ea3636 src/com/beem/project/beem/service/IXMPPFacade.aidl --- a/src/com/beem/project/beem/service/IXMPPFacade.aidl Thu Mar 26 16:55:37 2009 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -package com.beem.project.beem.service; - -// import org.jivesoftware.smack.XMPPConnection; - -interface IXMPPFacade { - - // org.jivesoftware.smack.XMPPConnection getXMPPConnection(); - - List getContactList(); - List getGroupList(); - -} diff -r 5b42427793c5 -r c537c1ea3636 src/com/beem/project/beem/service/RosterAdapter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/RosterAdapter.java Thu Mar 26 18:26:13 2009 +0100 @@ -0,0 +1,89 @@ +/** + * + */ +package com.beem.project.beem.service; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.jivesoftware.smack.Roster; +import org.jivesoftware.smack.RosterEntry; +import org.jivesoftware.smack.XMPPException; + +import android.os.RemoteException; + +/** + * This class implement a Roster adapter for BEEM. + * @author darisk + */ +public class RosterAdapter extends com.beem.project.beem.service.aidl.IRoster.Stub { + + private Roster mAdaptee; + private Map mContacts = new HashMap(); + + /** + * Constructor. + * @param roster the roster to adapt + */ + public RosterAdapter(final Roster roster) { + mAdaptee = roster; + for (RosterEntry entry : roster.getEntries()) { + String user = entry.getUser(); + mContacts.put(user, new Contact(user)); + } + } + + /** + * {@inheritDoc} + */ + @Override + public void createGroup(String groupname) throws RemoteException { + // TODO Auto-generated method stub + mAdaptee.createGroup(groupname); + } + + /** + * {@inheritDoc} + */ + @Override + public Contact addContact(String user, String name, String[] groups) throws RemoteException { + try { + mAdaptee.createEntry(user, name, groups); + Contact res = new Contact(user); + mContacts.put(user, res); + return res; + } catch (XMPPException e) { + return null; + } + } + + /** + * {@inheritDoc} + */ + @Override + public void deleteContact(Contact contact) throws RemoteException { + // TODO Auto-generated method stub + + } + + /** + * {@inheritDoc} + */ + @Override + public Contact getContact(String jid) throws RemoteException { + return mContacts.get(jid); + } + + /** + * {@inheritDoc} + */ + @Override + public List getContactList() throws RemoteException { + List res = new ArrayList(); + res.addAll(mContacts.values()); + return res; + } + +} diff -r 5b42427793c5 -r c537c1ea3636 src/com/beem/project/beem/service/XMPPConnectionAdapter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/XMPPConnectionAdapter.java Thu Mar 26 18:26:13 2009 +0100 @@ -0,0 +1,323 @@ +/** + * + */ +package com.beem.project.beem.service; + +import org.jivesoftware.smack.ConnectionConfiguration; +import org.jivesoftware.smack.ConnectionListener; +import org.jivesoftware.smack.Roster; +import org.jivesoftware.smack.XMPPConnection; +import org.jivesoftware.smack.XMPPException; +import org.jivesoftware.smackx.ServiceDiscoveryManager; +import org.jivesoftware.smackx.jingle.JingleManager; + +import android.os.RemoteCallbackList; +import android.os.RemoteException; +import android.util.Log; + +import com.beem.project.beem.BeemException; +import com.beem.project.beem.service.aidl.IBeemConnectionListener; +import com.beem.project.beem.service.aidl.IRoster; +import com.beem.project.beem.service.aidl.IXMPPConnection; + +/** + * This class implements an adapter for XMPPConnection. + * @author darisk + */ +public class XMPPConnectionAdapter extends IXMPPConnection.Stub { + + private static final String TAG = "XMPPConnectionAdapter"; + private XMPPConnection mAdaptee; + private BeemException mLastException; + private String mLogin; + private String mPassword; + private RosterAdapter mRoster; + + private RemoteCallbackList mRemoteConnListeners = + new RemoteCallbackList(); + private ConnexionListenerAdapter mConListener = new ConnexionListenerAdapter(); + + /** + * Constructor. + * @param con The connection to adapt + * @param login The login to use + * @param password The password to use + */ + public XMPPConnectionAdapter(final XMPPConnection con, final String login, final String password) { + mAdaptee = con; + mLogin = login; + mPassword = password; + } + + /** + * Constructor. + * @param serviceName name of the service to connect to + * @param login login to use on connect + * @param password password to use on connect + */ + public XMPPConnectionAdapter(final String serviceName, final String login, final String password) { + this(new XMPPConnection(serviceName), login, password); + } + + /** + * Constructor. + * @param config Configuration to use in order to connect + * @param login login to use on connect + * @param password password to use on connect + */ + public XMPPConnectionAdapter(final ConnectionConfiguration config, final String login, final String password) { + this(new XMPPConnection(config), login, password); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean connectSync() throws RemoteException { + try { + mAdaptee.connect(); + mAdaptee.addConnectionListener(mConListener); + mAdaptee.login(mLogin, mPassword, "BEEM"); + // 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; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean disconnect() { + mAdaptee.disconnect(); + mLastException = null; + return true; + } + + /** + * {@inheritDoc} + */ + @Override + public IRoster getRoster() throws RemoteException { + if (mRoster != null) + return mRoster; + Roster adap = mAdaptee.getRoster(); + if (adap == null) + return null; + mRoster = new RosterAdapter(adap); + return mRoster; + } + + /** + * {@inheritDoc} + */ + @Override + public final void connectAsync() throws RemoteException { + Thread t = new Thread(new Runnable() { + + @Override + public void run() { + try { + connectSync(); + } catch (RemoteException e) { + Log.e(TAG, "Error while connecting", e); + } + } + }); + t.start(); + } + + /** + * {@inheritDoc} + */ + @Override + public void addConnectionListener(IBeemConnectionListener listen) throws RemoteException { + if (listen != null) + mRemoteConnListeners.register(listen); + } + + /** + * {@inheritDoc} + */ + @Override + public void removeConnectionListener(IBeemConnectionListener listen) throws RemoteException { + if (listen != null) + mRemoteConnListeners.unregister(listen); + } + + /** + * Trigger Connection event. + */ + private void triggerAsynchronousConnectEvent() { + mConListener.onConnect(); + } + + /** + * Listener for XMPP connection events. + * It will calls the remote listeners for connexion events. + * @author darisk + */ + private class ConnexionListenerAdapter implements ConnectionListener { + + /** + * Defaut constructor. + */ + public ConnexionListenerAdapter() { + // TODO Auto-generated constructor stub + } + + /** + * Method to execute when a connection event occurs. + */ + public void onConnect() { + final int n = mRemoteConnListeners.beginBroadcast(); + + for (int i = 0; i < n; i++) { + IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i); + try { + listener.onConnect(); + } 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(); + } + + /** + * {@inheritDoc} + */ + @Override + public void connectionClosed() { + final int n = mRemoteConnListeners.beginBroadcast(); + + for (int i = 0; i < n; i++) { + IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i); + try { + listener.connectionClosed(); + } 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(); + } + + /** + * {@inheritDoc} + */ + @Override + public void connectionClosedOnError(Exception arg0) { + final int n = mRemoteConnListeners.beginBroadcast(); + + for (int i = 0; i < n; i++) { + IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i); + try { + listener.connectionClosedOnError(); + } 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(); + } + + /** + * {@inheritDoc} + */ + @Override + public void reconnectingIn(int arg0) { + final int n = mRemoteConnListeners.beginBroadcast(); + + for (int i = 0; i < n; i++) { + IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i); + try { + listener.reconnectingIn(arg0); + } catch (RemoteException e) { + // The RemoteCallbackList will take care of removing the + // dead listeners. + } + } + mRemoteConnListeners.finishBroadcast(); + } + + /** + * {@inheritDoc} + */ + @Override + public void reconnectionFailed(Exception arg0) { + final int r = mRemoteConnListeners.beginBroadcast(); + + for (int i = 0; i < r; i++) { + IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i); + try { + listener.reconnectionFailed(); + } 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(); + } + + /** + * {@inheritDoc} + */ + @Override + public void reconnectionSuccessful() { + final int n = mRemoteConnListeners.beginBroadcast(); + + for (int i = 0; i < n; i++) { + IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i); + try { + listener.reconnectionSuccessful(); + } 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(); + } + + } + + /** + * enregistre les features dispo dans notre version Liste de features que Telepathy supporte. + * "http://www.google.com/xmpp/protocol/session" "http://www.google.com/transport/p2p" + * "http://jabber.org/protocol/jingle" "http://jabber.org/protocol/chatstates" "http://jabber.org/protocol/nick" + * "http://jabber.org/protocol/nick+notify" "http://jabber.org/protocol/si" "ttp://jabber.org/protocol/ibb" + * "ttp://telepathy.freedesktop.org/xmpp/tubes" "http://www.google.com/xmpp/protocol/voice/v1" + * "http://jabber.org/protocol/jingle/description/audio" "http://jabber.org/protocol/jingle/description/video" Liste + * de features que pidgin `supporte' (on notera la cradence de l'annonce): "jabber:iq:last" "jabber:iq:oob" + * "jabber:iq:time" "jabber:iq:version" "jabber:x:conference" "urn:xmpp:attention:0" "urn:xmpp:bob" "urn:xmpp:ping" + * "xmpp:urn:time" "http://jabber.org/protocol/bytestreams" "http://jabber.org/protocol/disco#info" + * "http://jabber.org/protocol/disco#items" "http://jabber.org/protocol/ibb" "http://jabber.org/protocol/muc" + * "http://jabber.org/protocol/muc#user" "http://jabber.org/protocol/si" + * "http://jabber.org/protocol/si/profile/file-transfer" "http://jabber.org/protocol/xhtml-im" + * "http://www.xmpp.org/extensions/xep-0199.html#ns" "http://jabber.org/protocol/mood" + * "http://jabber.org/protocol/mood+notify" "http://jabber.org/protocol/nick" + * "http://jabber.org/protocol/nick+notify" "http://jabber.org/protocol/tune" + * "http://jabber.org/protocol/tune+notify" "http://www.xmpp.org/extensions/xep-0084.html#ns-metadata" + * "http://www.xmpp.org/extensions/xep-0084.html#ns-data" + * "http://www.xmpp.org/extensions/xep-0084.html#ns-metadata+notify" + * "http://www.xmpp.org/extensions/xep-0167.html#ns" << Jingle RTP Sessions + */ + private void initFeatures() { + JingleManager.setJingleServiceEnabled(); + ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(mAdaptee); + sdm.addFeature("http://jabber.org/protocol/disco#info"); + // sdm.addFeature("http://jabber.org/protocol/nick"); + + } + +} diff -r 5b42427793c5 -r c537c1ea3636 src/com/beem/project/beem/service/XMPPFacade.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/XMPPFacade.java Thu Mar 26 18:26:13 2009 +0100 @@ -0,0 +1,55 @@ +/** + * + */ +package com.beem.project.beem.service; +import android.os.RemoteException; + +import com.beem.project.beem.service.aidl.IRoster; +import com.beem.project.beem.service.aidl.IXMPPConnection; +import com.beem.project.beem.service.aidl.IXMPPFacade; +/** + * @author darisk + * + */ +public class XMPPFacade extends IXMPPFacade.Stub { + + private XMPPConnectionAdapter mConnexion; + + /** + * Constructor for XMPPFacade. + * @param connection the connection use by the facade + */ + public XMPPFacade(XMPPConnectionAdapter connection) { + this.mConnexion = connection; + } + + @Override + public void connectAsync() throws RemoteException { + // TODO Auto-generated method stub + mConnexion.connectAsync(); + } + + @Override + public void connectSync() throws RemoteException { + // TODO Auto-generated method stub + mConnexion.connectSync(); + } + + @Override + public IXMPPConnection createConnection() throws RemoteException { + // TODO Auto-generated method stub + return mConnexion; + } + + @Override + public void disconnect() throws RemoteException { + // TODO Auto-generated method stub + mConnexion.disconnect(); + } + + @Override + public IRoster getRoster() throws RemoteException { + return mConnexion.getRoster(); + } + +} diff -r 5b42427793c5 -r c537c1ea3636 src/com/beem/project/beem/service/aidl/IBeemConnectionListener.aidl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/aidl/IBeemConnectionListener.aidl Thu Mar 26 18:26:13 2009 +0100 @@ -0,0 +1,17 @@ +package com.beem.project.beem.service.aidl; + +interface IBeemConnectionListener { + + void connectionClosed(); + + void onConnect(); + + //void connectionClosedOnError(in Exception e); + void connectionClosedOnError(); + + void reconnectingIn(in int seconds); + + void reconnectionFailed(); + + void reconnectionSuccessful(); +} diff -r 5b42427793c5 -r c537c1ea3636 src/com/beem/project/beem/service/aidl/IRoster.aidl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/aidl/IRoster.aidl Thu Mar 26 18:26:13 2009 +0100 @@ -0,0 +1,17 @@ +package com.beem.project.beem.service.aidl; + +import com.beem.project.beem.service.Contact; + +interface IRoster { + + Contact addContact(in String user, in String name, in String[] groups); + + void deleteContact(in Contact contact); + + Contact getContact(in String jid); + + void createGroup(in String groupname); + + List getContactList(); + +} \ No newline at end of file diff -r 5b42427793c5 -r c537c1ea3636 src/com/beem/project/beem/service/aidl/IXMPPConnection.aidl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/aidl/IXMPPConnection.aidl Thu Mar 26 18:26:13 2009 +0100 @@ -0,0 +1,18 @@ +package com.beem.project.beem.service.aidl; + +import com.beem.project.beem.service.aidl.IRoster; +import com.beem.project.beem.service.aidl.IBeemConnectionListener; + +interface IXMPPConnection { + + boolean connectSync(); + + void connectAsync(); + + boolean disconnect(); + + IRoster getRoster(); + + void addConnectionListener(in IBeemConnectionListener listen); + void removeConnectionListener(in IBeemConnectionListener listen); +} \ No newline at end of file diff -r 5b42427793c5 -r c537c1ea3636 src/com/beem/project/beem/service/aidl/IXMPPFacade.aidl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/aidl/IXMPPFacade.aidl Thu Mar 26 18:26:13 2009 +0100 @@ -0,0 +1,18 @@ +package com.beem.project.beem.service.aidl; + +import com.beem.project.beem.service.aidl.IXMPPConnection; +import com.beem.project.beem.service.aidl.IRoster; + +interface IXMPPFacade { + + IXMPPConnection createConnection(); + + IRoster getRoster(); + + void connectSync(); + + void connectAsync(); + + void disconnect(); + +} diff -r 5b42427793c5 -r c537c1ea3636 src/com/beem/project/beem/ui/Beem.java --- a/src/com/beem/project/beem/ui/Beem.java Thu Mar 26 16:55:37 2009 +0100 +++ b/src/com/beem/project/beem/ui/Beem.java Thu Mar 26 18:26:13 2009 +0100 @@ -4,6 +4,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; +import android.os.Handler; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; @@ -13,62 +14,95 @@ import com.beem.project.beem.R; +/** + * La principale activite to be continuous. + */ public class Beem extends Activity { private SharedPreferences mSettings; private BeemDialogSettings mDialog; private Button mButton; + private Handler mHandler; + + /** + * Default constructor. + */ + public Beem() { + super(); + mHandler = new Handler(); + } /** * Called when the activity is first created. + * @param savedInstanceState + * previous state. */ @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.beem); - mSettings = getSharedPreferences( - getString(R.string.PreferenceFileName), MODE_PRIVATE); - mDialog = new BeemDialogSettings(this, mSettings); + public final void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.beem); + mSettings = getSharedPreferences( + getString(R.string.PreferenceFileName), MODE_PRIVATE); + mDialog = new BeemDialogSettings(this, mSettings); - mButton = (Button) findViewById(R.id.connection); - mButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - if (mButton.getText() == getString(R.string.BeemCreateAccount)) - mDialog.show(); - else - startActivity(new Intent(Beem.this, ContactList.class)); - } - }); - showJID(); + mButton = (Button) findViewById(R.id.connection); + mButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + if (mButton.getText() == getString(R.string.BeemCreateAccount)) + mDialog.show(); + else + startActivity(new Intent(Beem.this, ContactList.class)); + } + }); + showJID(); } + /** + * Callback for menu creation. + * @param menu + * the menu created + * @return true on success, false otherwise + */ @Override - public boolean onCreateOptionsMenu(Menu menu) { - super.onCreateOptionsMenu(menu); - MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.beemmenu, menu); - return true; + public final boolean onCreateOptionsMenu(Menu menu) { + super.onCreateOptionsMenu(menu); + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.beemmenu, menu); + return true; } + /** + * Callback for menu item selected. + * @param item + * the item selected + * @return true on success, false otherwise + */ @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.account_edit: - mDialog.show(); - return true; - case R.id.account_about: - return true; - } - return false; + public final boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.account_edit: + mDialog.show(); + return true; + case R.id.account_about: + return true; + default: + return false; + } } - public void showJID() { - String jid = mSettings.getString(getString(R.string.PreferenceLoginKey), "") + "@" - + mSettings.getString(getString(R.string.PreferenceHostKey), ""); - if (jid.length() == 1) - jid = getString(R.string.BeemCreateAccount); - mButton.setText(jid); + /** + * Show jabber id in button. + */ + public final void showJID() { + String jid = mSettings.getString( + getString(R.string.PreferenceLoginKey), "") + + "@" + + mSettings + .getString(getString(R.string.PreferenceHostKey), ""); + if (jid.length() == 1) + jid = getString(R.string.BeemCreateAccount); + mButton.setText(jid); } } diff -r 5b42427793c5 -r c537c1ea3636 src/com/beem/project/beem/ui/ContactList.java --- a/src/com/beem/project/beem/ui/ContactList.java Thu Mar 26 16:55:37 2009 +0100 +++ b/src/com/beem/project/beem/ui/ContactList.java Thu Mar 26 18:26:13 2009 +0100 @@ -11,15 +11,23 @@ import android.content.ServiceConnection; import android.os.Bundle; import android.os.IBinder; +import android.os.RemoteException; +import android.util.Log; import android.widget.ExpandableListAdapter; import android.widget.SimpleExpandableListAdapter; import com.beem.project.beem.BeemService; import com.beem.project.beem.R; -import com.beem.project.beem.service.IXMPPFacade; +import com.beem.project.beem.service.Contact; +import com.beem.project.beem.service.aidl.IBeemConnectionListener; +import com.beem.project.beem.service.aidl.IRoster; +import com.beem.project.beem.service.aidl.IXMPPConnection; +import com.beem.project.beem.service.aidl.IXMPPFacade; public class ContactList extends ExpandableListActivity { + private static final String TAG = "CONTACTLIST_ACT"; + private IXMPPFacade mService = null; @Override @@ -27,7 +35,6 @@ super.onCreate(saveBundle); bindService(new Intent(this, BeemService.class), mConnection, BIND_AUTO_CREATE | BIND_DEBUG_UNBIND); - showContactList(); } private void showContactList() { @@ -45,7 +52,7 @@ for (int j = 0; j < 5; j++) { Map curChildMap = new HashMap(); children.add(curChildMap); - curChildMap.put("NAME CHILD", "Child " + j); + curChildMap.put("NAOME CHILD", "Child " + j); } childData.add(children); } @@ -62,10 +69,19 @@ @Override public void onServiceConnected(ComponentName name, IBinder service) { mService = IXMPPFacade.Stub.asInterface(service); + try { + IXMPPConnection con = mService.createConnection(); + con.addConnectionListener(new TestConnectionListener()); + mService.connectSync(); + Log.i("BEEM", "Connected !!!"); + } catch (RemoteException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + /* * mService.getGroupList(); mService.getContactList(); */ - showContactList(); } @Override @@ -80,4 +96,48 @@ unbindService(mConnection); } + private class TestConnectionListener extends IBeemConnectionListener.Stub { + + @Override + public void connectionClosed() throws RemoteException { + // TODO Auto-generated method stub + + } + + @Override + public void connectionClosedOnError() throws RemoteException { + // TODO Auto-generated method stub + + } + + @Override + public void onConnect() throws RemoteException { + // TODO Auto-generated method stub + IRoster roster = mService.getRoster(); + for (Contact contact : roster.getContactList()) { + Log.v(TAG,"Contact name " + contact.getJID() ); + } + showContactList(); + } + + @Override + public void reconnectingIn(int seconds) throws RemoteException { + // TODO Auto-generated method stub + + } + + @Override + public void reconnectionFailed() throws RemoteException { + // TODO Auto-generated method stub + + } + + @Override + public void reconnectionSuccessful() throws RemoteException { + // TODO Auto-generated method stub + + } + + } + }