--- 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
--- 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 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.beem.project.beem" android:versionCode="1"
android:versionName="1.0">
- <!-- <application android:label="@string/app_name" android:name="BeemApplication" -->
- <application android:theme="@style/customtheme">
- <activity android:name=".ui.Beem" android:label="@string/app_name">
+ <application android:label="@string/app_name" android:name="BeemApplication" android:theme="@style/customtheme">
+ <activity android:name=".ui.ContactList" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
- <activity android:name=".ui.ContactList" android:label="@string/app_name" />
<activity android:name=".ui.SendIM" android:label="@string/app_name" />
<service android:name="BeemService" android:enabled="true"
android:label="Beem Service" android:permission="com.beem.project.beem.BEEM_SERVICE">
@@ -25,5 +23,5 @@
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.VIBRATE"></uses-permission>
<uses-permission android:name="com.beem.project.beem.BEEM_SERVICE"></uses-permission>
-<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"></uses-permission>
+ <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"></uses-permission>
</manifest>
--- 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 @@
<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 Sun Apr 05 23:43:55 2009 +0200
+++ b/build.xml Tue Apr 07 15:20:28 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 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
Binary file res/drawable/away.png has changed
Binary file res/drawable/chat.png has changed
Binary file res/drawable/closed.png has changed
Binary file res/drawable/connecting.png has changed
Binary file res/drawable/dnd.png has changed
Binary file res/drawable/error.png has changed
Binary file res/drawable/invisible.png has changed
Binary file res/drawable/message.png has changed
Binary file res/drawable/not_in_the_roster.png has changed
Binary file res/drawable/offline.png has changed
Binary file res/drawable/online.png has changed
Binary file res/drawable/requested.png has changed
--- 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 @@
-<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
-
- <!-- <ImageView android:id="@+id/logo"
- android:src="@drawable/logo"
- android:adjustViewBounds="true"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"/>
- -->
-
- <TextView android:text="@string/BeemJabberID"
- android:textSize="25sp"
- android:paddingLeft="100sp"
- android:paddingTop="150sp"
- android:paddingBottom="15sp"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content" />
-
- <ImageView android:id="@+id/avatar"
- android:src="@drawable/bart"
- android:paddingTop="30sp"
- android:paddingBottom="30sp"
- android:adjustViewBounds="true"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"/>
-
- <Button android:id="@+id/connection"
- android:textSize="20sp"
- android:singleLine="true"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- />
-</LinearLayout>
--- a/res/layout/beemdialogsettings.xml Sun Apr 05 23:43:55 2009 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,89 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- >
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Host/Port:"
- android:minWidth="70dp"
- />
-
- <EditText android:id="@+id/host"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:singleLine="true"
- android:textSize="16sp"
- android:autoText="false"
- android:capitalize="none"
- android:minWidth="150dp"
- android:scrollHorizontally="true"/>
- <EditText android:id="@+id/port"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:singleLine="true"
- android:textSize="16sp"
- android:autoText="false"
- android:minWidth="80dp"
- android:capitalize="none"
- android:scrollHorizontally="true"/>
- </LinearLayout>
-
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- >
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Userid:"
- android:minWidth="70dp"
- />
- <EditText android:id="@+id/userid"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:singleLine="true"
- android:textSize="16sp"
- android:autoText="false"
- android:minWidth="250dp"
- android:capitalize="none"
- android:scrollHorizontally="true"/>
- </LinearLayout>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- >
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Password:"
- android:minWidth="70dp"
- />
- <EditText android:id="@+id/password"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:singleLine="true"
- android:password="true"
- android:textSize="16sp"
- android:autoText="false"
- android:minWidth="250dp"
- android:capitalize="none"
- android:scrollHorizontally="true"/>
- </LinearLayout>
-
- <Button android:id="@+id/ok"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:text="OK">
- <requestFocus/>
- </Button>
-</LinearLayout>
\ No newline at end of file
--- 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 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
- android:layout_height="50sp"
+ android:layout_height="wrap_content"
android:gravity="center_vertical" >
- <ImageView android:id="@+id/avatar"
- android:layout_width="70px"
- android:layout_height="40sp" />
+ <ImageView android:id="@+id/contactliststatus"
+ android:layout_weight="5"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:gravity="center_vertical" />
+
<LinearLayout
android:orientation="vertical"
+ android:layout_weight="1"
android:layout_width="fill_parent"
- android:layout_height="40sp">
-
- <TextView android:id="@+id/textchild1"
+ android:layout_height="wrap_content" >
+ <TextView android:id="@+id/contactlistpseudo"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:paddingLeft="20sp" />
+ <TextView android:id="@+id/contactlistmsgperso"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="20sp" />
-
- <TextView android:id="@+id/textchild2"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content" />
</LinearLayout>
+ <ImageView android:id="@+id/contactlistavatar"
+ android:layout_weight="5"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:gravity="center_vertical" />
+
</LinearLayout>
\ No newline at end of file
--- /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 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ >
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ >
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Host/Port:"
+ android:minWidth="70dp"
+ />
+
+ <EditText android:id="@+id/host"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:singleLine="true"
+ android:textSize="16sp"
+ android:autoText="false"
+ android:capitalize="none"
+ android:minWidth="150dp"
+ android:scrollHorizontally="true"/>
+ <EditText android:id="@+id/port"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:singleLine="true"
+ android:textSize="16sp"
+ android:autoText="false"
+ android:minWidth="80dp"
+ android:capitalize="none"
+ android:scrollHorizontally="true"/>
+ </LinearLayout>
+
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ >
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Userid:"
+ android:minWidth="70dp"
+ />
+ <EditText android:id="@+id/userid"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:singleLine="true"
+ android:textSize="16sp"
+ android:autoText="false"
+ android:minWidth="250dp"
+ android:capitalize="none"
+ android:scrollHorizontally="true"/>
+ </LinearLayout>
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ >
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Password:"
+ android:minWidth="70dp"
+ />
+ <EditText android:id="@+id/password"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:singleLine="true"
+ android:password="true"
+ android:textSize="16sp"
+ android:autoText="false"
+ android:minWidth="250dp"
+ android:capitalize="none"
+ android:scrollHorizontally="true"/>
+ </LinearLayout>
+
+ <Button android:id="@+id/ok"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:text="OK">
+ <requestFocus/>
+ </Button>
+</LinearLayout>
\ No newline at end of file
--- 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 @@
-<menu xmlns:android="http://schemas.android.com/apk/res/android">
- <item android:title="Creer ou Editer un compte" android:id="@+id/account_edit" android:icon="@drawable/xmpp"/>
- <item android:title="L'equipe Beem" android:id="@+id/account_about"/>
-</menu>
--- /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 @@
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:title="Creer ou Editer un compte" android:id="@+id/account_edit"/>
+ <item android:title="L'equipe Beem" android:id="@+id/account_about"/>
+</menu>
--- 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 @@
<string name="app_name">Beem</string>
<!-- Beem class -->
- <string name="BeemCreateAccount">Creer un compte</string>
+
<string name="BeemJabberID">Jabber ID</string>
<!-- BeemService class -->
@@ -13,9 +13,9 @@
<!-- Preferences informations -->
<string name="PreferenceFileName">Beem</string>
- <string name="PreferenceLoginKey">login</string>
+
<string name="PreferenceHostKey">host</string>
- <string name="PreferencePasswordKey">password</string>
+ <string name="PreferenceJID">Jabber ID</string><string name="PreferenceLoginKey">login</string><string name="PreferencePasswordKey">password</string>
<string name="PreferencePortKey">port</string>
<!-- SendIM class -->
@@ -24,4 +24,5 @@
<string name="SendIMState">Is : </string>
<string name="SendIMFrom">and is speaking from : </string>
<string name="SendIMSmiley">Insert a smiley</string>
+
</resources>
--- 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<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(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;
+ }
+
}
--- 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();
- }
- }
}
--- 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;
--- /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<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 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();
+ }
+ }
+}
--- /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;
+ }
+}
--- /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;
+ }
+
+}
--- 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<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() {
@@ -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");
--- 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<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;
+ }
}
--- 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) {
--- 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;
--- /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<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 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();
+ }
+ }
+
+}
--- 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<String> 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<String>();
+ 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<String>();
+ 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<String> mRes) {
+ this.mRes = mRes;
}
-
+ /**
+ * @return the mRes
+ */
+ public List<String> getMRes() {
+ return mRes;
+ }
}
--- /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<Message> CREATOR = new Parcelable.Creator<Message>() {
+
+ @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;
+ }
+
+}
--- /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<PresenceAdapter> CREATOR = new Parcelable.Creator<PresenceAdapter>() {
+
+ @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;
+ }
+}
--- 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<IBeemRosterListener> mRemoteRosListeners =
+ new RemoteCallbackList<IBeemRosterListener>();
private Map<String, Contact> mContacts = new HashMap<String, Contact>();
+ 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<String> addresses) {
+ Log.i(TAG, "Ajout de l'entry");
+ final int n = mRemoteRosListeners.beginBroadcast();
+
+ List<String> tab = new ArrayList<String>();
+ 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<String> addresses) {
+ Log.i(TAG, "Suppression de l'entry");
+ final int n = mRemoteRosListeners.beginBroadcast();
+
+ List<String> tab = new ArrayList<String>();
+ 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<String> addresses) {
+ Log.i(TAG, "Update de l'entry");
+ final int n = mRemoteRosListeners.beginBroadcast();
+
+ List<String> tab = new ArrayList<String>();
+ 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<String> getGroupsNames() throws RemoteException {
+ Collection<RosterGroup> groups = mAdaptee.getGroups();
+ ArrayList<String> result = new ArrayList<String>(groups.size());
+ for (RosterGroup rosterGroup : groups) {
+ result.add(rosterGroup.getName());
+ }
+ return result;
+ }
+
}
--- 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<IBeemConnectionListener> mRemoteConnListeners =
- new RemoteCallbackList<IBeemConnectionListener>();
- 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");
-
- }
-
-}
--- 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();
- }
-
-}
--- /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<IBeemConnectionListener> mRemoteConnListeners = new RemoteCallbackList<IBeemConnectionListener>();
+ 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();
+ }
+
+}
--- /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();
+ }
+
+}
--- 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 <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/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<String> addresses);
+ void onEntriesUpdated(in List<String> addresses);
+ void onEntriesDeleted(in List<String> addresses);
+ void onPresenceChanged(in PresenceAdapter presence);
+}
\ No newline at end of file
--- /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
--- /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
--- /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
--- /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
--- /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);
+}
--- 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<Contact> getContactList();
+ List<Contact> getContactList();
+
+ List<String> getGroupsNames();
+
+ void addConnectionListener(in IBeemRosterListener listen);
+ void removeConnectionListener(in IBeemRosterListener listen);
}
\ No newline at end of file
--- 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
--- 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();
-
-}
--- /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
--- /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();
+
+}
--- 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);
- }
-
-}
--- 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();
- }
-}
--- 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<String, Contact> child = (HashMap<String, Contact>) 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<Contact> listGroup, List<Contact> 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<String> listGroup,
+ List<Contact> listContact) {
ExpandableListAdapter Adapter;
List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
- List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();
+ List<List<Map<String, Contact>>> childData = new ArrayList<List<Map<String, Contact>>>();
if (listGroup.size() == 0)
- listGroup.add(new Contact());
+ listGroup.add("Default");
for (int i = 0; i < listGroup.size(); i++) {
Map<String, String> curGroupMap = new HashMap<String, String>();
groupData.add(curGroupMap);
- curGroupMap.put("NAME", "Default");
+ curGroupMap.put("GROUP", listGroup.get(i));
- List<Map<String, String>> children = new ArrayList<Map<String, String>>();
+ List<Map<String, Contact>> children = new ArrayList<Map<String, Contact>>();
for (int j = 0; j < listContact.size(); ++j) {
- Map<String, String> curChildMap = new HashMap<String, String>();
+ Map<String, Contact> curChildMap = new HashMap<String, Contact>();
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<? extends List<? extends Map<String, ?>>> mChildData;
private String[] mChildFrom;
private int[] mChildTo;
- public ContactExpandableListAdapter(Context context, List<? extends Map<String, ?>> groupData, int groupLayout,
- String[] groupFrom, int[] groupTo, List<? extends List<? extends Map<String, ?>>> childData,
- int childLayout, String[] childFrom, int[] childTo) {
- super(context, groupData, groupLayout, groupFrom, groupTo, childData, childLayout, childFrom, childTo);
+ public ContactExpandableListAdapter(Context context,
+ List<? extends Map<String, ?>> groupData, int groupLayout,
+ String[] groupFrom, int[] groupTo,
+ List<? extends List<? extends Map<String, ?>>> 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<String, ?> 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<String, ?> 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
--- /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();
+ }
+}
--- 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<String> mMessages = new ArrayList<String>();
- private ArrayAdapter<String> mAdapter;
- private SendIMDialogSmiley mSmyDialog;
+public class SendIM extends ListActivity implements OnClickListener,
+ OnKeyListener {
+ private EditText mToSend;
+ private ArrayList<String> mMessages = new ArrayList<String>();
+ private ArrayAdapter<String> 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<String>(this, R.layout.messagelist, mMessages);
+ mAdapter = new ArrayAdapter<String>(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()) {