# HG changeset patch # User Da Risk # Date 1239110428 -7200 # Node ID fb3e3ed4bafca4667c24a177f185d20934b960d7 # Parent 31b436663df5ec600485f51b83855c88f5dd48ec# Parent cc06de2dfff0d603fd772e1013b4856c4215c4b6 Merge de jibe diff -r 31b436663df5 -r fb3e3ed4bafc .hgignore --- a/.hgignore Sun Apr 05 23:43:55 2009 +0200 +++ b/.hgignore Tue Apr 07 15:20:28 2009 +0200 @@ -1,2 +1,5 @@ +syntax: glob bin/* R.java +doc/javadoc +src/com/beem/project/beem/service/aidl/*.java diff -r 31b436663df5 -r fb3e3ed4bafc AndroidManifest.xml --- a/AndroidManifest.xml Sun Apr 05 23:43:55 2009 +0200 +++ b/AndroidManifest.xml Tue Apr 07 15:20:28 2009 +0200 @@ -2,15 +2,13 @@ - - - + + - @@ -25,5 +23,5 @@ - + diff -r 31b436663df5 -r fb3e3ed4bafc Beem-ecipse-formatter.xml --- a/Beem-ecipse-formatter.xml Sun Apr 05 23:43:55 2009 +0200 +++ b/Beem-ecipse-formatter.xml Tue Apr 07 15:20:28 2009 +0200 @@ -19,7 +19,7 @@ - + @@ -37,7 +37,7 @@ - + @@ -69,8 +69,8 @@ - - + + @@ -139,7 +139,7 @@ - + @@ -157,7 +157,7 @@ - + @@ -186,7 +186,7 @@ - + @@ -230,7 +230,7 @@ - + diff -r 31b436663df5 -r fb3e3ed4bafc build.xml --- a/build.xml Sun Apr 05 23:43:55 2009 +0200 +++ b/build.xml Tue Apr 07 15:20:28 2009 +0200 @@ -114,6 +114,8 @@ + + @@ -121,6 +123,7 @@ Creating output directories if needed... + @@ -145,11 +148,13 @@ Compiling aidl files into Java classes... + + @@ -244,7 +249,9 @@ - + Packaging ${out-unsigned-package} for release... @@ -264,7 +271,8 @@ - + Installing ${out-debug-package} onto default emulator... @@ -281,8 +289,9 @@ - - + + Uninstalling ${application-package} from the default emulator... @@ -295,6 +304,13 @@ - + + + + + + + diff -r 31b436663df5 -r fb3e3ed4bafc project.aidl --- a/project.aidl Sun Apr 05 23:43:55 2009 +0200 +++ b/project.aidl Tue Apr 07 15:20:28 2009 +0200 @@ -3,4 +3,6 @@ // action. Do not modify! parcelable com.beem.project.beem.BeemException +parcelable com.beem.project.beem.service.Message parcelable com.beem.project.beem.service.Contact +parcelable com.beem.project.beem.service.PresenceAdapter diff -r 31b436663df5 -r fb3e3ed4bafc res/drawable/away.png Binary file res/drawable/away.png has changed diff -r 31b436663df5 -r fb3e3ed4bafc res/drawable/chat.png Binary file res/drawable/chat.png has changed diff -r 31b436663df5 -r fb3e3ed4bafc res/drawable/closed.png Binary file res/drawable/closed.png has changed diff -r 31b436663df5 -r fb3e3ed4bafc res/drawable/connecting.png Binary file res/drawable/connecting.png has changed diff -r 31b436663df5 -r fb3e3ed4bafc res/drawable/dnd.png Binary file res/drawable/dnd.png has changed diff -r 31b436663df5 -r fb3e3ed4bafc res/drawable/error.png Binary file res/drawable/error.png has changed diff -r 31b436663df5 -r fb3e3ed4bafc res/drawable/invisible.png Binary file res/drawable/invisible.png has changed diff -r 31b436663df5 -r fb3e3ed4bafc res/drawable/message.png Binary file res/drawable/message.png has changed diff -r 31b436663df5 -r fb3e3ed4bafc res/drawable/not_in_the_roster.png Binary file res/drawable/not_in_the_roster.png has changed diff -r 31b436663df5 -r fb3e3ed4bafc res/drawable/offline.png Binary file res/drawable/offline.png has changed diff -r 31b436663df5 -r fb3e3ed4bafc res/drawable/online.png Binary file res/drawable/online.png has changed diff -r 31b436663df5 -r fb3e3ed4bafc res/drawable/requested.png Binary file res/drawable/requested.png has changed diff -r 31b436663df5 -r fb3e3ed4bafc res/layout/beem.xml --- a/res/layout/beem.xml Sun Apr 05 23:43:55 2009 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff -r 31b436663df5 -r fb3e3ed4bafc res/layout/contactlistcontact.xml --- a/res/layout/contactlistcontact.xml Sun Apr 05 23:43:55 2009 +0200 +++ b/res/layout/contactlistcontact.xml Tue Apr 07 15:20:28 2009 +0200 @@ -2,25 +2,34 @@ - + + - - + + - - + + \ No newline at end of file diff -r 31b436663df5 -r fb3e3ed4bafc res/layout/contactlistdialogsettings.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/res/layout/contactlistdialogsettings.xml Tue Apr 07 15:20:28 2009 +0200 @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff -r 31b436663df5 -r fb3e3ed4bafc res/menu/beemmenu.xml --- a/res/menu/beemmenu.xml Sun Apr 05 23:43:55 2009 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ - - - - diff -r 31b436663df5 -r fb3e3ed4bafc res/menu/contactlistmenu.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/res/menu/contactlistmenu.xml Tue Apr 07 15:20:28 2009 +0200 @@ -0,0 +1,4 @@ + + + + diff -r 31b436663df5 -r fb3e3ed4bafc res/values/strings.xml --- a/res/values/strings.xml Sun Apr 05 23:43:55 2009 +0200 +++ b/res/values/strings.xml Tue Apr 07 15:20:28 2009 +0200 @@ -3,7 +3,7 @@ Beem - Creer un compte + Jabber ID @@ -13,9 +13,9 @@ Beem - login + host - password + Jabber IDloginpassword port @@ -24,4 +24,5 @@ Is : and is speaking from : Insert a smiley + diff -r 31b436663df5 -r fb3e3ed4bafc src/com/beem/project/beem/BeemApplication.java --- a/src/com/beem/project/beem/BeemApplication.java Sun Apr 05 23:43:55 2009 +0200 +++ b/src/com/beem/project/beem/BeemApplication.java Tue Apr 07 15:20:28 2009 +0200 @@ -18,66 +18,21 @@ import android.os.IBinder; import android.os.Message; -import com.beem.project.beem.service.aidl.IXMPPFacade; +import com.beem.project.beem.service.aidl.IXmppFacade; /** + * The Beem application. + * This class has some methods utiliy needs by the activities. * @author darisk */ public class BeemApplication extends Application { - private IXMPPFacade mFacade; - + private static BeemApplication mBeemApp; + private IXmppFacade mFacade; private Context mApplicationContext; private Resources mPrivateResources; - private static BeemApplication mBeemApp; private List mQueue = new LinkedList(); private boolean mIsConnected; - - public static BeemApplication getApplication(Activity activity) { - if (mBeemApp == null) { - mBeemApp = new BeemApplication(); - mBeemApp.mApplicationContext = activity.getApplication(); - mBeemApp.mPrivateResources = activity.getResources(); - mBeemApp.onCreate(); - } - return mBeemApp; - } - - @Override - public void onConfigurationChanged(Configuration newConfig) { - // TODO Auto-generated method stub - super.onConfigurationChanged(newConfig); - } - - @Override - public void onCreate() { - // TODO Auto-generated method stub - super.onCreate(); - mFacade = null; - } - - @Override - public void onLowMemory() { - // TODO Auto-generated method stub - super.onLowMemory(); - } - - @Override - public void onTerminate() { - // TODO Auto-generated method stub - super.onTerminate(); - } - - public synchronized void startBeemService() { - if (!mIsConnected) { - // Intent intent = new Intent(this, BeemService.class); - Intent intent = new Intent(); - intent.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService")); - mApplicationContext.startService(intent); - mApplicationContext.bindService(intent, mServConn, BIND_AUTO_CREATE); - mIsConnected = true; - } - } private ServiceConnection mServConn = new ServiceConnection() { @@ -90,7 +45,7 @@ @Override public void onServiceConnected(ComponentName name, IBinder service) { // TODO Auto-generated method stub - mFacade = IXMPPFacade.Stub.asInterface(service); + mFacade = IXmppFacade.Stub.asInterface(service); synchronized (mQueue) { for (Message msg : mQueue) { msg.sendToTarget(); @@ -100,16 +55,107 @@ } }; - public synchronized void stopBeemService() { - Intent intent = new Intent(this, BeemService.class); - mApplicationContext.unbindService(mServConn); - mApplicationContext.stopService(intent); + /** + * Constructor. + */ + public BeemApplication() { + // TODO Auto-generated constructor stub + } + + /** + * Get the Beem application for an activity. + * @param activity the activity which want the Beem application + * @return the Beem application + */ + public static BeemApplication getApplication(Activity activity) { + if (mBeemApp == null) { + mBeemApp = new BeemApplication(); + mBeemApp.mApplicationContext = activity.getApplication(); + mBeemApp.mPrivateResources = activity.getResources(); + mBeemApp.onCreate(); + } + return mBeemApp; + } + + /** + * {@inheritDoc} + */ + @Override + public void onConfigurationChanged(Configuration newConfig) { + // TODO Auto-generated method stub + super.onConfigurationChanged(newConfig); + } + + /** + * {@inheritDoc} + */ + @Override + public void onCreate() { + // TODO Auto-generated method stub + super.onCreate(); + mFacade = null; + } + + /** + * {@inheritDoc} + */ + @Override + public void onLowMemory() { + // TODO Auto-generated method stub + super.onLowMemory(); } - public IXMPPFacade getXmppFacade() { + /** + * {@inheritDoc} + */ + @Override + public void onTerminate() { + // TODO Auto-generated method stub + super.onTerminate(); + } + + /** + * Start the beem service. + */ + public synchronized void startBeemService() { + if (!mIsConnected) { + // Intent intent = new Intent(this, BeemService.class); + Intent intent = new Intent(); + intent.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService")); + mApplicationContext.startService(intent); + mApplicationContext.bindService(intent, mServConn, BIND_AUTO_CREATE); + mIsConnected = true; + } + } + + /** + * Stop the Beem service. + */ + public synchronized void stopBeemService() { + if (mIsConnected) { + Intent intent = new Intent(); + intent.setComponent(new ComponentName("com.beem.project.beem", + "com.beem.project.beem.BeemService")); + mApplicationContext.unbindService(mServConn); + mApplicationContext.stopService(intent); + mIsConnected = false; + } + } + + /** + * Get the facade to use to access the Beem service. + * @return the facade or null if the application is not connected to the beem service. + */ + public IXmppFacade getXmppFacade() { return mFacade; } - + + + /** + * Add a methode to execute when the application is connected to the Beem service. + * @param target the handler which will execute the callback + * @param callback the callback to execute + */ public void callWhenServiceConnected(Handler target, Runnable callback) { Message msg = Message.obtain(target, callback); if (!mIsConnected) { @@ -121,4 +167,12 @@ } } } + + /** + * Indique si on est connecte au service. + */ + public boolean isConnected() { + return mIsConnected; + } + } diff -r 31b436663df5 -r fb3e3ed4bafc src/com/beem/project/beem/BeemService.java --- a/src/com/beem/project/beem/BeemService.java Sun Apr 05 23:43:55 2009 +0200 +++ b/src/com/beem/project/beem/BeemService.java Tue Apr 07 15:20:28 2009 +0200 @@ -1,19 +1,5 @@ - -/** - * - */ package com.beem.project.beem; -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; - import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; @@ -21,15 +7,13 @@ 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.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; +import com.beem.project.beem.service.XmppConnectionAdapter; +import com.beem.project.beem.service.XmppFacade; +import com.beem.project.beem.service.aidl.IXmppFacade; +import com.beem.project.beem.service.aidl.IXmppConnection; /** * This class is for the Beem service. * @author darisk @@ -37,20 +21,18 @@ */ public class BeemService extends Service { - private NotificationManager notificationManager; + private NotificationManager mNotificationManager; - private IXMPPConnection connection; - private SharedPreferences settings; + private IXmppConnection mConnection; + private SharedPreferences mSettings; private String mLogin; private String mPassword; private String mHost; - private IXMPPFacade.Stub mBind; + private IXmppFacade.Stub mBind; - /* - * (non-Javadoc) - * - * @see android.app.Service#onBind(android.content.Intent) + /** + * {@inheritDoc} */ @Override public IBinder onBind(Intent intent) { @@ -60,20 +42,62 @@ // return null; } + /** + * {@inheritDoc} + */ @Override public void onCreate() { super.onCreate(); - settings = getSharedPreferences(getString(R.string.PreferenceFileName), + mSettings = getSharedPreferences(getString(R.string.PreferenceFileName), MODE_PRIVATE); - mLogin = settings.getString(getString(R.string.PreferenceLoginKey), ""); - mPassword = settings.getString( + mLogin = mSettings.getString(getString(R.string.PreferenceLoginKey), ""); + mPassword = mSettings.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); + mHost = mSettings.getString(getString(R.string.PreferenceHostKey), ""); + mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + mConnection = new XmppConnectionAdapter("10.0.2.2", mLogin, mPassword); // address + mBind = new XmppFacade((XmppConnectionAdapter) mConnection); + } + + /** + * {@inheritDoc} + */ + @Override + public void onStart(Intent intent, int startId) { + try { + mConnection.connectSync(); + } catch (RemoteException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } + /** + * {@inheritDoc} + */ + @Override + public void onDestroy() { + closeConnection(); + showBasicNotification(R.string.BeemServiceDestroyed); + } + + /** + * Close the connection to the xmpp server. + */ + private void closeConnection() { + if (mConnection != null) + try { + mConnection.disconnect(); + } catch (RemoteException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + /** + * Add a notification in the notification status bar. + * @param stringResource the ressource of the text to show + */ private void showBasicNotification(int stringResource) { String text = (String) getText(stringResource); Notification notif = new Notification(R.drawable.logo, text, System @@ -81,36 +105,11 @@ notif.defaults = Notification.DEFAULT_ALL; notif.setLatestEventInfo(this, text, text, PendingIntent.getActivity( this, 0, new Intent(), 0)); - notificationManager.notify(stringResource, notif); + mNotificationManager.notify(stringResource, notif); Toast toast = Toast.makeText(this, R.string.BeemServiceCreated, Toast.LENGTH_LONG); toast.show(); } - @Override - public void onStart(Intent intent, int startId) { - try { - connection.connectSync(); - } catch (RemoteException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Override - public void onDestroy() { - 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 31b436663df5 -r fb3e3ed4bafc src/com/beem/project/beem/jingle/Caller.java --- a/src/com/beem/project/beem/jingle/Caller.java Sun Apr 05 23:43:55 2009 +0200 +++ b/src/com/beem/project/beem/jingle/Caller.java Tue Apr 07 15:20:28 2009 +0200 @@ -1,22 +1,16 @@ package com.beem.project.beem.jingle; import java.net.UnknownHostException; - import java.util.ArrayList; import java.util.List; - import org.jivesoftware.smack.ConnectionConfiguration; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; - import org.jivesoftware.smackx.jingle.JingleManager; import org.jivesoftware.smackx.jingle.JingleSession; - import org.jivesoftware.smackx.jingle.listeners.JingleSessionListener; - import org.jivesoftware.smackx.jingle.media.JingleMediaManager; import org.jivesoftware.smackx.jingle.media.PayloadType; - import org.jivesoftware.smackx.jingle.nat.BasicTransportManager; import org.jivesoftware.smackx.jingle.nat.TransportCandidate; diff -r 31b436663df5 -r fb3e3ed4bafc src/com/beem/project/beem/jingle/RTPMediaManager.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/jingle/RTPMediaManager.java Tue Apr 07 15:20:28 2009 +0200 @@ -0,0 +1,53 @@ +package com.beem.project.beem.jingle; + +import java.util.ArrayList; +import java.util.List; + +import org.jivesoftware.smackx.jingle.JingleSession; +import org.jivesoftware.smackx.jingle.SmackLogger; +import org.jivesoftware.smackx.jingle.media.JingleMediaManager; +import org.jivesoftware.smackx.jingle.media.JingleMediaSession; +import org.jivesoftware.smackx.jingle.media.PayloadType; +import org.jivesoftware.smackx.jingle.nat.JingleTransportManager; +import org.jivesoftware.smackx.jingle.nat.TransportCandidate; + +public class RTPMediaManager extends JingleMediaManager { + + private static final SmackLogger LOGGER = SmackLogger.getLogger(RTPMediaManager.class); + + public static final String MEDIA_NAME = "RTP_BIDON"; + + private List payloads; + + public RTPMediaManager(JingleTransportManager transportManager) { + super(transportManager); + // TODO Auto-generated constructor stub + setupPayloads(); + LOGGER.info("A TestMedia Manager is created(Receiver)"); + } + + @Override + public JingleMediaSession createMediaSession(PayloadType payloadType, + TransportCandidate remote, TransportCandidate local, + JingleSession jingleSession) { + // TODO Auto-generated method stub + return new RTPMediaSession(payloadType, remote, local, null, jingleSession); + } + + @Override + public List getPayloads() { + // TODO Auto-generated method stub + return payloads; + } + + private void setupPayloads() { + payloads = new ArrayList(); + payloads.add(new PayloadType.Audio(51, "BIDON1")); + payloads.add(new PayloadType.Audio(52, "BIDON2")); + payloads.add(new PayloadType.Audio(53, "BIDON3")); + } + + public String getName() { + return MEDIA_NAME; + } +} diff -r 31b436663df5 -r fb3e3ed4bafc src/com/beem/project/beem/jingle/RTPMediaSession.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/jingle/RTPMediaSession.java Tue Apr 07 15:20:28 2009 +0200 @@ -0,0 +1,76 @@ +/** + * + */ +package com.beem.project.beem.jingle; + +import org.jivesoftware.smackx.jingle.JingleSession; +import org.jivesoftware.smackx.jingle.SmackLogger; +import org.jivesoftware.smackx.jingle.media.JingleMediaSession; +import org.jivesoftware.smackx.jingle.media.PayloadType; +import org.jivesoftware.smackx.jingle.nat.TransportCandidate; + +/** + * @author darisk + * + */ +public class RTPMediaSession extends JingleMediaSession { + + private static final SmackLogger LOGGER = SmackLogger + .getLogger(RTPMediaSession.class); + private RTPTransmitter transmitter; + private RTPReceiver receiver; + + /** + * @param payloadType + * @param remote + * @param local + * @param mediaLocator + * @param jingleSession + */ + public RTPMediaSession(PayloadType payloadType, + TransportCandidate remote, TransportCandidate local, + String mediaLocator, JingleSession jingleSession) { + + super(payloadType, remote, local, mediaLocator, jingleSession); + initialize(); + LOGGER.info("Demarrage d'une session avec local: " + local + + " #remote: " + remote); + + transmitter = new RTPTransmitter(remote.getIp(), getRemote().getPort()); + receiver = new RTPReceiver(getLocal().getPort()); + } + + @Override + public void initialize() { + // TODO Auto-generated method stub + + } + + @Override + public void setTrasmit(boolean active) { + } + + @Override + public void startReceive() { + + } + + @Override + public void startTrasmit() { + + } + + @Override + public void stopReceive() { + if (receiver != null) { + receiver.stop(); + } + } + + @Override + public void stopTrasmit() { + if (transmitter != null) { + transmitter.stop(); + } + } +} diff -r 31b436663df5 -r fb3e3ed4bafc src/com/beem/project/beem/jingle/RTPReceiver.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/jingle/RTPReceiver.java Tue Apr 07 15:20:28 2009 +0200 @@ -0,0 +1,97 @@ +package com.beem.project.beem.jingle; + +import java.io.IOException; +import java.net.DatagramSocket; +import java.net.ServerSocket; + +import org.jivesoftware.smackx.jingle.SmackLogger; + +import jlibrtp.DataFrame; +import jlibrtp.Participant; +import jlibrtp.RTPAppIntf; +import jlibrtp.RTPSession; + +public class RTPReceiver implements Runnable, RTPAppIntf{ + + RTPSession rtpSession = null; + byte[] abData = null; + private boolean killme = false; + + private static final SmackLogger LOGGER = SmackLogger.getLogger(SenderMediaManager.class); + + public RTPReceiver(int rtpPort) { + DatagramSocket rtpSocket = null; + + try { + rtpSocket = new DatagramSocket(rtpPort); + } catch (Exception e) { + System.out.println("RTPSession failed to obtain port"); + return; + } + rtpSession = new RTPSession(rtpSocket, null); + rtpSession.naivePktReception(true); + rtpSession.RTPSessionRegister(this, null, null); + } + + @Override + public void run() { + start(); + } + + private void start() { + LOGGER.info("Debut envoi de donnees par RTPTransmitter"); + while (!killme) { + try { Thread.sleep(1000); } catch(Exception e) { } + } + + try {Thread.sleep(200);} catch (Exception e) {} + this.rtpSession.endSession(); + + } + + @Override + public int frameSize(int payloadType) { + return 1; + } + + @Override + public void receiveData(DataFrame frame, Participant participant) { + //byte[] data = frame.getConcatenatedData(); + } + + @Override + public void userEvent(int type, Participant[] participant) { + //rien + + } + + public void stop() { + this.killme = true; + } + + protected int getFreePort() { + ServerSocket ss; + int freePort = 0; + + for (int i = 0; i < 10; i++) { + freePort = (int) (10000 + Math.round(Math.random() * 10000)); + freePort = freePort % 2 == 0 ? freePort : freePort + 1; + try { + ss = new ServerSocket(freePort); + freePort = ss.getLocalPort(); + ss.close(); + return freePort; + } catch (IOException e) { + e.printStackTrace(); + } + } + try { + ss = new ServerSocket(0); + freePort = ss.getLocalPort(); + ss.close(); + } catch (IOException e) { + e.printStackTrace(); + } + return freePort; + } +} diff -r 31b436663df5 -r fb3e3ed4bafc src/com/beem/project/beem/jingle/RTPTransmitter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/jingle/RTPTransmitter.java Tue Apr 07 15:20:28 2009 +0200 @@ -0,0 +1,100 @@ +package com.beem.project.beem.jingle; + +import java.io.IOException; +import java.net.DatagramSocket; +import java.net.ServerSocket; + +import org.jivesoftware.smackx.jingle.SmackLogger; + +import jlibrtp.DataFrame; +import jlibrtp.Participant; +import jlibrtp.RTPAppIntf; +import jlibrtp.RTPSession; + +public class RTPTransmitter implements Runnable, RTPAppIntf { + + private static final SmackLogger LOGGER = SmackLogger + .getLogger(SenderMediaManager.class); + private RTPSession rtpSession; + private boolean killme = false; + + public RTPTransmitter(String remoteIP, int port) { + + DatagramSocket rtpSocket = null; + int rtpPort = 0; + + try { + rtpPort = getFreePort(); + rtpSocket = new DatagramSocket(rtpPort); + } catch (Exception e) { + System.out.println("RTPSession failed to obtain port"); + return; + } + rtpSession = new RTPSession(rtpSocket, null); + rtpSession.naivePktReception(true); + rtpSession.RTPSessionRegister(this, null, null); + rtpSession.addParticipant(new Participant(remoteIP,rtpPort, 0)); + } + + private void start() { + LOGGER.info("Debut envoi de donnees par RTPTransmitter"); + while (!killme) { + rtpSession.sendData(null); + } + + try {Thread.sleep(200);} catch (Exception e) {} + this.rtpSession.endSession(); + } + + @Override + public void run() { + start(); + } + + @Override + public int frameSize(int payloadType) { + return 1; + } + + @Override + public void receiveData(DataFrame frame, Participant participant) { + //On envoie uniquement + } + + @Override + public void userEvent(int type, Participant[] participant) { + //je sais pas ce que c'est + + } + + protected int getFreePort() { + ServerSocket ss; + int freePort = 0; + + for (int i = 0; i < 10; i++) { + freePort = (int) (10000 + Math.round(Math.random() * 10000)); + freePort = freePort % 2 == 0 ? freePort : freePort + 1; + try { + ss = new ServerSocket(freePort); + freePort = ss.getLocalPort(); + ss.close(); + return freePort; + } catch (IOException e) { + e.printStackTrace(); + } + } + try { + ss = new ServerSocket(0); + freePort = ss.getLocalPort(); + ss.close(); + } catch (IOException e) { + e.printStackTrace(); + } + return freePort; + } + + public void stop() { + this.killme = true; + } + +} diff -r 31b436663df5 -r fb3e3ed4bafc src/com/beem/project/beem/jingle/Receiver.java --- a/src/com/beem/project/beem/jingle/Receiver.java Sun Apr 05 23:43:55 2009 +0200 +++ b/src/com/beem/project/beem/jingle/Receiver.java Tue Apr 07 15:20:28 2009 +0200 @@ -2,13 +2,13 @@ import java.io.IOException; import java.io.InputStream; -import java.net.ServerSocket; import java.net.Socket; import java.util.ArrayList; import java.util.List; import org.jivesoftware.smack.ConnectionConfiguration; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; +import org.jivesoftware.smackx.ServiceDiscoveryManager; import org.jivesoftware.smackx.jingle.JingleManager; import org.jivesoftware.smackx.jingle.JingleSession; import org.jivesoftware.smackx.jingle.JingleSessionRequest; @@ -18,6 +18,7 @@ import org.jivesoftware.smackx.jingle.media.PayloadType; import org.jivesoftware.smackx.jingle.nat.BasicTransportManager; import org.jivesoftware.smackx.jingle.nat.TransportCandidate; +import org.jivesoftware.smackx.packet.DiscoverInfo; public class Receiver { @@ -32,10 +33,26 @@ ConnectionConfiguration conf = new ConnectionConfiguration("nikita-rack"); conf.setRosterLoadedAtLogin(false); con = new XMPPConnection(conf); + try { + con.connect(); - con.login(username, pass, "TEST"); + JingleManager.setJingleServiceEnabled(); + ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(con); + //NOTE Classe gerant le service discovery (ce qui permet aux autres de savoir ce qu'on sait faire) + + + //Pour rajouter une liste de feature supporter (de format : "http://jabber.org/protocol/disco#info") + sdm.addFeature("http://jabber.org/protocol/disco#info"); + sdm.addFeature("TOTO"); + + con.login(username, pass, "TEST-JAVA"); initialize(); + // Le client demande les services dispo en face a son roster + // il doit en suite fournir lui meme une liste de feature + + //DiscoverInfo di = sdm.discoverInfo("test@nikita-rack/pidgin"); + //DiscoverInfo di2 = sdm.discoverInfo("nikita@nikita-rack/Telepathy"); } catch (XMPPException e) { // TODO Auto-generated catch block @@ -43,11 +60,12 @@ } } - private void initialize() - { + private void initialize() { + BasicTransportManager bt = new BasicTransportManager(); mediaManagers = new ArrayList(); - mediaManagers.add(new SenderMediaManager(new BasicTransportManager())); - JingleManager.setJingleServiceEnabled(); + mediaManagers.add(new RTPMediaManager(bt)); + mediaManagers.add(new SenderMediaManager(bt)); + jingleManager = new JingleManager(con, mediaManagers); jingleManager.addJingleSessionRequestListener(new JingleSessionRequestListener() { @@ -56,20 +74,16 @@ System.out.println("Jingle Session request from "+request.getFrom()); try { in = request.accept(); - // TODO configure in in.addListener(new JingleSessionListener() { @Override public void sessionRedirected(String redirection, JingleSession jingleSession) { - // TODO Auto-generated method stub - } @Override public void sessionMediaReceived(JingleSession jingleSession, String participant) { - // TODO Auto-generated method stub System.out.println("Session Media received from " + participant); } @@ -77,7 +91,6 @@ public void sessionEstablished(PayloadType pt, TransportCandidate remoteCandidate, TransportCandidate localCandidate, JingleSession jingleSession) { - // TODO Auto-generated method stub System.out.println("Session established"); try{ System.out.println("Je recois sur " + remoteCandidate.getIp() + ":" + remoteCandidate.getPort() ); @@ -103,13 +116,11 @@ @Override public void sessionClosed(String reason, JingleSession jingleSession) { - // TODO Auto-generated method stub System.out.println("Session "+ jingleSession.getResponder() +"closedd because "+ reason); } }); in.startIncoming(); } catch (XMPPException e) { - // TODO Auto-generated catch block e.printStackTrace(); } } @@ -141,7 +152,6 @@ * @throws InterruptedException */ public static void main(String[] args) throws InterruptedException { - // TODO Auto-generated method stub Receiver rec = new Receiver("test2", "test2"); System.out.println("Receiver initialized"); diff -r 31b436663df5 -r fb3e3ed4bafc src/com/beem/project/beem/jingle/SenderMediaManager.java --- a/src/com/beem/project/beem/jingle/SenderMediaManager.java Sun Apr 05 23:43:55 2009 +0200 +++ b/src/com/beem/project/beem/jingle/SenderMediaManager.java Tue Apr 07 15:20:28 2009 +0200 @@ -12,39 +12,42 @@ public class SenderMediaManager extends JingleMediaManager { - private static final SmackLogger LOGGER = SmackLogger.getLogger(SenderMediaManager.class); + private static final SmackLogger LOGGER = SmackLogger + .getLogger(SenderMediaManager.class); - public static final String MEDIA_NAME = "42Test"; + public static final String MEDIA_NAME = "42Test"; - private List payloads; + private List payloads; - public SenderMediaManager(JingleTransportManager transportManager) { - super(transportManager); - // TODO Auto-generated constructor stub - setupPayloads(); - LOGGER.info("A TestMedia Manager is created"); - } + public SenderMediaManager(JingleTransportManager transportManager) { + super(transportManager); + // TODO Auto-generated constructor stub + setupPayloads(); + LOGGER.info("A TestMedia Manager is created(Sender)"); + } - @Override - public JingleMediaSession createMediaSession(PayloadType payloadType, - TransportCandidate remote, TransportCandidate local, - JingleSession jingleSession) { - // TODO Auto-generated method stub - return new SenderMediaSession(payloadType, remote, local, null, jingleSession); - } + @Override + public JingleMediaSession createMediaSession(PayloadType payloadType, + TransportCandidate remote, TransportCandidate local, + JingleSession jingleSession) { + // TODO Auto-generated method stub + return new RTPMediaSession(payloadType, remote, local, null, + jingleSession); + } - @Override - public List getPayloads() { - return payloads; - } + @Override + public List getPayloads() { + return payloads; + } - private void setupPayloads() { - payloads = new ArrayList(); - payloads.add(new PayloadType.Audio(42, "Test")); - } + private void setupPayloads() { + payloads = new ArrayList(); + payloads.add(new PayloadType.Audio(42, "Test")); + payloads.add(new PayloadType.Audio(15, "Speex")); + } - @Override - public String getName() { - return MEDIA_NAME; - } + @Override + public String getName() { + return MEDIA_NAME; + } } diff -r 31b436663df5 -r fb3e3ed4bafc src/com/beem/project/beem/provider/BeemDatabaseHelper.java --- a/src/com/beem/project/beem/provider/BeemDatabaseHelper.java Sun Apr 05 23:43:55 2009 +0200 +++ b/src/com/beem/project/beem/provider/BeemDatabaseHelper.java Tue Apr 07 15:20:28 2009 +0200 @@ -23,6 +23,7 @@ public void onCreate(SQLiteDatabase db) { db.execSQL(this.creationQuery); } + @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { diff -r 31b436663df5 -r fb3e3ed4bafc src/com/beem/project/beem/provider/ContactProvider.java --- a/src/com/beem/project/beem/provider/ContactProvider.java Sun Apr 05 23:43:55 2009 +0200 +++ b/src/com/beem/project/beem/provider/ContactProvider.java Tue Apr 07 15:20:28 2009 +0200 @@ -9,7 +9,6 @@ import android.content.ContentUris; import android.content.ContentValues; import android.content.UriMatcher; -import android.content.res.Resources; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; diff -r 31b436663df5 -r fb3e3ed4bafc src/com/beem/project/beem/service/BeemChatManager.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/BeemChatManager.java Tue Apr 07 15:20:28 2009 +0200 @@ -0,0 +1,135 @@ +/** + * + */ +package com.beem.project.beem.service; + +import java.util.HashMap; +import java.util.Map; + +import org.jivesoftware.smack.Chat; +import org.jivesoftware.smack.ChatManager; +import org.jivesoftware.smack.ChatManagerListener; +import org.jivesoftware.smack.MessageListener; + +import android.os.RemoteCallbackList; +import android.os.RemoteException; +import android.util.Log; + +import com.beem.project.beem.service.aidl.IChat; +import com.beem.project.beem.service.aidl.IChatManager; +import com.beem.project.beem.service.aidl.IChatManagerListener; +import com.beem.project.beem.service.aidl.IMessageListener; + +/** + * An adapter for smack's ChatManager. This class provides functionnality to handle chats. + * @author darisk + */ +public class BeemChatManager extends IChatManager.Stub { + + /** + * Tag to use with log methods. + */ + public static final String TAG = "BeemChatManager"; + private ChatManager mAdaptee; + private Map mChats = new HashMap(); + private ChatListener mChatListener = new ChatListener(); + private RemoteCallbackList mRemoteChatCreationListeners = + new RemoteCallbackList(); + + /** + * Constructor. + * @param chatManager the smack ChatManager to adapt + */ + public BeemChatManager(final ChatManager chatManager) { + // TODO Auto-generated constructor stub + mAdaptee = chatManager; + mAdaptee.addChatListener(mChatListener); + } + + /** + * Create a chat session. + * @param jid the jid of the contact you want to chat with + * @param listener listener to use for chat events on this chat session + * @return the chat session + */ + public Chat createChat(String jid, MessageListener listener) { + return mAdaptee.createChat(jid, listener); + } + + /** + * Create a chat session. + * @param contact the contact you want to chat with + * @param listener listener to use for chat events on this chat session + * @return the chat session + */ + public Chat createChat(Contact contact, MessageListener listener) { + String jid = contact.getJID(); + return createChat(jid, listener); + } + + /** + * {@inheritDoc} + */ + @Override + public void addChatCreationListener(IChatManagerListener listener) throws RemoteException { + // TODO Auto-generated method stub + mRemoteChatCreationListeners.register(listener); + } + + /** + * {@inheritDoc} + */ + @Override + public IChat createChat(Contact contact, IMessageListener listener) throws RemoteException { + // TODO Auto-generated method stub + return null; + } + + /** + * {@inheritDoc} + */ + @Override + public void removeChatCreationListener(IChatManagerListener listener) throws RemoteException { + // TODO Auto-generated method stub + mRemoteChatCreationListeners.unregister(listener); + } + + /** + * A listener for all the chat creation event that happens on the connection. + * @author darisk + */ + private class ChatListener implements ChatManagerListener { + + /** + * Constructor. + */ + public ChatListener() { + // TODO Auto-generated constructor stub + } + + /** + * {@inheritDoc} + */ + @Override + public void chatCreated(Chat chat, boolean locally) { + if (!locally) { + mChats.put(chat.getParticipant(), chat); + } + final int n = mRemoteChatCreationListeners.beginBroadcast(); + + for (int i = 0; i < n; i++) { + IChatManagerListener listener = mRemoteChatCreationListeners.getBroadcastItem(i); + try { + IChat newchat = new ChatAdapter(chat); + listener.chatCreated(newchat, locally); + } catch (RemoteException e) { + // The RemoteCallbackList will take care of removing the + // dead listeners. + Log.w(TAG, "Error while triggering remote connection listeners", e); + } + } + mRemoteChatCreationListeners.finishBroadcast(); + } + } + +} diff -r 31b436663df5 -r fb3e3ed4bafc src/com/beem/project/beem/service/ChatAdapter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/ChatAdapter.java Tue Apr 07 15:20:28 2009 +0200 @@ -0,0 +1,57 @@ +/** + * + */ +package com.beem.project.beem.service; + +import org.jivesoftware.smack.Chat; +import org.jivesoftware.smack.XMPPException; + +import android.os.RemoteException; + +import com.beem.project.beem.service.aidl.IChat; + +/** + * An adapter for smack's Chat class. + * @author darisk + */ +public class ChatAdapter extends IChat.Stub { + private Chat mAdaptee; + private Contact mParticipant; + + /** + * Constructor. + * @param chat The chat to adapt + */ + public ChatAdapter(final Chat chat) { + mAdaptee = chat; + mParticipant = new Contact(chat.getParticipant()); + } + + /** + * {@inheritDoc} + */ + @Override + public Contact getParticipant() throws RemoteException { + return mParticipant; + } + + /** + * {@inheritDoc} + */ + @Override + public void sendMessage(Message message) throws RemoteException { + org.jivesoftware.smack.packet.Message send = new org.jivesoftware.smack.packet.Message(); + send.setTo(message.getTo()); + send.setBody(message.getBody()); + send.setThread(message.getThread()); + send.setSubject(message.getSubject()); + send.setType(org.jivesoftware.smack.packet.Message.Type.chat); + try { + mAdaptee.sendMessage(send); + } catch (XMPPException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + +} diff -r 31b436663df5 -r fb3e3ed4bafc src/com/beem/project/beem/service/Contact.java --- a/src/com/beem/project/beem/service/Contact.java Sun Apr 05 23:43:55 2009 +0200 +++ b/src/com/beem/project/beem/service/Contact.java Tue Apr 07 15:20:28 2009 +0200 @@ -3,8 +3,16 @@ */ package com.beem.project.beem.service; +import java.util.ArrayList; +import java.util.List; + +import org.jivesoftware.smack.RosterEntry; +import org.jivesoftware.smack.packet.Presence; +import org.jivesoftware.smack.packet.Presence.Mode; + import android.os.Parcel; import android.os.Parcelable; +import android.util.Log; /** * This class contains informations on a jabber contact. @@ -12,6 +20,20 @@ */ public class Contact implements Parcelable { + public static final int CONTACT_STATUS_DISCONNECT = 100; + public static final int CONTACT_STATUS_UNAVAILABLE = 200; + public static final int CONTACT_STATUS_AWAY = 300; + public static final int CONTACT_STATUS_BUSY = 400; + public static final int CONTACT_STATUS_AVAILABLE = 500; + public static final int CONTACT_STATUS_AVAILABLE_FOR_CHAT = 600; + private static final String TAG = "Contact"; + + private int mID; + private int mStatus; + private String mJID; + private String mMsgState; + private List mRes; + /** * Parcelable.Creator needs by Android. */ @@ -28,10 +50,39 @@ } }; - private String mJID; - private int mID; - private int mStatus; - private String mMsgState; + /** + * Construct a contact from a parcel. + * @param in parcel to use for construction + */ + private Contact(final Parcel in) { + mID = in.readInt(); + mStatus = in.readInt(); + mJID = in.readString(); + mMsgState = in.readString(); + mRes = new ArrayList(); + in.readStringList(mRes); + } + + /** + * {@inheritDoc} + */ + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(mID); + dest.writeInt(mStatus); + dest.writeString(mJID); + dest.writeString(mMsgState); + dest.writeStringList(getMRes()); + } + + /** + * {@inheritDoc} + */ + @Override + public int describeContents() { + // TODO Auto-generated method stub + return 0; + } /** * Constructor. @@ -46,14 +97,85 @@ */ public Contact(final String jid) { mJID = jid; + mStatus = Contact.CONTACT_STATUS_DISCONNECT; + mRes = new ArrayList(); + mRes.add("none"); + } + + /** + * @return the mID + */ + public int getID() { + return mID; + } + + /** + * @param mid the mID to set + */ + public void setID(int mid) { + mID = mid; + } + + /** + * @return the mStatus + */ + public int getStatus() { + return mStatus; + } + + /** + * @param status the mStatus to set + */ + public void setStatus(int status) { + mStatus = status; } /** - * Construct a contact from a parcel. - * @param in parcel to use for construction + * @param presence the presence containing status */ - private Contact(final Parcel in) { + public void setStatus(Presence presence) { + 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) { + case available: + mStatus = Contact.CONTACT_STATUS_AVAILABLE; + break; + case away: + mStatus = Contact.CONTACT_STATUS_AWAY; + break; + case chat: + mStatus = Contact.CONTACT_STATUS_AVAILABLE_FOR_CHAT; + break; + case dnd: + mStatus = Contact.CONTACT_STATUS_BUSY; + break; + case xa: + mStatus = Contact.CONTACT_STATUS_UNAVAILABLE; + break; + default: + Log.e("RosterAdapter", "Status mode non gere"); + mStatus = Contact.CONTACT_STATUS_DISCONNECT; + break; + } + } + } + /** + * @return the mMsgState + */ + public String getMMsgState() { + return mMsgState; + } + + /** + * @param msgState the mMsgState to set + */ + public void setMMsgState(String msgState) { + mMsgState = msgState; } /** @@ -72,22 +194,26 @@ mJID = mjid; } - /** - * {@inheritDoc} - */ - @Override - public int describeContents() { - // TODO Auto-generated method stub - return 0; + public void addRes(String res) { + if (!mRes.contains(res)) + mRes.add(res); + } + + public void delRes(String res) { + mRes.remove(res); } /** - * {@inheritDoc} + * @param mRes the mRes to set */ - @Override - public void writeToParcel(Parcel dest, int flags) { - // TODO Auto-generated method stub + public void setMRes(List mRes) { + this.mRes = mRes; } - + /** + * @return the mRes + */ + public List getMRes() { + return mRes; + } } diff -r 31b436663df5 -r fb3e3ed4bafc src/com/beem/project/beem/service/Message.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/Message.java Tue Apr 07 15:20:28 2009 +0200 @@ -0,0 +1,196 @@ +/** + * + */ +package com.beem.project.beem.service; + +import android.os.Parcel; +import android.os.Parcelable; + +/** + * This class represents a instant message. + * @author darisk + */ +public class Message implements Parcelable { + + /** + * Normal message type. + * Theese messages are like an email, with subject. + */ + public static final int MSG_TYPE_NORMAL = 100; + + /** + * Chat message type. + */ + public static final int MSG_TYPE_CHAT = 200; + + /** + * Group chat message type. + */ + public static final int MSG_TYPE_GROUP_CHAT = 300; + + private int mType; + private String mBody; + private String mSubject; + private String mTo; + private String mThread; + + /** + * Parcelable.Creator needs by Android. + */ + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + + @Override + public Message createFromParcel(Parcel source) { + return new Message(source); + } + + @Override + public Message[] newArray(int size) { + return new Message[size]; + } + }; + + /** + * Constructor. + * @param to the destinataire of the message + * @param type the message type + */ + public Message(final String to, final int type) { + mTo = to; + mType = type; + mBody = ""; + mSubject = ""; + mThread = ""; + } + + /** + * Constructor a message of type chat. + * @param to the destinataire of the message + */ + public Message(final String to) { + this(to, MSG_TYPE_CHAT); + } + + /** + * Construct a message from a parcel. + * @param in parcel to use for construction + */ + private Message(final Parcel in) { + mType = in.readInt(); + mTo = in.readString(); + mBody = in.readString(); + mSubject = in.readString(); + mThread = in.readString(); + } + + /** + * {@inheritDoc} + */ + @Override + public void writeToParcel(Parcel dest, int flags) { + // TODO Auto-generated method stub + dest.writeInt(mType); + dest.writeString(mTo); + dest.writeString(mBody); + dest.writeString(mSubject); + dest.writeString(mThread); + } + + /** + * Get the type of the message. + * @return the type of the message. + */ + public int getType() { + return mType; + } + + /** + * Set the type of the message. + * @param type the type to set + */ + public void setType(int type) { + mType = type; + } + + + /** + * Get the body of the message. + * @return the Body of the message + */ + public String getBody() { + return mBody; + } + + + /** + * Set the body of the message. + * @param body the body to set + */ + public void setBody(String body) { + mBody = body; + } + + + /** + * Get the subject of the message. + * @return the subject + */ + public String getSubject() { + return mSubject; + } + + + /** + * Set the subject of the message. + * @param subject the subject to set + */ + public void setSubject(String subject) { + mSubject = subject; + } + + + /** + * Get the destinataire of the message. + * @return the destinataire of the message + */ + public String getTo() { + return mTo; + } + + + /** + * Set the destinataire of the message. + * @param to the destinataire to set + */ + public void setTo(String to) { + mTo = to; + } + + + /** + * Get the thread of the message. + * @return the thread + */ + public String getThread() { + return mThread; + } + + + /** + * Set the thread of the message. + * @param thread the thread to set + */ + public void setThread(String thread) { + mThread = thread; + } + + /** + * {@inheritDoc} + */ + @Override + public int describeContents() { + // TODO Auto-generated method stub + return 0; + } + +} diff -r 31b436663df5 -r fb3e3ed4bafc src/com/beem/project/beem/service/PresenceAdapter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/PresenceAdapter.java Tue Apr 07 15:20:28 2009 +0200 @@ -0,0 +1,54 @@ +package com.beem.project.beem.service; + +import org.jivesoftware.smack.packet.Presence; + +import android.os.IBinder; +import android.os.Parcel; +import android.os.Parcelable; + +public class PresenceAdapter implements Parcelable { + + private Presence mPresence; + + /** + * Parcelable.Creator needs by Android. + */ + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + + @Override + public PresenceAdapter createFromParcel(Parcel source) { + return new PresenceAdapter(source); + } + + @Override + public PresenceAdapter[] newArray(int size) { + return new PresenceAdapter[size]; + } + }; + + public PresenceAdapter(Presence presence) { + mPresence = presence; + } + + + public PresenceAdapter(Parcel source) { + // TODO Auto-generated constructor stub + } + + @Override + public int describeContents() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + // TODO Auto-generated method stub + + } + + public IBinder asBinder() { + // TODO Auto-generated method stub + return null; + } +} diff -r 31b436663df5 -r fb3e3ed4bafc src/com/beem/project/beem/service/RosterAdapter.java --- a/src/com/beem/project/beem/service/RosterAdapter.java Sun Apr 05 23:43:55 2009 +0200 +++ b/src/com/beem/project/beem/service/RosterAdapter.java Tue Apr 07 15:20:28 2009 +0200 @@ -1,18 +1,27 @@ /** - * + * */ package com.beem.project.beem.service; import java.util.ArrayList; +import java.util.Collection; 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.RosterGroup; +import org.jivesoftware.smack.RosterListener; import org.jivesoftware.smack.XMPPException; +import org.jivesoftware.smack.packet.Presence; +import org.jivesoftware.smack.util.StringUtils; +import com.beem.project.beem.service.aidl.IBeemRosterListener; + +import android.os.RemoteCallbackList; import android.os.RemoteException; +import android.util.Log; /** * This class implement a Roster adapter for BEEM. @@ -20,33 +29,33 @@ */ public class RosterAdapter extends com.beem.project.beem.service.aidl.IRoster.Stub { + private static final String TAG = "RosterAdapter"; private Roster mAdaptee; + private RemoteCallbackList mRemoteRosListeners = + new RemoteCallbackList(); private Map mContacts = new HashMap(); + private RosterListenerAdapter mRosterListener = new RosterListenerAdapter(); + /** * Constructor. * @param roster the roster to adapt */ public RosterAdapter(final Roster roster) { mAdaptee = roster; + roster.addRosterListener(mRosterListener); for (RosterEntry entry : roster.getEntries()) { - String user = entry.getUser(); - mContacts.put(user, new Contact(user)); + String user = StringUtils.parseBareAddress(entry.getUser()); + if ( !mContacts.containsKey(user)) + 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 { @@ -64,13 +73,21 @@ */ @Override public void deleteContact(Contact contact) throws RemoteException { - // TODO Auto-generated method stub - + mContacts.remove(contact.getJID()); } - /** - * {@inheritDoc} - */ + @Override + public void addConnectionListener(IBeemRosterListener listen) throws RemoteException { + if (listen != null) + mRemoteRosListeners.register(listen); + } + + @Override + public void removeConnectionListener(IBeemRosterListener listen) throws RemoteException { + if (listen != null) + mRemoteRosListeners.unregister(listen); + } + @Override public Contact getContact(String jid) throws RemoteException { return mContacts.get(jid); @@ -86,4 +103,109 @@ return res; } + private class RosterListenerAdapter implements RosterListener { + + @Override + public void entriesAdded(Collection addresses) { + Log.i(TAG, "Ajout de l'entry"); + final int n = mRemoteRosListeners.beginBroadcast(); + + List tab = new ArrayList(); + for (int i = 0; i < n; i++) { + IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i); + try { + tab.addAll(addresses); + listener.onEntriesAdded(tab); + } catch (RemoteException e) { + // The RemoteCallbackList will take care of removing the + // dead listeners. + Log.w(TAG, "Error while adding roster entries", e); + } + } + mRemoteRosListeners.finishBroadcast(); + } + + @Override + public void entriesDeleted(Collection addresses) { + Log.i(TAG, "Suppression de l'entry"); + final int n = mRemoteRosListeners.beginBroadcast(); + + List tab = new ArrayList(); + for (int i = 0; i < n; i++) { + IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i); + try { + tab.addAll(addresses); + listener.onEntriesDeleted(tab); + } catch (RemoteException e) { + // The RemoteCallbackList will take care of removing the + // dead listeners. + Log.w(TAG, "Error while deleting roster entries", e); + } + } + mRemoteRosListeners.finishBroadcast(); + } + + @Override + public void entriesUpdated(Collection addresses) { + Log.i(TAG, "Update de l'entry"); + final int n = mRemoteRosListeners.beginBroadcast(); + + List tab = new ArrayList(); + for (int i = 0; i < n; i++) { + IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i); + try { + tab.addAll(addresses); + listener.onEntriesUpdated(tab); + } catch (RemoteException e) { + // The RemoteCallbackList will take care of removing the + // dead listeners. + Log.w(TAG, "Error while updating roster entries", e); + } + } + mRemoteRosListeners.finishBroadcast(); + } + + @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); + Contact c = mContacts.get(StringUtils.parseBareAddress(user)); + if (c == null) { + c = new Contact(user); + mContacts.put(user, c); + } + c.addRes(StringUtils.parseResource(presence.getFrom())); + c.setStatus(mAdaptee.getPresence(presence.getFrom())); + /* redispatch vers les IBeemRosterListener */ + final int n = mRemoteRosListeners.beginBroadcast(); + + for (int i = 0; i < n; i++) { + IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i); + try { + listener.onPresenceChanged(new PresenceAdapter(presence)); + } catch (RemoteException e) { + // The RemoteCallbackList will take care of removing the + // dead listeners. + Log.w(TAG, "Error while updating roster entries", e); + } + } + mRemoteRosListeners.finishBroadcast(); + } + } + + /** + * {@inheritDoc} + */ + @Override + public List getGroupsNames() throws RemoteException { + Collection groups = mAdaptee.getGroups(); + ArrayList result = new ArrayList(groups.size()); + for (RosterGroup rosterGroup : groups) { + result.add(rosterGroup.getName()); + } + return result; + } + } diff -r 31b436663df5 -r fb3e3ed4bafc src/com/beem/project/beem/service/XMPPConnectionAdapter.java --- a/src/com/beem/project/beem/service/XMPPConnectionAdapter.java Sun Apr 05 23:43:55 2009 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,323 +0,0 @@ -/** - * - */ -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 31b436663df5 -r fb3e3ed4bafc src/com/beem/project/beem/service/XMPPFacade.java --- a/src/com/beem/project/beem/service/XMPPFacade.java Sun Apr 05 23:43:55 2009 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -/** - * - */ -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 31b436663df5 -r fb3e3ed4bafc 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 Tue Apr 07 15:20:28 2009 +0200 @@ -0,0 +1,316 @@ +/** + * + */ +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.IChatManager; +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 IChatManager mChatManager; + private String mLogin; + private String mPassword; + private RosterAdapter mRoster; + private Object mLastException; + + 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"); + 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; + } + + /** + * {@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); + } + + /** + * {@inheritDoc} + */ + @Override + public IChatManager getChatManager() throws RemoteException { + return mChatManager; + } + + /** + * Trigger Connection event. + */ + private void triggerAsynchronousConnectEvent() { + mConListener.onConnect(); + } + + /** + * enregistre les features dispo dans notre version Liste de features que Telepathy supporte. + */ + 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"); + + } + + /** + * 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(); + } + + } + + public boolean isAuthentificated() throws RemoteException { + return mAdaptee.isAuthenticated(); + } + +} diff -r 31b436663df5 -r fb3e3ed4bafc 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 Tue Apr 07 15:20:28 2009 +0200 @@ -0,0 +1,73 @@ +package com.beem.project.beem.service; +import android.os.RemoteException; + +import com.beem.project.beem.service.aidl.IChatManager; +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 a facade for the Beem Service. + * @author darisk + */ +public class XmppFacade extends IXmppFacade.Stub { + + private XmppConnectionAdapter mConnexion; + + /** + * Constructor for XMPPFacade. + * @param connection the connection use by the facade + */ + public XmppFacade(final XmppConnectionAdapter connection) { + this.mConnexion = connection; + } + + /** + * {@inheritDoc} + */ + @Override + public void connectAsync() throws RemoteException { + mConnexion.connectAsync(); + } + + /** + * {@inheritDoc} + */ + @Override + public void connectSync() throws RemoteException { + mConnexion.connectSync(); + } + + /** + * {@inheritDoc} + */ + @Override + public IXmppConnection createConnection() throws RemoteException { + return mConnexion; + } + + /** + * {@inheritDoc} + */ + @Override + public void disconnect() throws RemoteException { + mConnexion.disconnect(); + } + + /** + * {@inheritDoc} + */ + @Override + public IRoster getRoster() throws RemoteException { + return mConnexion.getRoster(); + } + + /** + * {@inheritDoc} + */ + @Override + public IChatManager getChatManager() throws RemoteException { + return mConnexion.getChatManager(); + } + +} diff -r 31b436663df5 -r fb3e3ed4bafc src/com/beem/project/beem/service/aidl/IBeemConnectionListener.aidl --- a/src/com/beem/project/beem/service/aidl/IBeemConnectionListener.aidl Sun Apr 05 23:43:55 2009 +0200 +++ b/src/com/beem/project/beem/service/aidl/IBeemConnectionListener.aidl Tue Apr 07 15:20:28 2009 +0200 @@ -1,17 +1,39 @@ package com.beem.project.beem.service.aidl; +/** + * Interface to listen for connection events + * @author Da Risk + */ interface IBeemConnectionListener { + /** + * Callback to call when the connection is closed + */ void connectionClosed(); + /** + * Callback to call when the connection occurs + */ void onConnect(); //void connectionClosedOnError(in Exception e); + /** + * Callback to call when the connection is closed on error + */ void connectionClosedOnError(); + /** + * Callback to call when trying to reconnecting + */ void reconnectingIn(in int seconds); + /** + * Callback to call when the reconnection has failed + */ void reconnectionFailed(); + /** + * Callback to call when the reconnection is successfull + */ void reconnectionSuccessful(); } diff -r 31b436663df5 -r fb3e3ed4bafc src/com/beem/project/beem/service/aidl/IBeemRosterListener.aidl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/aidl/IBeemRosterListener.aidl Tue Apr 07 15:20:28 2009 +0200 @@ -0,0 +1,10 @@ +package com.beem.project.beem.service.aidl; + +import com.beem.project.beem.service.PresenceAdapter; + +interface IBeemRosterListener { + void onEntriesAdded(in List addresses); + void onEntriesUpdated(in List addresses); + void onEntriesDeleted(in List addresses); + void onPresenceChanged(in PresenceAdapter presence); +} \ No newline at end of file diff -r 31b436663df5 -r fb3e3ed4bafc src/com/beem/project/beem/service/aidl/IChat.aidl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/aidl/IChat.aidl Tue Apr 07 15:20:28 2009 +0200 @@ -0,0 +1,22 @@ +package com.beem.project.beem.service.aidl; + +import com.beem.project.beem.service.Contact; +import com.beem.project.beem.service.Message; + +/** + * An aidl interface for Chat session. + */ +interface IChat { + + /** + * Send a message. + * @param message the message to send + */ + void sendMessage(in Message message); + + /** + * Get the participant of the chat + * @return the participant + */ + Contact getParticipant(); +} \ No newline at end of file diff -r 31b436663df5 -r fb3e3ed4bafc src/com/beem/project/beem/service/aidl/IChatManager.aidl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/aidl/IChatManager.aidl Tue Apr 07 15:20:28 2009 +0200 @@ -0,0 +1,35 @@ +package com.beem.project.beem.service.aidl; + +import com.beem.project.beem.service.Contact; +import com.beem.project.beem.service.aidl.IChat; +import com.beem.project.beem.service.aidl.IMessageListener; +import com.beem.project.beem.service.aidl.IChatManagerListener; + +/** + * Aidl interface for a chat manager. + * The chat manager will manage all the chat sessions. + */ +interface IChatManager { + + //IChat createChat(in String jid, in IMessageListener listener); + + /** + * Create a chat session with a contact. + * @param contact the contact to chat with + * @param listener the callback to call when a new message comes from this chat session + * @return the chat session + */ + IChat createChat(in Contact contact, in IMessageListener listener); + + /** + * Register a callback to call when a new chat session is created. + * @param listener the callback to add + */ + void addChatCreationListener(in IChatManagerListener listener); + + /** + * Remove a callback for the creation of new chat session. + * @param listener the callback to remove. + */ + void removeChatCreationListener(in IChatManagerListener listener); +} \ No newline at end of file diff -r 31b436663df5 -r fb3e3ed4bafc src/com/beem/project/beem/service/aidl/IChatManagerListener.aidl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/aidl/IChatManagerListener.aidl Tue Apr 07 15:20:28 2009 +0200 @@ -0,0 +1,18 @@ +package com.beem.project.beem.service.aidl; + +import com.beem.project.beem.service.aidl.IChat; + +/** + * Aidl interface for ChatManager listener. + * This listener will execute on events like creation of chat session. + */ +interface IChatManagerListener { + + /** + * Call when a new chat session is created. + * @param chat the created chat session + * @param locally true if the session is create by a chat manager. + */ + void chatCreated(IChat chat, boolean locally); + +} \ No newline at end of file diff -r 31b436663df5 -r fb3e3ed4bafc src/com/beem/project/beem/service/aidl/IContact.aidl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/aidl/IContact.aidl Tue Apr 07 15:20:28 2009 +0200 @@ -0,0 +1,9 @@ +package com.beem.project.beem.service.aidl; + +interface IContact { + + String getJID(); + + void setJID(String mjid); + +} \ No newline at end of file diff -r 31b436663df5 -r fb3e3ed4bafc src/com/beem/project/beem/service/aidl/IMessageListener.aidl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/aidl/IMessageListener.aidl Tue Apr 07 15:20:28 2009 +0200 @@ -0,0 +1,9 @@ +package com.beem.project.beem.service.aidl; + +import com.beem.project.beem.service.Message; +import com.beem.project.beem.service.aidl.IChat; + +interface IMessageListener { + + void processMessage(in IChat chat, in Message msg); +} diff -r 31b436663df5 -r fb3e3ed4bafc src/com/beem/project/beem/service/aidl/IRoster.aidl --- a/src/com/beem/project/beem/service/aidl/IRoster.aidl Sun Apr 05 23:43:55 2009 +0200 +++ b/src/com/beem/project/beem/service/aidl/IRoster.aidl Tue Apr 07 15:20:28 2009 +0200 @@ -1,5 +1,6 @@ package com.beem.project.beem.service.aidl; +import com.beem.project.beem.service.aidl.IBeemRosterListener; import com.beem.project.beem.service.Contact; interface IRoster { @@ -12,6 +13,11 @@ void createGroup(in String groupname); - List getContactList(); + List getContactList(); + + List getGroupsNames(); + + void addConnectionListener(in IBeemRosterListener listen); + void removeConnectionListener(in IBeemRosterListener listen); } \ No newline at end of file diff -r 31b436663df5 -r fb3e3ed4bafc src/com/beem/project/beem/service/aidl/IXMPPConnection.aidl --- a/src/com/beem/project/beem/service/aidl/IXMPPConnection.aidl Sun Apr 05 23:43:55 2009 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -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 31b436663df5 -r fb3e3ed4bafc src/com/beem/project/beem/service/aidl/IXMPPFacade.aidl --- a/src/com/beem/project/beem/service/aidl/IXMPPFacade.aidl Sun Apr 05 23:43:55 2009 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -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 31b436663df5 -r fb3e3ed4bafc 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 Tue Apr 07 15:20:28 2009 +0200 @@ -0,0 +1,23 @@ +package com.beem.project.beem.service.aidl; + +import com.beem.project.beem.service.aidl.IRoster; +import com.beem.project.beem.service.aidl.IBeemConnectionListener; +import com.beem.project.beem.service.aidl.IChatManager; + +interface IXmppConnection { + + boolean connectSync(); + + void connectAsync(); + + boolean disconnect(); + + IRoster getRoster(); + + void addConnectionListener(in IBeemConnectionListener listen); + void removeConnectionListener(in IBeemConnectionListener listen); + + boolean isAuthentificated(); + + IChatManager getChatManager(); +} \ No newline at end of file diff -r 31b436663df5 -r fb3e3ed4bafc 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 Tue Apr 07 15:20:28 2009 +0200 @@ -0,0 +1,21 @@ +package com.beem.project.beem.service.aidl; + +import com.beem.project.beem.service.aidl.IXmppConnection; +import com.beem.project.beem.service.aidl.IRoster; +import com.beem.project.beem.service.aidl.IChatManager; + +interface IXmppFacade { + + IXmppConnection createConnection(); + + IRoster getRoster(); + + void connectSync(); + + void connectAsync(); + + void disconnect(); + + IChatManager getChatManager(); + +} diff -r 31b436663df5 -r fb3e3ed4bafc src/com/beem/project/beem/ui/Beem.java --- a/src/com/beem/project/beem/ui/Beem.java Sun Apr 05 23:43:55 2009 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,115 +0,0 @@ -package com.beem.project.beem.ui; - -import android.app.Activity; -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; -import android.view.View; -import android.view.View.OnClickListener; -import android.widget.Button; -import android.widget.ImageButton; -import com.beem.project.beem.BeemApplication; -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 ImageButton mAvatar; - private Handler mHandler; - private BeemApplication mBeemApplication; - - /** - * Default constructor. - */ - public Beem() { - super(); - mHandler = new Handler(); - } - - - /** - * Called when the activity is first created. - * @param savedInstanceState - * previous state. - */ - @Override - public final void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - mBeemApplication = BeemApplication.getApplication(this); - setTheme(R.style.customtheme_login); - 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(); - } - - /** - * Callback for menu creation. - * @param menu - * the menu created - * @return true on success, false otherwise - */ - @Override - 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 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; - } - } - - /** - * 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 31b436663df5 -r fb3e3ed4bafc src/com/beem/project/beem/ui/BeemDialogSettings.java --- a/src/com/beem/project/beem/ui/BeemDialogSettings.java Sun Apr 05 23:43:55 2009 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,76 +0,0 @@ -package com.beem.project.beem.ui; - -import android.app.Dialog; -import android.content.Context; -import android.content.SharedPreferences; -import android.view.View; -import android.widget.Button; -import android.widget.EditText; - -import com.beem.project.beem.R; - -/** - * - */ -public class BeemDialogSettings extends Dialog implements - android.view.View.OnClickListener { - - private Beem mbeem; - - private SharedPreferences mSettings; - - public BeemDialogSettings(Beem beem, SharedPreferences settings) { - super(beem); - this.mbeem = beem; - this.mSettings = settings; - } - - @Override - protected void onStart() { - super.onStart(); - setContentView(R.layout.beemdialogsettings); - getWindow().setFlags(4, 4); - setTitle("Jabber Account Settings"); - showSettings(); - Button ok = (Button) findViewById(R.id.ok); - ok.setOnClickListener(this); - } - - @Override - public void onClick(View v) { - SharedPreferences.Editor editor = mSettings.edit(); - Context ctx = getContext(); - editor.putString(ctx.getString(R.string.PreferenceHostKey), - getWidgetText(R.id.host)); - editor.putString(ctx.getString(R.string.PreferencePortKey), - getWidgetText(R.id.port)); - editor.putString(ctx.getString(R.string.PreferenceLoginKey), - getWidgetText(R.id.userid)); - editor.putString(ctx.getString(R.string.PreferencePasswordKey), - getWidgetText(R.id.password)); - editor.commit(); - this.mbeem.showJID(); - dismiss(); - } - - private void showSettings() { - String tmp; - EditText eHost = (EditText) findViewById(R.id.host); - if ((tmp = mSettings.getString("host", "")) != "") - eHost.setText(tmp); - EditText ePort = (EditText) findViewById(R.id.port); - if ((tmp = mSettings.getString("port", "")) != "") - ePort.setText(tmp); - EditText eLogin = (EditText) findViewById(R.id.userid); - if ((tmp = mSettings.getString("login", "")) != "") - eLogin.setText(tmp); - EditText ePwd = (EditText) findViewById(R.id.password); - if ((tmp = mSettings.getString("password", "")) != "") - ePwd.setText(tmp); - } - - private String getWidgetText(int id) { - EditText widget = (EditText) this.findViewById(id); - return widget.getText().toString(); - } -} diff -r 31b436663df5 -r fb3e3ed4bafc src/com/beem/project/beem/ui/ContactList.java --- a/src/com/beem/project/beem/ui/ContactList.java Sun Apr 05 23:43:55 2009 +0200 +++ b/src/com/beem/project/beem/ui/ContactList.java Tue Apr 07 15:20:28 2009 +0200 @@ -4,14 +4,20 @@ import java.util.HashMap; import java.util.List; import java.util.Map; + import android.app.ExpandableListActivity; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; +import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.Handler; import android.os.RemoteException; import android.util.Log; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.ExpandableListAdapter; @@ -19,95 +25,196 @@ import android.widget.ImageView; import android.widget.SimpleExpandableListAdapter; import android.widget.TextView; + import com.beem.project.beem.BeemApplication; import com.beem.project.beem.R; import com.beem.project.beem.service.Contact; -import com.beem.project.beem.service.aidl.IXMPPFacade; +import com.beem.project.beem.service.aidl.IXmppFacade; +import com.beem.project.beem.service.aidl.IRoster; public class ContactList extends ExpandableListActivity { private static final String TAG = "CONTACTLIST_ACT"; - private IXMPPFacade mService = null; + private IXmppFacade mService = null; + private SharedPreferences mSettings; private Handler mHandler; private BeemApplication mBeemApplication; + private ContactListDialogSettings mDialog; + + @SuppressWarnings("unchecked") + @Override + public boolean onChildClick(ExpandableListView parent, View v, + int groupPosition, int childPosition, long id) { + Intent i = new Intent(this, SendIM.class); + Map child = (HashMap) parent + .getExpandableListAdapter().getChild(groupPosition, + childPosition); + i.putExtra("contact", child.get("CHILD")); + startActivity(i); + return true; + } @Override - public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { - startActivity(new Intent(this, SendIM.class)); - return true; - - }; - - @Override - public void onCreate(Bundle saveBundle) { + protected void onCreate(Bundle saveBundle) { super.onCreate(saveBundle); mHandler = new Handler(); mBeemApplication = BeemApplication.getApplication(this); + mSettings = getSharedPreferences( + getString(R.string.PreferenceFileName), MODE_PRIVATE); + mDialog = new ContactListDialogSettings(this, mSettings); + + mSettings + .registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener() { + @Override + public void onSharedPreferenceChanged( + SharedPreferences sharedPreferences, String key) { + /* + * TODO : A faire apres listener nikita + * + * mBeemApplication.stopBeemService(); + * mBeemApplication.startBeemService(); + * mBeemApplication.callWhenServiceConnected(mHandler, + * new Runnable() { + * + * @Override public void run() { + * callbackShowContactList(); } }); + */ + } + }); } @Override - public void onStart() { + protected void onStart() { super.onStart(); - mBeemApplication.startBeemService(); + Log.i(TAG, "onStart"); + } + + @Override + protected void onResume() { + super.onResume(); + /* + * @TODO: A ameliorer apres listener de nikita + */ + Log.i(TAG, "onResume"); + if (!mBeemApplication.isConnected()) + mBeemApplication.startBeemService(); + else { + callbackShowContactList(); + } mBeemApplication.callWhenServiceConnected(mHandler, new Runnable() { @Override public void run() { - mService = mBeemApplication.getXmppFacade(); - try { - showContactList(mService.getRoster().getContactList(), mService.getRoster().getContactList()); - } catch (RemoteException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - + callbackShowContactList(); } }); } - private void showContactList(List listGroup, List listContact) { + private void callbackShowContactList() { + /* + * @TODO: A ameliorer apres listener de nikita + */ + mService = mBeemApplication.getXmppFacade(); + if (mService != null) { + try { + IRoster r = mService.getRoster(); + if (r != null) + showContactList(r.getGroupsNames(), r.getContactList()); + } catch (RemoteException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + /** + * Callback for menu creation. + * + * @param menu + * the menu created + * @return true on success, false otherwise + */ + @Override + public final boolean onCreateOptionsMenu(Menu menu) { + super.onCreateOptionsMenu(menu); + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.contactlistmenu, menu); + return true; + } + + /** + * Callback for menu item selected. + * + * @param item + * the item selected + * @return true on success, false otherwise + */ + @Override + 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; + } + } + + private void showContactList(List listGroup, + List listContact) { ExpandableListAdapter Adapter; List> groupData = new ArrayList>(); - List>> childData = new ArrayList>>(); + List>> childData = new ArrayList>>(); if (listGroup.size() == 0) - listGroup.add(new Contact()); + listGroup.add("Default"); for (int i = 0; i < listGroup.size(); i++) { Map curGroupMap = new HashMap(); groupData.add(curGroupMap); - curGroupMap.put("NAME", "Default"); + curGroupMap.put("GROUP", listGroup.get(i)); - List> children = new ArrayList>(); + List> children = new ArrayList>(); for (int j = 0; j < listContact.size(); ++j) { - Map curChildMap = new HashMap(); + Map curChildMap = new HashMap(); children.add(curChildMap); - curChildMap.put("NAME_CHILD", listContact.get(j).getJID()); - curChildMap.put("MSG", "Taper votre message perso"); + Contact c = listContact.get(j); + Log.i(TAG, c.getID() + " " +c.getJID()); + curChildMap.put("CHILD", c); } childData.add(children); } - Adapter = new ContactExpandableListAdapter(this, groupData, R.layout.contactlistgroup, new String[] { "NAME" }, - new int[] { R.id.textgroup }, childData, R.layout.contactlistcontact, new String[] { "NAME_CHILD", "MSG" }, - new int[] { R.id.textchild1, R.id.textchild2, R.id.avatar }); + Adapter = new ContactExpandableListAdapter(this, groupData, + R.layout.contactlistgroup, new String[] { "GROUP" }, + new int[] { R.id.textgroup }, childData, + R.layout.contactlistcontact, new String[] { "CHILD" }, + new int[] { R.id.contactliststatus, R.id.contactlistpseudo, + R.id.contactlistmsgperso, R.id.contactlistavatar }); setListAdapter(Adapter); } /** - * A simple adapter which allows you to bind data to specific Views defined within the layout of an Expandable Lists - * children (Implement getGroupView() to define the layout of parents) + * A simple adapter which allows you to bind data to specific Views defined + * within the layout of an Expandable Lists children (Implement + * getGroupView() to define the layout of parents) */ - public class ContactExpandableListAdapter extends SimpleExpandableListAdapter { + private class ContactExpandableListAdapter extends + SimpleExpandableListAdapter { private List>> mChildData; private String[] mChildFrom; private int[] mChildTo; - public ContactExpandableListAdapter(Context context, List> groupData, int groupLayout, - String[] groupFrom, int[] groupTo, List>> childData, - int childLayout, String[] childFrom, int[] childTo) { - super(context, groupData, groupLayout, groupFrom, groupTo, childData, childLayout, childFrom, childTo); + public ContactExpandableListAdapter(Context context, + List> groupData, int groupLayout, + String[] groupFrom, int[] groupTo, + List>> childData, + int childLayout, String[] childFrom, int[] childTo) { + super(context, groupData, groupLayout, groupFrom, groupTo, + childData, childLayout, childFrom, childTo); mChildData = childData; mChildFrom = childFrom; @@ -116,8 +223,8 @@ } @Override - public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, - ViewGroup parent) { + public View getChildView(int groupPosition, int childPosition, + boolean isLastChild, View convertView, ViewGroup parent) { View v; if (convertView == null) { @@ -125,33 +232,67 @@ } else { v = convertView; } - bindView(v, mChildData.get(groupPosition).get(childPosition), mChildFrom, mChildTo, groupPosition, - childPosition); + bindView(v, mChildData.get(groupPosition).get(childPosition), + mChildFrom, mChildTo, groupPosition, childPosition); return v; } - // This method binds my data to the Views specified in the child - // xmllayout - private void bindView(View view, Map data, String[] from, int[] to, int groupPosition, - int childPosition) { - // Apply TextViews - TextView v1 = (TextView) view.findViewById(to[0]); - if (v1 != null) { - Log.i("CONTACT LIST 1", (String) data.get(from[0]) + " " + to[0]); - v1.setText((String) data.get(from[0])); - } - TextView v2 = (TextView) view.findViewById(to[1]); - if (v2 != null) { - Log.i("CONTACT LIST 2", (String) data.get(from[1]) + " " + to[1]); - v2.setText((String) data.get(from[1])); - } - // Apply ImageView - ImageView imgV = (ImageView) view.findViewById(to[2]); - if (imgV != null) { - Drawable avatar = (Drawable) getResources().getDrawable(R.drawable.avatar); - imgV.setImageDrawable(avatar); + private void bindView(View view, Map data, String[] from, + int[] to, int groupPosition, int childPosition) { + Contact c = (Contact) data.get(from[0]); + + if (c != null) { + + ImageView imgV = (ImageView) view.findViewById(to[0]); + Drawable imageDrawable = null; + switch (c.getStatus()) { + case Contact.CONTACT_STATUS_AVAILABLE: + imageDrawable = (Drawable) getResources().getDrawable( + R.drawable.avatar); + case Contact.CONTACT_STATUS_AVAILABLE_FOR_CHAT: + imageDrawable = (Drawable) getResources().getDrawable( + R.drawable.chat); + case Contact.CONTACT_STATUS_AWAY: + imageDrawable = (Drawable) getResources().getDrawable( + R.drawable.away); + case Contact.CONTACT_STATUS_BUSY: + imageDrawable = (Drawable) getResources().getDrawable( + R.drawable.dnd); + case Contact.CONTACT_STATUS_DISCONNECT: + imageDrawable = (Drawable) getResources().getDrawable( + R.drawable.offline); + case Contact.CONTACT_STATUS_UNAVAILABLE: + imageDrawable = (Drawable) getResources().getDrawable( + R.drawable.requested); + default: + imageDrawable = (Drawable) getResources().getDrawable( + R.drawable.error); + } + imgV.setImageDrawable(imageDrawable); + + TextView v = (TextView) view.findViewById(to[1]); + if (v != null) { + v.setText(c.getJID()); + } + /* + * @TODO: Rajouter le message perso du contact v = (TextView) + */ + v = (TextView) view.findViewById(to[2]); + if (v != null) { + v.setText(c.getMMsgState()); + } + + /* + * @TODO: Rajouter l'avatar du contact getAvatar() dans la + * classe + */ + imgV = (ImageView) view.findViewById(to[3]); + if (imgV != null) { + imageDrawable = (Drawable) getResources().getDrawable( + R.drawable.avatar); + imgV.setImageDrawable(imageDrawable); + } } } } - -} +} \ No newline at end of file diff -r 31b436663df5 -r fb3e3ed4bafc src/com/beem/project/beem/ui/ContactListDialogSettings.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/ui/ContactListDialogSettings.java Tue Apr 07 15:20:28 2009 +0200 @@ -0,0 +1,81 @@ +package com.beem.project.beem.ui; + +import android.app.Dialog; +import android.content.Context; +import android.content.SharedPreferences; +import android.os.RemoteException; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; + +import com.beem.project.beem.BeemApplication; +import com.beem.project.beem.R; + +/** + * + */ +public class ContactListDialogSettings extends Dialog implements + android.view.View.OnClickListener { + + private SharedPreferences mSettings; + private ContactList mContactList; + + public ContactListDialogSettings(ContactList contactList, + SharedPreferences settings) { + super(contactList); + this.mContactList = contactList; + this.mSettings = settings; + } + + @Override + protected void onStart() { + super.onStart(); + setContentView(R.layout.contactlistdialogsettings); + getWindow().setFlags(4, 4); + setTitle("Jabber Account Settings"); + showSettings(); + Button ok = (Button) findViewById(R.id.ok); + ok.setOnClickListener(this); + } + + @Override + public void onClick(View v) { + SharedPreferences.Editor editor = mSettings.edit(); + Context ctx = getContext(); + editor.putString(ctx.getString(R.string.PreferenceHostKey), + getWidgetText(R.id.host)); + editor.putString(ctx.getString(R.string.PreferencePortKey), + getWidgetText(R.id.port)); + editor.putString(ctx.getString(R.string.PreferenceLoginKey), + getWidgetText(R.id.userid)); + editor.putString(ctx.getString(R.string.PreferencePasswordKey), + getWidgetText(R.id.password)); + String JID = ctx.getString(R.string.PreferenceLoginKey) + "@" + + ctx.getString(R.string.PreferenceHostKey); + editor.putString(ctx.getString(R.string.PreferenceJID), JID); + editor.commit(); + dismiss(); + } + + private void showSettings() { + Context ctx = getContext(); + EditText e = (EditText) findViewById(R.id.host); + e.setText(mSettings.getString( + ctx.getString(R.string.PreferenceHostKey), "")); + e = (EditText) findViewById(R.id.port); + e.setText(mSettings.getString( + ctx.getString(R.string.PreferencePortKey), "")); + e = (EditText) findViewById(R.id.userid); + e.setText(mSettings.getString(ctx + .getString(R.string.PreferenceLoginKey), "")); + e = (EditText) findViewById(R.id.password); + e.setText(mSettings.getString(ctx + .getString(R.string.PreferencePasswordKey), "")); + } + + private String getWidgetText(int id) { + EditText widget = (EditText) this.findViewById(id); + return widget.getText().toString(); + } +} diff -r 31b436663df5 -r fb3e3ed4bafc src/com/beem/project/beem/ui/SendIM.java --- a/src/com/beem/project/beem/ui/SendIM.java Sun Apr 05 23:43:55 2009 +0200 +++ b/src/com/beem/project/beem/ui/SendIM.java Tue Apr 07 15:20:28 2009 +0200 @@ -5,6 +5,7 @@ import android.app.ListActivity; import android.content.SharedPreferences; import android.os.Bundle; +import android.util.Log; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuInflater; @@ -16,19 +17,21 @@ import android.widget.EditText; import com.beem.project.beem.R; +import com.beem.project.beem.service.Contact; /** - * @author barbu - * This activity class provide the view for instant messaging - * after selecting a correspondant. + * @author barbu This activity class provide the view for instant messaging + * after selecting a correspondant. */ -public class SendIM extends ListActivity implements OnClickListener, OnKeyListener { - private EditText mToSend; - private ArrayList mMessages = new ArrayList(); - private ArrayAdapter mAdapter; - private SendIMDialogSmiley mSmyDialog; +public class SendIM extends ListActivity implements OnClickListener, + OnKeyListener { + private EditText mToSend; + private ArrayList mMessages = new ArrayList(); + private ArrayAdapter mAdapter; + private SendIMDialogSmiley mSmyDialog; private SharedPreferences mSet; + private Contact mContact; /** * Constructor. @@ -43,16 +46,26 @@ @Override public void onCreate(Bundle saveBundle) { super.onCreate(saveBundle); + setContentView(R.layout.sendim); mToSend = (EditText) findViewById(R.id.userText); mSet = getSharedPreferences("lol", MODE_PRIVATE); mSmyDialog = new SendIMDialogSmiley(this, mSet); - mAdapter = new ArrayAdapter(this, R.layout.messagelist, mMessages); + mAdapter = new ArrayAdapter(this, R.layout.messagelist, + mMessages); setListAdapter(mAdapter); mToSend.setOnClickListener(this); mToSend.setOnKeyListener(this); + + mContact = getIntent().getParcelableExtra("contact"); + } + + @Override + public void onStart() { + super.onStart(); + } /** @@ -63,19 +76,25 @@ } /** - * This method send a message to the server over the XMPP - * connection and display it on activity view - * TODO : Exception si la connexion se coupe pendant la conversation + * This method send a message to the server over the XMPP connection and + * display it on activity view TODO : Exception si la connexion se coupe + * pendant la conversation */ private void sendText() { String text = mToSend.getText().toString(); if (!text.equals("")) { /* - * Prepare the message to be send - * */ - /*Message msg = new Message("barbu", Message.Type.chat);*/ - /*msg.setBody(text);*/ - mAdapter.add("Barbu " + getString(R.string.SendIMSays) + text); + * Prepare the message to be send + */ + /* Message msg = new Message("barbu", Message.Type.chat); */ + /* msg.setBody(text); */ + /* + * Rien a voir il faut changer le mContact.getJID() et remplacer + * avec son pseudo cetait juste un test pour savoir qu'on recupere + * bien le contact a qui envoyer les infos + */ + mAdapter.add(mContact.getJID() + " " + + getString(R.string.SendIMSays) + text); mToSend.setText(null); } } @@ -94,9 +113,10 @@ } return false; } - + /** * Callback for menu creation. + * * @param menu * the menu created * @return true on success, false otherwise @@ -108,7 +128,7 @@ inflater.inflate(R.menu.sendimmenu, menu); return true; } - + @Override public final boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) {