Merge avec bart.
--- a/.hgignore Fri Apr 03 00:49:23 2009 +0200
+++ b/.hgignore Fri Apr 03 01:26:42 2009 +0200
@@ -1,2 +1,5 @@
+syntax: glob
bin/*
R.java
+doc/javadoc
+src/com/beem/project/beem/service/aidl/*.java
--- a/Beem-ecipse-formatter.xml Fri Apr 03 00:49:23 2009 +0200
+++ b/Beem-ecipse-formatter.xml Fri Apr 03 01:26:42 2009 +0200
@@ -19,7 +19,7 @@
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_ellipsis" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation" value="do not insert"/>
@@ -37,7 +37,7 @@
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_package" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.continuation_indentation" value="2"/>
+<setting id="org.eclipse.jdt.core.formatter.continuation_indentation" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments" value="do not insert"/>
@@ -69,8 +69,8 @@
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment" value="false"/>
-<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="80"/>
+<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="120"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression" value="do not insert"/>
@@ -139,7 +139,7 @@
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment" value="false"/>
+<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator" value="insert"/>
@@ -157,7 +157,7 @@
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression" value="16"/>
<setting id="org.eclipse.jdt.core.compiler.compliance" value="1.5"/>
-<setting id="org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer" value="2"/>
+<setting id="org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression" value="16"/>
@@ -186,7 +186,7 @@
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_javadoc_comments" value="true"/>
-<setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="80"/>
+<setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="120"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_import_groups" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon" value="do not insert"/>
@@ -230,7 +230,7 @@
<setting id="org.eclipse.jdt.core.compiler.codegen.targetPlatform" value="1.5"/>
<setting id="org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.comment.format_header" value="false"/>
+<setting id="org.eclipse.jdt.core.formatter.comment.format_header" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_block_comments" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_enum_constants" value="0"/>
--- a/build.xml Fri Apr 03 00:49:23 2009 +0200
+++ b/build.xml Fri Apr 03 01:26:42 2009 +0200
@@ -114,6 +114,8 @@
<property name="android-jar" value="${sdk-folder}/android.jar" />
+ <property name="javadoc-output" value="doc/javadoc" />
+
<!-- Rules -->
<!-- Create the output directories if they don't exist yet. -->
@@ -121,6 +123,7 @@
<echo>Creating output directories if needed...</echo>
<mkdir dir="${outdir}" />
<mkdir dir="${outdir-classes}" />
+ <mkdir dir="${javadoc-output}" />
</target>
<!-- Generate the R.java file for this project's resources. -->
@@ -145,11 +148,13 @@
<echo>Compiling aidl files into Java classes...</echo>
<apply executable="${aidl}" failonerror="true">
<arg value="-p${android-framework}" />
+ <arg value="-p${basedir}/project.aidl"/>
<arg value="-I${srcdir}" />
<fileset dir="${srcdir}">
<include name="**/*.aidl"/>
</fileset>
</apply>
+
</target>
<!-- Compile this project's .java files into .class files. -->
@@ -244,7 +249,9 @@
<!-- Package the application without signing it.
This allows for the application to be signed later with an official publishing key. -->
- <target name="release" depends="dex, package-res">
+ <target name="release" depends="dex, package-res"
+ description="Package the application without signing it.
+ This allows for the application to be signed later with an official publishing key.">
<echo>Packaging ${out-unsigned-package} for release...</echo>
<exec executable="${apk-builder}" failonerror="true">
<arg value="${out-unsigned-package-ospath}" />
@@ -264,7 +271,8 @@
</target>
<!-- Install the package on the default emulator -->
- <target name="install" depends="debug">
+ <target name="install" depends="debug"
+ description="Install the package on the default emulator">
<echo>Installing ${out-debug-package} onto default emulator...</echo>
<exec executable="${adb}" failonerror="true">
<arg value="install" />
@@ -281,8 +289,9 @@
</exec>
</target>
- <!-- Uinstall the package from the default emulator -->
- <target name="uninstall">
+ <!-- Uninstall the package from the default emulator -->
+ <target name="uninstall"
+ description="Uninstall the package from the default emulator">
<echo>Uninstalling ${application-package} from the default emulator...</echo>
<exec executable="${adb}" failonerror="true">
<arg value="uninstall" />
@@ -295,6 +304,13 @@
<delete verbose="false" dir="${outdir}"/>
</target>
-
+ <target name="javadoc" depends="aidl"
+ description="Build the javadoc">
+ <javadoc sourcepath="${srcdir}" destdir="${javadoc-output}">
+ <classpath>
+ <fileset dir="${external-libs}" includes="*.jar" />
+ </classpath>
+ </javadoc>
+ </target>
</project>
--- a/project.aidl Fri Apr 03 00:49:23 2009 +0200
+++ b/project.aidl Fri Apr 03 01:26:42 2009 +0200
@@ -4,3 +4,4 @@
parcelable com.beem.project.beem.BeemException
parcelable com.beem.project.beem.service.Contact
+parcelable com.beem.project.beem.service.Message
--- a/src/com/beem/project/beem/BeemApplication.java Fri Apr 03 00:49:23 2009 +0200
+++ b/src/com/beem/project/beem/BeemApplication.java Fri Apr 03 01:26:42 2009 +0200
@@ -21,64 +21,21 @@
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 static BeemApplication mBeemApp;
private IXMPPFacade mFacade;
private Context mApplicationContext;
private Resources mPrivateResources;
- private static BeemApplication mBeemApp;
private List<Message> mQueue = new LinkedList<Message>();
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();
- 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() {
@@ -101,6 +58,82 @@
}
};
+ /**
+ * 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();
+ }
+
+ /**
+ * {@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();
@@ -112,10 +145,20 @@
}
}
+ /**
+ * 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) {
--- a/src/com/beem/project/beem/BeemService.java Fri Apr 03 00:49:23 2009 +0200
+++ b/src/com/beem/project/beem/BeemService.java Fri Apr 03 01:26:42 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.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;
- /*
- * (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();
- }
- }
}
--- a/src/com/beem/project/beem/jingle/Caller.java Fri Apr 03 00:49:23 2009 +0200
+++ b/src/com/beem/project/beem/jingle/Caller.java Fri Apr 03 01:26:42 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;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/jingle/RTPMediaManager.java Fri Apr 03 01:26:42 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<PayloadType> 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<PayloadType> getPayloads() {
+ // TODO Auto-generated method stub
+ return payloads;
+ }
+
+ private void setupPayloads() {
+ payloads = new ArrayList<PayloadType>();
+ 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;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/jingle/RTPMediaSession.java Fri Apr 03 01:26:42 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();
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/jingle/RTPReceiver.java Fri Apr 03 01:26:42 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;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/jingle/RTPTransmitter.java Fri Apr 03 01:26:42 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;
+ }
+
+}
--- a/src/com/beem/project/beem/jingle/Receiver.java Fri Apr 03 00:49:23 2009 +0200
+++ b/src/com/beem/project/beem/jingle/Receiver.java Fri Apr 03 01:26:42 2009 +0200
@@ -5,10 +5,12 @@
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
+import java.util.Iterator;
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 +20,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 +35,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 +62,12 @@
}
}
- private void initialize()
- {
+ private void initialize() {
+ BasicTransportManager bt = new BasicTransportManager();
mediaManagers = new ArrayList<JingleMediaManager>();
- 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() {
--- a/src/com/beem/project/beem/jingle/SenderMediaManager.java Fri Apr 03 00:49:23 2009 +0200
+++ b/src/com/beem/project/beem/jingle/SenderMediaManager.java Fri Apr 03 01:26:42 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<PayloadType> payloads;
+ private List<PayloadType> 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<PayloadType> getPayloads() {
- return payloads;
- }
+ @Override
+ public List<PayloadType> getPayloads() {
+ return payloads;
+ }
- private void setupPayloads() {
- payloads = new ArrayList<PayloadType>();
- payloads.add(new PayloadType.Audio(42, "Test"));
- }
+ private void setupPayloads() {
+ payloads = new ArrayList<PayloadType>();
+ 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;
+ }
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/service/BeemChatManager.java Fri Apr 03 01:26:42 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<String, Chat> mChats = new HashMap<String, Chat>();
+ private ChatListener mChatListener = new ChatListener();
+ private RemoteCallbackList<IChatManagerListener> mRemoteChatCreationListeners =
+ new RemoteCallbackList<IChatManagerListener>();
+
+ /**
+ * 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();
+ }
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/service/ChatAdapter.java Fri Apr 03 01:26:42 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();
+ }
+ }
+
+}
--- a/src/com/beem/project/beem/service/Contact.java Fri Apr 03 00:49:23 2009 +0200
+++ b/src/com/beem/project/beem/service/Contact.java Fri Apr 03 01:26:42 2009 +0200
@@ -12,6 +12,14 @@
*/
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;
+
+
/**
* Parcelable.Creator needs by Android.
*/
@@ -31,6 +39,49 @@
private String mJID;
private int mID;
private int mStatus;
+
+ /**
+ * @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;
+ }
+
+ /**
+ * @return the mMsgState
+ */
+ public String getMMsgState() {
+ return mMsgState;
+ }
+
+ /**
+ * @param msgState the mMsgState to set
+ */
+ public void setMMsgState(String msgState) {
+ mMsgState = msgState;
+ }
+
private String mMsgState;
/**
@@ -71,7 +122,6 @@
dest.writeString(mMsgState);
}
-
/**
* Get the Jabber ID of the contact.
* @return the Jabber ID
--- a/src/com/beem/project/beem/service/Message.java Fri Apr 03 00:49:23 2009 +0200
+++ b/src/com/beem/project/beem/service/Message.java Fri Apr 03 01:26:42 2009 +0200
@@ -7,15 +7,27 @@
import android.os.Parcelable;
/**
+ * This class represents a instant message.
* @author darisk
- *
*/
public class Message implements Parcelable {
-
- public final static int MSG_TYPE_NORMAL = 100;
- public final static int MSG_TYPE_CHAT = 200;
- public final static int MSG_TYPE_GROUP_CHAT = 300;
-
+
+ /**
+ * 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;
@@ -37,19 +49,28 @@
return new Message[size];
}
};
-
- public Message(String to, int type) {
+
+ /**
+ * 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 = "";
}
-
- public Message(String to) {
+
+ /**
+ * 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
@@ -61,7 +82,10 @@
mSubject = in.readString();
mThread = in.readString();
}
-
+
+ /**
+ * {@inheritDoc}
+ */
@Override
public void writeToParcel(Parcel dest, int flags) {
// TODO Auto-generated method stub
@@ -71,16 +95,18 @@
dest.writeString(mSubject);
dest.writeString(mThread);
}
-
+
/**
- * @return the Type
+ * Get the type of the message.
+ * @return the type of the message.
*/
public int getType() {
return mType;
}
/**
- * @param type the Type to set
+ * Set the type of the message.
+ * @param type the type to set
*/
public void setType(int type) {
mType = type;
@@ -88,7 +114,8 @@
/**
- * @return the mBody
+ * Get the body of the message.
+ * @return the Body of the message
*/
public String getBody() {
return mBody;
@@ -96,7 +123,8 @@
/**
- * @param body the mBody to set
+ * Set the body of the message.
+ * @param body the body to set
*/
public void setBody(String body) {
mBody = body;
@@ -104,7 +132,8 @@
/**
- * @return the mSubject
+ * Get the subject of the message.
+ * @return the subject
*/
public String getSubject() {
return mSubject;
@@ -112,7 +141,8 @@
/**
- * @param subject the mSubject to set
+ * Set the subject of the message.
+ * @param subject the subject to set
*/
public void setSubject(String subject) {
mSubject = subject;
@@ -120,7 +150,8 @@
/**
- * @return the mTo
+ * Get the destinataire of the message.
+ * @return the destinataire of the message
*/
public String getTo() {
return mTo;
@@ -128,7 +159,8 @@
/**
- * @param to the mTo to set
+ * Set the destinataire of the message.
+ * @param to the destinataire to set
*/
public void setTo(String to) {
mTo = to;
@@ -136,7 +168,8 @@
/**
- * @return the mThread
+ * Get the thread of the message.
+ * @return the thread
*/
public String getThread() {
return mThread;
@@ -144,22 +177,20 @@
/**
- * @param thread the mThread to set
+ * 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;
}
-
-
-
-
-
}
--- a/src/com/beem/project/beem/service/RosterAdapter.java Fri Apr 03 00:49:23 2009 +0200
+++ b/src/com/beem/project/beem/service/RosterAdapter.java Fri Apr 03 01:26:42 2009 +0200
@@ -1,11 +1,10 @@
/**
- *
+ *
*/
package com.beem.project.beem.service;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -13,9 +12,12 @@
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 android.os.RemoteException;
+import android.util.Log;
/**
* This class implement a Roster adapter for BEEM.
@@ -25,6 +27,64 @@
private Roster mAdaptee;
private Map<String, Contact> mContacts = new HashMap<String, Contact>();
+ private RosterListener mRosterListener = new RosterListener() {
+
+ @Override
+ public void presenceChanged(Presence presence) {
+ String user = presence.getFrom();
+ Presence bestPresence = mAdaptee.getPresence(user);
+ Contact c = mContacts.get(user);
+ if (c == null) {
+ c = new Contact(user);
+ mContacts.put(user, c);
+ }
+ int status;
+ if (bestPresence.getType().equals(Presence.Type.unavailable))
+ status = Contact.CONTACT_STATUS_DISCONNECT;
+ else {
+ switch (bestPresence.getMode()) {
+ case available:
+ status = Contact.CONTACT_STATUS_AVAILABLE;
+ break;
+ case away:
+ status = Contact.CONTACT_STATUS_AWAY;
+ break;
+ case chat:
+ status = Contact.CONTACT_STATUS_AVAILABLE_FOR_CHAT;
+ break;
+ case dnd:
+ status = Contact.CONTACT_STATUS_BUSY;
+ break;
+ case xa:
+ status = Contact.CONTACT_STATUS_UNAVAILABLE;
+ break;
+ default:
+ Log.e("RosterAdapter", "Status mode non gere");
+ status = Contact.CONTACT_STATUS_DISCONNECT;
+ break;
+ }
+ }
+ c.setStatus(status);
+ }
+
+ @Override
+ public void entriesUpdated(Collection<String> arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void entriesDeleted(Collection<String> arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void entriesAdded(Collection<String> arg0) {
+ // TODO Auto-generated method stub
+
+ }
+ };
/**
* Constructor.
@@ -32,9 +92,11 @@
*/
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));
+ if ( !mContacts.containsKey(user))
+ mContacts.put(user, new Contact(user));
}
}
@@ -89,6 +151,9 @@
return res;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public List<String> getGroupsNames() throws RemoteException {
Collection<RosterGroup> groups = mAdaptee.getGroups();
--- a/src/com/beem/project/beem/service/XMPPConnectionAdapter.java Fri Apr 03 00:49:23 2009 +0200
+++ b/src/com/beem/project/beem/service/XMPPConnectionAdapter.java Fri Apr 03 01:26:42 2009 +0200
@@ -10,24 +10,24 @@
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;
+import com.beem.project.beem.service.aidl.IXmppConnection;
/**
* This class implements an adapter for XMPPConnection.
* @author darisk
*/
-public class XMPPConnectionAdapter extends IXMPPConnection.Stub {
+public class XMPPConnectionAdapter extends IXmppConnection.Stub {
private static final String TAG = "XMPPConnectionAdapter";
private XMPPConnection mAdaptee;
+ private IChatManager mChatManager;
private BeemException mLastException;
private String mLogin;
private String mPassword;
@@ -78,6 +78,7 @@
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;
@@ -149,6 +150,14 @@
if (listen != null)
mRemoteConnListeners.unregister(listen);
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public IChatManager getChatManager() throws RemoteException {
+ return mChatManager;
+ }
/**
* Trigger Connection event.
--- a/src/com/beem/project/beem/service/XMPPFacade.java Fri Apr 03 00:49:23 2009 +0200
+++ b/src/com/beem/project/beem/service/XMPPFacade.java Fri Apr 03 01:26:42 2009 +0200
@@ -1,15 +1,14 @@
-/**
- *
- */
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.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 {
@@ -19,36 +18,56 @@
* Constructor for XMPPFacade.
* @param connection the connection use by the facade
*/
- public XMPPFacade(XMPPConnectionAdapter connection) {
+ public XMPPFacade(final XMPPConnectionAdapter connection) {
this.mConnexion = connection;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void connectAsync() throws RemoteException {
- // TODO Auto-generated method stub
mConnexion.connectAsync();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void connectSync() throws RemoteException {
- // TODO Auto-generated method stub
mConnexion.connectSync();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
- public IXMPPConnection createConnection() throws RemoteException {
+ public IXmppConnection createConnection() throws RemoteException {
return mConnexion;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void disconnect() throws RemoteException {
- // TODO Auto-generated method stub
mConnexion.disconnect();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public IRoster getRoster() throws RemoteException {
return mConnexion.getRoster();
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public IChatManager getChatManager() throws RemoteException {
+ return mConnexion.getChatManager();
+ }
+
}
--- a/src/com/beem/project/beem/service/aidl/IBeemConnectionListener.aidl Fri Apr 03 00:49:23 2009 +0200
+++ b/src/com/beem/project/beem/service/aidl/IBeemConnectionListener.aidl Fri Apr 03 01:26:42 2009 +0200
@@ -1,17 +1,39 @@
package com.beem.project.beem.service.aidl;
+/**
+ * Interface to listen for connection events
+ * @author Da Risk <barthe_f@epitech.eu>
+ */
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();
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/service/aidl/IChat.aidl Fri Apr 03 01:26:42 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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/service/aidl/IChatManager.aidl Fri Apr 03 01:26:42 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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/service/aidl/IChatManagerListener.aidl Fri Apr 03 01:26:42 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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/service/aidl/IMessageListener.aidl Fri Apr 03 01:26:42 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);
+}
--- a/src/com/beem/project/beem/service/aidl/IXMPPConnection.aidl Fri Apr 03 00:49:23 2009 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +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);
-
- boolean isAuthentificated();
-}
\ No newline at end of file
--- a/src/com/beem/project/beem/service/aidl/IXMPPFacade.aidl Fri Apr 03 00:49:23 2009 +0200
+++ b/src/com/beem/project/beem/service/aidl/IXMPPFacade.aidl Fri Apr 03 01:26:42 2009 +0200
@@ -1,11 +1,12 @@
package com.beem.project.beem.service.aidl;
-import com.beem.project.beem.service.aidl.IXMPPConnection;
+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();
+ IXmppConnection createConnection();
IRoster getRoster();
@@ -15,4 +16,6 @@
void disconnect();
+ IChatManager getChatManager();
+
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/service/aidl/IXmppConnection.aidl Fri Apr 03 01:26:42 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
--- a/src/com/beem/project/beem/ui/ContactList.java Fri Apr 03 00:49:23 2009 +0200
+++ b/src/com/beem/project/beem/ui/ContactList.java Fri Apr 03 01:26:42 2009 +0200
@@ -5,7 +5,6 @@
import java.util.List;
import java.util.Map;
-import com.beem.project.beem.R;
import android.app.ExpandableListActivity;
import android.content.Context;
import android.content.Intent;
@@ -26,6 +25,7 @@
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.IRoster;
import com.beem.project.beem.service.aidl.IXMPPFacade;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/ui/ContactListDialogSettings.java Fri Apr 03 01:26:42 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();
+ }
+}