Merge de la mort qui tue.
--- a/.classpath Mon Jun 22 15:38:20 2009 +0200
+++ b/.classpath Mon Jun 22 15:48:56 2009 +0200
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
- <classpathentry kind="lib" path="libs/smack.jar"/>
+ <classpathentry kind="lib" path="libs/smack.jar" sourcepath="/home/nikita/devel/smack_src_3_1_0"/>
<classpathentry kind="lib" path="libs/smackx-debug.jar"/>
<classpathentry kind="lib" path="libs/smackx-jingle.jar"/>
- <classpathentry kind="lib" path="libs/smackx.jar"/>
+ <classpathentry kind="lib" path="libs/smackx.jar" sourcepath="/home/nikita/devel/smack_src_3_1_0"/>
<classpathentry kind="lib" path="libs/jlibrtp-0.2.2.jar"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
--- a/AndroidManifest.xml Mon Jun 22 15:38:20 2009 +0200
+++ b/AndroidManifest.xml Mon Jun 22 15:48:56 2009 +0200
@@ -16,16 +16,11 @@
<activity android:name=".ui.SendIM" android:label="@string/SendIMActTitle"
android:launchMode="singleTop" />
<activity android:name=".ui.ChangeStatus" android:label="@string/ChangeStatusActTitle" />
- <activity android:name=".ui.AccountCreation" android:label="@string/app_name" />
<activity android:name=".ui.AddContact" android:label="@string/AddCActTitle" />
<activity android:name=".ui.Subscription" android:label="@string/app_name" />
- <activity android:name=".ui.EditSettings" android:label="@string/edit_settings_name">
- </activity>
- <activity android:name=".ui.CreateAccount" android:label="@string/create_account_name">
- </activity>
- <activity android:name=".ui.ContactList" android:label="@string/contact_list_name"
- android:launchMode="singleTask">
- </activity>
+ <activity android:name=".ui.EditSettings" android:label="@string/edit_settings_name" />
+ <activity android:name=".ui.CreateAccount" android:label="@string/create_account_name" />
+ <activity android:name=".ui.ContactList" android:label="@string/contact_list_name" android:launchMode="singleTask" />
<service android:name="BeemService" android:enabled="true"
android:label="Beem Service" android:permission="com.beem.project.beem.BEEM_SERVICE">
<intent-filter>
@@ -40,5 +35,6 @@
<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-sdk android:minSdkVersion="3"></uses-sdk>
+ <uses-sdk android:minSdkVersion="2"></uses-sdk>
+
</manifest>
--- a/res/layout/accountcreation.xml Mon Jun 22 15:38:20 2009 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,55 +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 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="@string/ACLogin"
- android:minWidth="70dp" />
-
- <EditText android:id="@+id/ac_login" 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" />
- </LinearLayout>
-
- <LinearLayout 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="@string/ACEmail"
- android:minWidth="70dp" />
- <EditText android:id="@+id/ac_email" 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 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="@string/ACPassword"
- android:minWidth="70dp" />
- <EditText android:id="@+id/ac_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>
- <LinearLayout 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="@string/ACRepeat"
- android:minWidth="70dp" />
- <EditText android:id="@+id/ac_password2"
- 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/ac_ok" android:layout_width="fill_parent"
- android:layout_gravity="center_horizontal" android:layout_height="wrap_content"
- android:text="@string/ACOkButton">
- <requestFocus />
- </Button>
-</LinearLayout>
\ No newline at end of file
--- a/res/layout/create_account.xml Mon Jun 22 15:38:20 2009 +0200
+++ b/res/layout/create_account.xml Mon Jun 22 15:48:56 2009 +0200
@@ -1,48 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <LinearLayout
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical"
+ android:orientation="vertical" android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+ <LinearLayout android:layout_width="fill_parent"
+ android:layout_height="fill_parent" android:orientation="vertical"
android:padding="10dip">
- <TextView android:id="@+id/create_account_label_username"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="@string/create_account_username"
- style="@style/Label" />
+ <TextView android:id="@+id/create_account_label_username"
+ android:layout_width="fill_parent" android:layout_height="wrap_content"
+ android:text="@string/create_account_username" style="@style/Label" />
<EditText android:id="@+id/create_account_username"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
+ android:layout_width="fill_parent" android:layout_height="wrap_content"
android:singleLine="true" />
- <TextView android:id="@+id/create_account_label_password"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="@string/create_account_password"
- style="@style/Label" />
+ <TextView android:id="@+id/create_account_label_password"
+ android:layout_width="fill_parent" android:layout_height="wrap_content"
+ android:text="@string/create_account_password" style="@style/Label" />
<EditText android:id="@+id/create_account_password"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:password="true"
- android:singleLine="true" />
- <TextView android:id="@+id/create_account_label_confirm_password"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="@string/create_account_confirm_password"
- style="@style/Label" />
+ android:layout_width="fill_parent" android:layout_height="wrap_content"
+ android:password="true" android:singleLine="true" />
+ <TextView android:id="@+id/create_account_label_confirm_password"
+ android:layout_width="fill_parent" android:layout_height="wrap_content"
+ android:text="@string/create_account_confirm_password" style="@style/Label" />
<EditText android:id="@+id/create_account_confirm_password"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:password="true"
- android:singleLine="true" />
- <View
- android:layout_height="21dp"
- android:layout_width="fill_parent" />
+ android:layout_width="fill_parent" android:layout_height="wrap_content"
+ android:password="true" android:singleLine="true" />
+ <View android:layout_height="21dp" android:layout_width="fill_parent" />
<Button android:id="@+id/create_account_button"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
+ android:layout_width="fill_parent" android:layout_height="fill_parent"
android:text="@string/button_create_account" />
+ <Button android:id="@+id/create_account_login_button"
+ android:layout_width="fill_parent" android:layout_height="fill_parent"
+ android:text="@string/button_create_login_account" />
</LinearLayout>
</ScrollView>
--- a/res/values/strings.xml Mon Jun 22 15:38:20 2009 +0200
+++ b/res/values/strings.xml Mon Jun 22 15:48:56 2009 +0200
@@ -65,6 +65,7 @@
<string name="ACPassword">Password:</string>
<string name="ACRepeat">Repeat:</string>
<string name="ACOkButton">Ok</string>
+ <string name="ACOkLoginButton">Log with</string>
<string name="ACBadForm">Bad form</string>
<string name="ACCreated">Account created</string>
@@ -140,6 +141,7 @@
<string name="button_login">Login</string>
<string name="button_save">Save</string>
<string name="button_create_account">Create this account</string>
+ <string name="button_create_login_account">Create and log</string>
<!--
--- a/src/com/beem/project/beem/service/BeemChatManager.java Mon Jun 22 15:38:20 2009 +0200
+++ b/src/com/beem/project/beem/service/BeemChatManager.java Mon Jun 22 15:48:56 2009 +0200
@@ -104,7 +104,7 @@
public void processMessage(Chat chat, Message message) {
ChatAdapter newchat = getChat(chat);
try {
-
+ Log.d(TAG, message.getBody());
if (message.getBody() != null)
newchat.addMessage(new com.beem.project.beem.service.Message(message));
final int n = mRemoteMessageListeners.beginBroadcast();
--- a/src/com/beem/project/beem/service/RosterAdapter.java Mon Jun 22 15:38:20 2009 +0200
+++ b/src/com/beem/project/beem/service/RosterAdapter.java Mon Jun 22 15:48:56 2009 +0200
@@ -5,7 +5,9 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -30,245 +32,276 @@
*/
public class RosterAdapter extends com.beem.project.beem.service.aidl.IRoster.Stub {
- /**
- * Listener for the roster events. It will call the remote listeners registered.
- *
- * @author darisk
- */
- private class RosterListenerAdapter implements RosterListener {
+ /**
+ * Listener for the roster events. It will call the remote listeners registered.
+ *
+ * @author darisk
+ */
+ private class RosterListenerAdapter implements RosterListener {
+
+ /**
+ * Constructor.
+ */
+ public RosterListenerAdapter() {
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void entriesAdded(Collection<String> addresses) {
+ Log.i(TAG, "Ajout de l'entry");
+ final int n = mRemoteRosListeners.beginBroadcast();
+
+ List<String> tab = new ArrayList<String>();
+ tab.addAll(addresses);
+ for (int i = 0; i < n; i++) {
+ IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
+ try {
+ listener.onEntriesAdded(tab);
+ } catch (RemoteException e) {
+ Log.w(TAG, "Error while adding roster entries", e);
+ }
+ }
+ mRemoteRosListeners.finishBroadcast();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @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>();
+ tab.addAll(addresses);
+ for (int i = 0; i < n; i++) {
+ IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
+ try {
+ listener.onEntriesDeleted(tab);
+ } catch (RemoteException e) {
+ Log.w(TAG, "Error while deleting roster entries", e);
+ }
+ }
+ mRemoteRosListeners.finishBroadcast();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void entriesUpdated(Collection<String> addresses) {
+ Log.d(TAG, "Update de l'entry");
+ final int n = mRemoteRosListeners.beginBroadcast();
+
+ List<String> tab = new ArrayList<String>();
+ tab.addAll(addresses);
+ for (int i = 0; i < n; i++) {
+ IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
+ try {
+ listener.onEntriesUpdated(tab);
+ } catch (RemoteException e) {
+ Log.w(TAG, "Error while updating roster entries", e);
+ }
+ }
+ mRemoteRosListeners.finishBroadcast();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void presenceChanged(Presence presence) {
+ Log.i(TAG, "Changement de Presence");
+ 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()));
+ c.setMsgState(presence.getStatus());
+ c.setName(mAdaptee.getEntry(user).getName());
+ /* 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();
+ }
+ }
+
+ 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.
- */
- public RosterListenerAdapter() {
- // TODO Auto-generated constructor stub
- }
-
- /**
- * {@inheritDoc}
- */
- @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();
- }
-
- /**
- * {@inheritDoc}
+ *
+ * @param roster
+ * the roster to adapt
*/
- @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);
+ public RosterAdapter(final Roster roster) {
+ mAdaptee = roster;
+ roster.addRosterListener(mRosterListener);
+ for (RosterEntry entry : roster.getEntries()) {
+ String user = StringUtils.parseBareAddress(entry.getUser());
+ if (!mContacts.containsKey(user)) {
+ Contact c = new Contact(user);
+ c.setStatus(roster.getPresence(user));
+ c.setGroups(entry.getGroups());
+ c.setName(entry.getName());
+ mContacts.put(user, c);
+ }
}
- }
- mRemoteRosListeners.finishBroadcast();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void entriesUpdated(Collection<String> addresses) {
- Log.d(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();
}
/**
* {@inheritDoc}
*/
@Override
- public void presenceChanged(Presence presence) {
- Log.i(TAG, "Changement de Presence");
- /* gestion du roster coter sedirvice */
- String user = StringUtils.parseBareAddress(presence.getFrom());
- Log.d(TAG, "User : " + user);
- 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()));
- c.setMsgState(presence.getStatus());
- c.setName(mAdaptee.getEntry(user).getName());
- /* 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();
+ public void addRosterListener(IBeemRosterListener listen) throws RemoteException {
+ if (listen != null)
+ mRemoteRosListeners.register(listen);
}
- }
- 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 = StringUtils.parseBareAddress(entry.getUser());
- if (!mContacts.containsKey(user)) {
- Contact c = new Contact(user);
- c.setStatus(roster.getPresence(user));
- c.setGroups(entry.getGroups());
- c.setName(entry.getName());
- mContacts.put(user, c);
- }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Contact addContact(String user, String name, String[] groups) throws RemoteException {
+ Contact res = null;
+ RosterEntry contact = mAdaptee.getEntry(user);
+ if (contact != null) {
+ res = mContacts.get(user);
+ for (String groupStr : groups) {
+ boolean found = false;
+ for (RosterGroup group: mAdaptee.getGroups()) {
+ if (group.getName().equals(groupStr) && !group.contains(contact)) {
+ try {
+ group.addEntry(contact);
+ res.addGroup(groupStr);
+ found = true;
+ } catch (XMPPException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ if (!found) {
+ try {
+ mAdaptee.createGroup(groupStr).addEntry(contact);
+ } catch (XMPPException e) {
+ e.printStackTrace();
+ } catch (IllegalArgumentException e) {
+ }
+ res.addGroup(groupStr);
+ }
+ }
+ } else {
+ try {
+ mAdaptee.createEntry(user, name, groups);
+ res = new Contact(user);
+ mContacts.put(user, res);
+ for (String groupStr : groups) {
+ try {
+ mAdaptee.createGroup(groupStr);
+ } catch (IllegalArgumentException e) {
+ //e.printStackTrace();
+ }
+ res.addGroup(groupStr);
+ }
+ } catch (XMPPException e) {
+ Log.e(TAG, "Error while adding new contact", e);
+ return null;
+ }
+ }
+ return res;
}
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void addRosterListener(IBeemRosterListener listen) throws RemoteException {
- if (listen != null)
- mRemoteRosListeners.register(listen);
- }
- /**
- * {@inheritDoc}
- */
- @Override
- public Contact addContact(String user, String name, String[] groups) throws RemoteException {
- try {
- mAdaptee.createEntry(user, name, groups);
- Contact res = new Contact(user);
- mContacts.put(user, res);
- for (String group : groups) {
- // mAdaptee.createGroup(group);
- res.addGroup(group);
- }
- return res;
- } catch (XMPPException e) {
- Log.e(TAG, "Error while adding new contact", e);
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void createGroup(String groupname) throws RemoteException {
+ mAdaptee.createGroup(groupname);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void deleteContact(Contact contact) throws RemoteException {
+ mContacts.remove(contact.getJID());
}
- }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Contact getContact(String jid) throws RemoteException {
+ return mContacts.get(jid);
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public void createGroup(String groupname) throws RemoteException {
- mAdaptee.createGroup(groupname);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void deleteContact(Contact contact) throws RemoteException {
- mContacts.remove(contact.getJID());
- }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List<Contact> getContactList() throws RemoteException {
+ List<Contact> res = new ArrayList<Contact>();
+ res.addAll(mContacts.values());
+ return res;
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public Contact getContact(String jid) throws RemoteException {
- return mContacts.get(jid);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public List<Contact> getContactList() throws RemoteException {
- List<Contact> res = new ArrayList<Contact>();
- res.addAll(mContacts.values());
- return res;
- }
+ /**
+ * {@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;
+ }
- /**
- * {@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());
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void removeRosterListener(IBeemRosterListener listen) throws RemoteException {
+ if (listen != null)
+ mRemoteRosListeners.unregister(listen);
}
- return result;
- }
- /**
- * {@inheritDoc}
- */
- @Override
- public void removeRosterListener(IBeemRosterListener listen) throws RemoteException {
- if (listen != null)
- mRemoteRosListeners.unregister(listen);
- }
+ /**
+ *
+ */
+ @Override
+ public void setContactName(String jid, String name) throws RemoteException {
+ mContacts.get(jid).setName(name);
+ mAdaptee.getEntry(jid).setName(name);
+ }
- /**
- *
- */
- @Override
- public void setContactName(String jid, String name) throws RemoteException {
- mContacts.get(jid).setName(name);
- mAdaptee.getEntry(jid).setName(name);
- }
+ @Override
+ public PresenceAdapter getPresence(String jid) throws RemoteException {
+ return new PresenceAdapter(mAdaptee.getPresence(jid));
+ }
}
--- a/src/com/beem/project/beem/service/aidl/IRoster.aidl Mon Jun 22 15:38:20 2009 +0200
+++ b/src/com/beem/project/beem/service/aidl/IRoster.aidl Mon Jun 22 15:48:56 2009 +0200
@@ -2,6 +2,7 @@
import com.beem.project.beem.service.aidl.IBeemRosterListener;
import com.beem.project.beem.service.Contact;
+import com.beem.project.beem.service.PresenceAdapter;
interface IRoster {
@@ -18,6 +19,8 @@
List<String> getGroupsNames();
+ PresenceAdapter getPresence(in String jid);
+
void addRosterListener(in IBeemRosterListener listen);
void removeRosterListener(in IBeemRosterListener listen);
--- a/src/com/beem/project/beem/ui/AccountCreation.java Mon Jun 22 15:38:20 2009 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,112 +0,0 @@
-/**
- *
- */
-package com.beem.project.beem.ui;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.jivesoftware.smack.AccountManager;
-import org.jivesoftware.smack.ConnectionConfiguration;
-import org.jivesoftware.smack.XMPPConnection;
-import org.jivesoftware.smack.XMPPException;
-
-import android.app.Activity;
-import android.content.SharedPreferences;
-import android.os.Bundle;
-import android.util.Log;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
-import android.widget.EditText;
-import android.widget.Toast;
-
-import com.beem.project.beem.R;
-
-/**
- * @author nikita
- */
-public class AccountCreation extends Activity {
-
- protected static final String TAG = "AccountCreation";
- private SharedPreferences mSettings;
- Map<String, String> mAttributes = new HashMap<String, String>();
-
- private OnClickListener mOkListener = new OnClickListener() {
-
- @Override
- public void onClick(View v) {
- boolean valid = true;
- if (getWidgetText(R.id.ac_login).length() == 0) {
- valid = false;
- } else {
- mAttributes.put("login", getWidgetText(R.id.ac_login));
- mAttributes.put("name", getWidgetText(R.id.ac_login));
- }
- if (getWidgetText(R.id.ac_password).length() == 0
- || !getWidgetText(R.id.ac_password).contains(
- getWidgetText(R.id.ac_password2))) {
- valid = false;
-
- } else {
- mAttributes.put("password", getWidgetText(R.id.ac_password));
- }
- if (getWidgetText(R.id.ac_email).length() == 0) {
- valid = false;
- } else {
- mAttributes.put("email", getWidgetText(R.id.ac_email));
- }
-
- if (valid) {
- setResult(RESULT_OK);
- try {
- createAccount();
- Toast
- .makeText(AccountCreation.this,
- getString(R.string.ACCreated),
- Toast.LENGTH_SHORT).show();
- finish();
- } catch (XMPPException e) {
- Log.e(TAG, "Account creation failed", e);
- Toast.makeText(AccountCreation.this, e.getMessage(),
- Toast.LENGTH_SHORT).show();
- e.printStackTrace();
- }
- } else {
- Toast.makeText(AccountCreation.this,
- getString(R.string.ACBadForm), Toast.LENGTH_SHORT)
- .show();
- setResult(RESULT_CANCELED);
- }
-
- }
- };
-
- protected void createAccount() throws XMPPException {
- String mHost = mSettings.getString(getString(R.string.PreferenceHostKey), "");
- XMPPConnection xmmpCo = new XMPPConnection(new ConnectionConfiguration(mHost));
- xmmpCo.connect();
- AccountManager accM = new AccountManager(xmmpCo);
- accM.createAccount(mAttributes.get("login"), mAttributes.get("password"), mAttributes);
- xmmpCo.disconnect();
- SharedPreferences.Editor editor = mSettings.edit();
-
- editor.putString(getString(R.string.PreferenceLoginKey), mAttributes.get("login"));
- editor.putString(getString(R.string.PreferencePasswordKey), mAttributes.get("password"));
- editor.commit();
- }
-
- private String getWidgetText(int id) {
- EditText widget = (EditText) this.findViewById(id);
- return widget.getText().toString();
- }
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.accountcreation);
- Button ok = (Button) findViewById(R.id.ac_ok);
- mSettings = getSharedPreferences(getString(R.string.PreferenceFileName), MODE_PRIVATE);
- ok.setOnClickListener(mOkListener);
- }
-}
--- a/src/com/beem/project/beem/ui/AddContact.java Mon Jun 22 15:38:20 2009 +0200
+++ b/src/com/beem/project/beem/ui/AddContact.java Mon Jun 22 15:48:56 2009 +0200
@@ -86,7 +86,13 @@
ok.setOnClickListener(mOkListener);
bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
}
-
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ unbindService(mServConn);
+ }
+
private class BeemServiceConnection implements ServiceConnection {
@Override
--- a/src/com/beem/project/beem/ui/ContactDialog.java Mon Jun 22 15:38:20 2009 +0200
+++ b/src/com/beem/project/beem/ui/ContactDialog.java Mon Jun 22 15:48:56 2009 +0200
@@ -47,7 +47,7 @@
button.setOnClickListener(new resendListener());
button = (Button) findViewById(R.id.CDInfos);
button.setOnClickListener(new infosListener());
-
+
mContext.bindService(new Intent(mContext, BeemService.class), mServConn, Service.BIND_AUTO_CREATE);
}
@@ -58,7 +58,7 @@
ContactDialogAliasDialog dialog = new ContactDialogAliasDialog(mContext, mContact);
dialog.setOwnerActivity(ContactDialog.this.getOwnerActivity());
- dialog.initService();
+ dialog.initService(xmppFacade);
dialog.show();
}
--- a/src/com/beem/project/beem/ui/ContactDialogAliasDialog.java Mon Jun 22 15:38:20 2009 +0200
+++ b/src/com/beem/project/beem/ui/ContactDialogAliasDialog.java Mon Jun 22 15:48:56 2009 +0200
@@ -3,15 +3,14 @@
*/
package com.beem.project.beem.ui;
-import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
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;
import com.beem.project.beem.service.Contact;
import com.beem.project.beem.service.aidl.IXmppFacade;
@@ -21,8 +20,7 @@
*/
public class ContactDialogAliasDialog extends Dialog {
- @SuppressWarnings("unused")
- private String mName;
+ protected static final String TAG = "CAlias";
private Contact mContact;
private IXmppFacade mService;
@@ -41,6 +39,7 @@
public void onClick(View v) {
EditText nameText = (EditText) findViewById(R.id.CDAliasDialogName);
try {
+ Log.d(TAG, mContact.getJID() + nameText.getText().toString());
mService.getRoster().setContactName(mContact.getJID(), nameText.getText().toString());
} catch (RemoteException e) {
e.printStackTrace();
@@ -51,8 +50,7 @@
});
}
- public void initService() {
- Activity a = ContactDialogAliasDialog.this.getOwnerActivity();
- mService = BeemApplication.getApplication(a).getXmppFacade();
+ public void initService(IXmppFacade service) {
+ mService = service;
}
}
--- a/src/com/beem/project/beem/ui/ContactList.java Mon Jun 22 15:38:20 2009 +0200
+++ b/src/com/beem/project/beem/ui/ContactList.java Mon Jun 22 15:48:56 2009 +0200
@@ -19,6 +19,7 @@
import android.os.Handler;
import android.os.IBinder;
import android.os.RemoteException;
+import android.text.util.Linkify;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
@@ -43,453 +44,449 @@
public class ContactList extends ExpandableListActivity {
- private static final String TAG = "CONTACTLIST_ACT";
- private static final String DEFAULT_GROUP = "Default";
- private MyExpandableListAdapter mAdapter;
- private IRoster mRoster;
- private Map<String, List<Contact>> groupMap;
- private List<String> groupName;
- private List<Contact> mListContact;
- private Handler mHandler;
- private IXmppFacade xmppFacade = null;
- private final ServiceConnection mServConn = new BeemServiceConnection();
- private int REQUEST_CODE = 1;
-
- /**
- * 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.contact_list, 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.contact_list_menu_settings:
- startActivityForResult(new Intent(this, EditSettings.class), REQUEST_CODE);
- return true;
- case R.id.contact_list_menu_add_contact:
- startActivity(new Intent(ContactList.this, AddContact.class));
- return true;
- default:
- return false;
- }
- }
-
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- if (requestCode == REQUEST_CODE) {
- startActivity(new Intent(ContactList.this, Login.class));
- }
- }
+ private static final String TAG = "CONTACTLIST_ACT";
+ private static final String DEFAULT_GROUP = "Default";
+ private MyExpandableListAdapter mAdapter;
+ private IRoster mRoster;
+ private Map<String, List<Contact>> groupMap;
+ private List<String> groupName;
+ private List<Contact> mListContact;
+ private Handler mHandler;
+ private IXmppFacade xmppFacade = null;
+ private final ServiceConnection mServConn = new BeemServiceConnection();
- @Override
- protected void onCreate(Bundle saveBundle) {
- super.onCreate(saveBundle);
- bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
- mHandler = new Handler();
- groupMap = new HashMap<String, List<Contact>>();
- groupName = new ArrayList<String>();
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- unbindService(mServConn);
- }
-
- class ComparatorContactListByName<T> implements Comparator<T> {
+ /**
+ * Callback for menu creation.
+ * @param menu the menu created
+ * @return true on success, false otherwise
+ */
@Override
- public int compare(T c1, T c2) {
- return ((Contact) c1).getName().compareToIgnoreCase(((Contact) c2).getName());
- }
- }
-
- class ComparatorContactListByStatusAndName<T> implements Comparator<T> {
- @Override
- public int compare(T c1, T c2) {
- if (((Contact) c1).getStatus() < ((Contact) c2).getStatus()) {
- return 1;
- } else if (((Contact) c1).getStatus() > ((Contact) c2).getStatus()) {
- return -1;
- } else
- return ((Contact) c1).getName().compareToIgnoreCase(((Contact) c2).getName());
+ public final boolean onCreateOptionsMenu(Menu menu) {
+ super.onCreateOptionsMenu(menu);
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.contact_list, menu);
+ return true;
}
- }
- private void buildContactList(List<Contact> listContact) {
- mListContact = listContact;
- Collections.sort(mListContact, new ComparatorContactListByStatusAndName<Contact>());
- for (Contact contact : mListContact) {
- for (String group : contact.getGroups()) {
- if (!groupMap.containsKey(group)) {
- groupMap.put(group, new ArrayList<Contact>());
- groupName.add(group);
+ /**
+ * 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.contact_list_menu_settings:
+ startActivity(new Intent(this, EditSettings.class));
+ return true;
+ case R.id.contact_list_menu_add_contact:
+ startActivity(new Intent(ContactList.this, AddContact.class));
+ return true;
+ default:
+ return false;
}
- try {
- if (!groupMap.get(group).contains(contact))
- groupMap.get(group).add(contact);
- } catch (NullPointerException e) {
- Log.e(TAG, "Failed to find group in groupMap", e);
- }
- }
- if (contact.getGroups().isEmpty()) {
- if (!groupMap.containsKey(DEFAULT_GROUP)) {
- groupMap.put(DEFAULT_GROUP, new ArrayList<Contact>());
- groupName.add(DEFAULT_GROUP);
- }
- groupMap.get(DEFAULT_GROUP).add(contact);
- }
}
- mAdapter = new MyExpandableListAdapter();
- setListAdapter(mAdapter);
- }
-
- private class BeemRosterListener extends IBeemRosterListener.Stub {
@Override
- public void onEntriesAdded(List<String> addresses) throws RemoteException {
- for (String str : addresses) {
- Contact curContact = mRoster.getContact(str);
- for (String group : curContact.getGroups()) {
- if (!groupMap.containsKey(group)) {
- groupMap.put(group, new ArrayList<Contact>());
- groupName.add(group);
- }
- try {
- groupMap.get(group).add(curContact);
- } catch (NullPointerException e) {
- Log.e(TAG, "Failed to find group in groupMap", e);
- }
- }
- }
- mHandler.post(new RunnableChange());
+ protected void onCreate(Bundle saveBundle) {
+ super.onCreate(saveBundle);
+ bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
+ mHandler = new Handler();
+ groupMap = new HashMap<String, List<Contact>>();
+ groupName = new ArrayList<String>();
}
@Override
- public void onEntriesDeleted(List<String> addresses) throws RemoteException {
- for (List<Contact> cList : groupMap.values()) {
- for (Contact curContact : cList) {
- for (String addr : addresses) {
- if (addr.equals(curContact.getJID())) {
- cList.remove(curContact);
- if (cList.isEmpty()) {
- groupMap.values().remove(cList);
- }
+ protected void onDestroy() {
+ super.onDestroy();
+ unbindService(mServConn);
+ }
+
+ class ComparatorContactListByName<T> implements Comparator<T> {
+ @Override
+ public int compare(T c1, T c2) {
+ return ((Contact) c1).getName().compareToIgnoreCase(((Contact) c2).getName());
+ }
+ }
+
+ class ComparatorContactListByStatusAndName<T> implements Comparator<T> {
+ @Override
+ public int compare(T c1, T c2) {
+ if (((Contact) c1).getStatus() < ((Contact) c2).getStatus()) {
+ return 1;
+ } else if (((Contact) c1).getStatus() > ((Contact) c2).getStatus()) {
+ return -1;
+ } else
+ return ((Contact) c1).getName().compareToIgnoreCase(((Contact) c2).getName());
+ }
+ }
+
+ private void buildContactList(List<Contact> listContact) {
+ mListContact = listContact;
+ Collections.sort(mListContact, new ComparatorContactListByStatusAndName<Contact>());
+ for (Contact contact : mListContact) {
+ for (String group : contact.getGroups()) {
+ if (!groupMap.containsKey(group)) {
+ groupMap.put(group, new ArrayList<Contact>());
+ Collections.sort(groupMap.get(group), new ComparatorContactListByStatusAndName<Contact>());
+ groupName.add(group);
+ }
+ try {
+ if (!groupMap.get(group).contains(contact))
+ groupMap.get(group).add(contact);
+ } catch (NullPointerException e) {
+ Log.e(TAG, "Failed to find group in groupMap", e);
+ }
}
- }
+ if (contact.getGroups().isEmpty()) {
+ if (!groupMap.containsKey(DEFAULT_GROUP)) {
+ groupMap.put(DEFAULT_GROUP, new ArrayList<Contact>());
+ groupName.add(DEFAULT_GROUP);
+ }
+ groupMap.get(DEFAULT_GROUP).add(contact);
+ }
}
- }
- mHandler.post(new RunnableChange());
+ mAdapter = new MyExpandableListAdapter();
+ setListAdapter(mAdapter);
}
- @Override
- public void onEntriesUpdated(List<String> addresses) throws RemoteException {
- for (String str : addresses) {
- Contact curContact = mRoster.getContact(str);
- for (String group : curContact.getGroups()) {
- if (!groupMap.containsKey(group)) {
- groupMap.put(group, new ArrayList<Contact>());
- groupName.add(group);
- groupMap.get(group).add(curContact);
- } else {
- boolean found = false;
- for (Contact tempContact : groupMap.get(group)) {
- if (tempContact.getJID() == str) {
- curContact = tempContact;
- found = true;
- break;
- }
+ private class BeemRosterListener extends IBeemRosterListener.Stub {
+
+ @Override
+ public void onEntriesAdded(List<String> addresses) throws RemoteException {
+ for (String str : addresses) {
+ Contact curContact = mRoster.getContact(str);
+ for (String group : curContact.getGroups()) {
+ if (!groupMap.containsKey(group)) {
+ groupMap.put(group, new ArrayList<Contact>());
+ groupName.add(group);
+ }
+ try {
+ groupMap.get(group).add(curContact);
+ } catch (NullPointerException e) {
+ Log.e(TAG, "Failed to find group in groupMap", e);
+ }
+ }
}
- if (!found) {
- groupMap.get(group).add(curContact);
+ mHandler.post(new RunnableChange());
+ }
+
+ @Override
+ public void onEntriesDeleted(List<String> addresses) throws RemoteException {
+ for (List<Contact> cList : groupMap.values()) {
+ for (Contact curContact : cList) {
+ for (String addr : addresses) {
+ if (addr.equals(curContact.getJID())) {
+ cList.remove(curContact);
+ if (cList.isEmpty()) {
+ groupMap.values().remove(cList);
+ }
+ }
+ }
+ }
}
- }
+ mHandler.post(new RunnableChange());
}
- }
- mHandler.post(new RunnableChange());
- }
- @Override
- public void onPresenceChanged(PresenceAdapter presence) throws RemoteException {
- for (Contact curContact : mListContact) {
- if (curContact.getJID().equals(StringUtils.parseBareAddress(presence.getFrom()))) {
- curContact.setStatus(presence);
- mHandler.post(new RunnableChange());
- return;
+ @Override
+ public void onEntriesUpdated(List<String> addresses) throws RemoteException {
+ for (String str : addresses) {
+ Contact curContact = mRoster.getContact(str);
+ for (String group : curContact.getGroups()) {
+ if (!groupMap.containsKey(group)) {
+ groupMap.put(group, new ArrayList<Contact>());
+ groupName.add(group);
+ groupMap.get(group).add(curContact);
+ } else {
+ boolean found = false;
+ for (Contact tempContact : groupMap.get(group)) {
+ if (tempContact.getJID().equals(str)) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ groupMap.get(group).add(curContact);
+ }
+ }
+ }
+ }
+ mHandler.post(new RunnableChange());
}
- }
- }
-
- private class RunnableChange implements Runnable {
- @Override
- public void run() {
- mAdapter.changed();
- }
- }
- }
-
- private class MyExpandableListAdapter implements ExpandableListAdapter {
-
- class MyOnClickListener implements OnClickListener {
-
- private final Contact mContact;
+ @Override
+ public void onPresenceChanged(PresenceAdapter presence) throws RemoteException {
+ for (Contact curContact : mListContact) {
+ if (curContact.getJID().equals(StringUtils.parseBareAddress(presence.getFrom()))) {
+ curContact.setStatus(mRoster.getPresence(StringUtils.parseBareAddress(presence.getFrom())));
+ mHandler.post(new RunnableChange());
+ return;
+ }
+ }
+ }
- public MyOnClickListener(Contact contact) {
- mContact = contact;
- }
-
- @Override
- public void onClick(View v) {
- Intent i = new Intent(ContactList.this, SendIM.class);
- i.setData(mContact.toUri());
- startActivity(i);
- }
+ private class RunnableChange implements Runnable {
+ @Override
+ public void run() {
+ mAdapter.changed();
+ }
+ }
}
- class MyOnLongClickListener implements OnLongClickListener {
+ private class MyExpandableListAdapter implements ExpandableListAdapter {
+
+ class MyOnClickListener implements OnClickListener {
- private final Contact mContact;
+ private final Contact mContact;
+
+ public MyOnClickListener(Contact contact) {
+ mContact = contact;
+ }
- public MyOnLongClickListener(Contact contact) {
- mContact = contact;
- }
+ @Override
+ public void onClick(View v) {
+ Intent i = new Intent(ContactList.this, SendIM.class);
+ i.setData(mContact.toUri());
+ startActivity(i);
+ }
+
+ }
+
+ class MyOnLongClickListener implements OnLongClickListener {
+
+ private final Contact mContact;
- @Override
- public boolean onLongClick(View v) {
- createDialog(mContact);
- return true;
- }
- }
+ public MyOnLongClickListener(Contact contact) {
+ mContact = contact;
+ }
- private final List<DataSetObserver> observers;
+ @Override
+ public boolean onLongClick(View v) {
+ createDialog(mContact);
+ return true;
+ }
+ }
- public MyExpandableListAdapter() {
- observers = new ArrayList<DataSetObserver>();
- }
+ private final List<DataSetObserver> observers;
+
+ public MyExpandableListAdapter() {
+ observers = new ArrayList<DataSetObserver>();
+ }
+
- @Override
- public boolean areAllItemsEnabled() {
- return true;
- }
+ @Override
+ public boolean areAllItemsEnabled() {
+ return true;
+ }
- private void bindView(View view, Contact curContact) {
+ private void bindView(View view, Contact curContact) {
- if (curContact != null) {
- ImageView imgV = (ImageView) view.findViewById(R.id.contactliststatus);
- Drawable imageDrawable = null;
- switch (curContact.getStatus()) {
- case Status.CONTACT_STATUS_AVAILABLE:
- imageDrawable = getResources().getDrawable(R.drawable.online);
- break;
- case Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT:
- imageDrawable = getResources().getDrawable(R.drawable.chat);
- break;
- case Status.CONTACT_STATUS_AWAY:
- imageDrawable = getResources().getDrawable(R.drawable.away);
- break;
- case Status.CONTACT_STATUS_BUSY:
- imageDrawable = getResources().getDrawable(R.drawable.dnd);
- break;
- case Status.CONTACT_STATUS_DISCONNECT:
- imageDrawable = getResources().getDrawable(R.drawable.offline);
- break;
- case Status.CONTACT_STATUS_UNAVAILABLE:
- imageDrawable = getResources().getDrawable(R.drawable.requested);
- break;
- default:
- imageDrawable = getResources().getDrawable(R.drawable.error);
- break;
+ if (curContact != null) {
+ ImageView imgV = (ImageView) view.findViewById(R.id.contactliststatus);
+ Drawable imageDrawable = null;
+ switch (curContact.getStatus()) {
+ case Status.CONTACT_STATUS_AVAILABLE:
+ imageDrawable = getResources().getDrawable(R.drawable.online);
+ break;
+ case Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT:
+ imageDrawable = getResources().getDrawable(R.drawable.chat);
+ break;
+ case Status.CONTACT_STATUS_AWAY:
+ imageDrawable = getResources().getDrawable(R.drawable.away);
+ break;
+ case Status.CONTACT_STATUS_BUSY:
+ imageDrawable = getResources().getDrawable(R.drawable.dnd);
+ break;
+ case Status.CONTACT_STATUS_DISCONNECT:
+ imageDrawable = getResources().getDrawable(R.drawable.offline);
+ break;
+ case Status.CONTACT_STATUS_UNAVAILABLE:
+ imageDrawable = getResources().getDrawable(R.drawable.requested);
+ break;
+ default:
+ imageDrawable = getResources().getDrawable(R.drawable.error);
+ break;
+ }
+ imgV.setImageDrawable(imageDrawable);
+
+ TextView v = (TextView) view.findViewById(R.id.contactlistpseudo);
+ if (v != null) {
+ v.setText(curContact.getName());
+ }
+
+ v = (TextView) view.findViewById(R.id.contactlistmsgperso);
+ if (v != null) {
+ v.setText(curContact.getMsgState());
+ Linkify.addLinks(v, Linkify.WEB_URLS);
+ }
+
+ // TODO: Rajouter l'avatar du contact getAvatar() dans la classe
+ imgV = (ImageView) view.findViewById(R.id.contactlistavatar);
+ if (imgV != null) {
+ imageDrawable = getResources().getDrawable(R.drawable.avatar);
+ imgV.setImageDrawable(imageDrawable);
+ }
+ }
}
- imgV.setImageDrawable(imageDrawable);
- TextView v = (TextView) view.findViewById(R.id.contactlistpseudo);
- if (v != null) {
- v.setText(curContact.getName());
+ public void changed() {
+ for (String name : groupName) {
+ Collections.sort(groupMap.get(name), new ComparatorContactListByStatusAndName<Contact>());
+ }
+ for (DataSetObserver obs : observers) {
+ obs.onChanged();
+ }
+ }
+
+ void createDialog(Contact contact) {
+ ContactDialog dialogContact = new ContactDialog(ContactList.this, contact);
+ dialogContact.setOwnerActivity(ContactList.this);
+ dialogContact.show();
}
- v = (TextView) view.findViewById(R.id.contactlistmsgperso);
- if (v != null) {
- v.setText(curContact.getMsgState());
+ @Override
+ public Object getChild(int groupPosition, int childPosition) {
+ try {
+ return groupMap.get(groupName.get(groupPosition)).get(childPosition);
+ } catch (NullPointerException e) {
+ Log.e(TAG, "Child not found", e);
+ return null;
+ }
+ }
+
+ @Override
+ public long getChildId(int groupPosition, int childPosition) {
+ try {
+ groupMap.get(groupName.get(groupPosition)).get(childPosition);
+ } catch (NullPointerException e) {
+ Log.e(TAG, "Child not found", e);
+ return 0;
+ }
+ return childPosition;
+ }
+
+ @Override
+ public int getChildrenCount(int groupPosition) {
+ try {
+ return groupMap.get(groupName.get(groupPosition)).size();
+ } catch (NullPointerException e) {
+ Log.e(TAG, "Child not found", e);
+ return 0;
+ }
+ }
+
+ @Override
+ public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView,
+ ViewGroup parent) {
+ View v;
+ if (convertView == null) {
+ v = LayoutInflater.from(ContactList.this).inflate(R.layout.contactlistcontact, null);
+ } else {
+ v = convertView;
+ }
+ Contact contact = groupMap.get(groupName.get(groupPosition)).get(childPosition);
+ bindView(v, contact);
+
+ v.setOnLongClickListener(new MyOnLongClickListener(contact));
+ v.setOnClickListener(new MyOnClickListener(contact));
+ return v;
+ }
+
+ @Override
+ public long getCombinedChildId(long groupId, long childId) {
+ return 1000 * groupId + childId;
+ }
+
+ @Override
+ public long getCombinedGroupId(long groupId) {
+ return 1000 * groupId;
}
- // TODO: Rajouter l'avatar du contact getAvatar() dans la classe
- imgV = (ImageView) view.findViewById(R.id.contactlistavatar);
- if (imgV != null) {
- imageDrawable = getResources().getDrawable(R.drawable.avatar);
- imgV.setImageDrawable(imageDrawable);
+ @Override
+ public Object getGroup(int groupPosition) {
+ try {
+ return groupMap.get(groupName.get(groupPosition));
+ } catch (NullPointerException e) {
+ Log.e(TAG, "Group not found", e);
+ return null;
+ }
+ }
+
+ @Override
+ public int getGroupCount() {
+ return groupMap.size();
}
- }
- }
+
+ @Override
+ public long getGroupId(int groupPosition) {
+ return groupPosition;
+ }
- public void changed() {
- for (DataSetObserver obs : observers) {
- obs.onChanged();
- }
- }
+ @Override
+ public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
+ if (convertView == null) {
+ convertView = LayoutInflater.from(ContactList.this).inflate(R.layout.contactlistgroup, null);
+ }
+ TextView groupTextView = (TextView) convertView.findViewById(R.id.textgroup);
+ groupTextView.setText(groupName.get(groupPosition));
+ return convertView;
+ }
- void createDialog(Contact contact) {
- ContactDialog dialogContact = new ContactDialog(ContactList.this, contact);
- dialogContact.setOwnerActivity(ContactList.this);
- dialogContact.show();
- }
+ @Override
+ public boolean hasStableIds() {
+ return false;
+ }
+
+ @Override
+ public boolean isChildSelectable(int groupPosition, int childPosition) {
+ return true;
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return groupMap.isEmpty();
+ }
- @Override
- public Object getChild(int groupPosition, int childPosition) {
- try {
- return groupMap.get(groupName.get(groupPosition)).get(childPosition);
- } catch (NullPointerException e) {
- Log.e(TAG, "Child not found", e);
- return null;
- }
- }
+ @Override
+ public void onGroupCollapsed(int groupPosition) {
+ }
+
+ @Override
+ public void onGroupExpanded(int groupPosition) {
+ }
- @Override
- public long getChildId(int groupPosition, int childPosition) {
- try {
- groupMap.get(groupName.get(groupPosition)).get(childPosition);
- } catch (NullPointerException e) {
- Log.e(TAG, "Child not found", e);
- return 0;
- }
- return childPosition;
+ @Override
+ public void registerDataSetObserver(DataSetObserver observer) {
+ observers.add(observer);
+ }
+
+ @Override
+ public void unregisterDataSetObserver(DataSetObserver observer) {
+ observers.remove(observer);
+ }
}
- @Override
- public int getChildrenCount(int groupPosition) {
- try {
- return groupMap.get(groupName.get(groupPosition)).size();
- } catch (NullPointerException e) {
- Log.e(TAG, "Child not found", e);
- return 0;
- }
- }
-
- @Override
- public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView,
- ViewGroup parent) {
- View v;
- if (convertView == null) {
- v = LayoutInflater.from(ContactList.this).inflate(R.layout.contactlistcontact, null);
- } else {
- v = convertView;
- }
- Contact contact = groupMap.get(groupName.get(groupPosition)).get(childPosition);
- bindView(v, contact);
-
- v.setOnLongClickListener(new MyOnLongClickListener(contact));
- v.setOnClickListener(new MyOnClickListener(contact));
- return v;
- }
-
- @Override
- public long getCombinedChildId(long groupId, long childId) {
- return 1000 * groupId + childId;
- }
-
- @Override
- public long getCombinedGroupId(long groupId) {
- return 1000 * groupId;
- }
-
- @Override
- public Object getGroup(int groupPosition) {
- try {
- return groupMap.get(groupName.get(groupPosition));
- } catch (NullPointerException e) {
- Log.e(TAG, "Group not found", e);
- return null;
- }
- }
-
- @Override
- public int getGroupCount() {
- return groupMap.size();
- }
-
- @Override
- public long getGroupId(int groupPosition) {
- return groupPosition;
- }
+ private class BeemServiceConnection implements ServiceConnection {
- @Override
- public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
- if (convertView == null) {
- convertView = LayoutInflater.from(ContactList.this).inflate(R.layout.contactlistgroup, null);
- }
- TextView groupTextView = (TextView) convertView.findViewById(R.id.textgroup);
- groupTextView.setText(groupName.get(groupPosition));
- return convertView;
- }
-
- @Override
- public boolean hasStableIds() {
- return false;
- }
-
- @Override
- public boolean isChildSelectable(int groupPosition, int childPosition) {
- return true;
- }
-
- @Override
- public boolean isEmpty() {
- return groupMap.isEmpty();
- }
-
- @Override
- public void onGroupCollapsed(int groupPosition) {
- }
-
- @Override
- public void onGroupExpanded(int groupPosition) {
- }
+ @Override
+ public void onServiceConnected(ComponentName name, IBinder service) {
+ xmppFacade = IXmppFacade.Stub.asInterface(service);
+ try {
+ mRoster = xmppFacade.getRoster();
+ if (mRoster != null) {
+ mRoster.addRosterListener(new BeemRosterListener());
+ buildContactList(mRoster.getContactList());
+ }
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ }
- @Override
- public void registerDataSetObserver(DataSetObserver observer) {
- observers.add(observer);
- }
-
- @Override
- public void unregisterDataSetObserver(DataSetObserver observer) {
- observers.remove(observer);
+ @Override
+ public void onServiceDisconnected(ComponentName name) {
+ xmppFacade = null;
+ mRoster = null;
+ }
}
- }
-
- private class BeemServiceConnection implements ServiceConnection {
-
- @Override
- public void onServiceConnected(ComponentName name, IBinder service) {
- xmppFacade = IXmppFacade.Stub.asInterface(service);
- try {
- mRoster = xmppFacade.getRoster();
- if (mRoster != null) {
- mRoster.addRosterListener(new BeemRosterListener());
- buildContactList(mRoster.getContactList());
- }
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- }
-
- @Override
- public void onServiceDisconnected(ComponentName name) {
- xmppFacade = null;
- mRoster = null;
- }
- }
}
--- a/src/com/beem/project/beem/ui/CreateAccount.java Mon Jun 22 15:38:20 2009 +0200
+++ b/src/com/beem/project/beem/ui/CreateAccount.java Mon Jun 22 15:48:56 2009 +0200
@@ -38,6 +38,18 @@
private SharedPreferences settings = null;
private Button createAccountButton = null;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.create_account);
+ initCreateAccountButton();
+ settings = getSharedPreferences(getString(R.string.settings_filename), MODE_PRIVATE);
+ }
+
/**
* Check if the fields password and confirm password match
*
@@ -46,7 +58,7 @@
private boolean checkPasswords() {
final String passwordFieldValue = ((EditText) findViewById(R.id.create_account_password)).getText().toString();
final String passwordConfirmFielddValue = ((EditText) findViewById(R.id.create_account_confirm_password))
- .getText().toString();
+ .getText().toString();
if (passwordFieldValue.equals(passwordConfirmFielddValue))
return (true);
@@ -56,13 +68,13 @@
/**
* Create an account on the XMPP server specified in settings
*/
- private void createAccount(String username, String password) {
+ private boolean createAccount(String username, String password) {
XMPPConnection xmppConnection = null;
ConnectionConfiguration connectionConfiguration = null;
if (getRegisteredProxy() != null) {
connectionConfiguration = new ConnectionConfiguration(getRegisteredXMPPServer(), getRegisteredXMPPPort(),
- getRegisteredProxy());
+ getRegisteredProxy());
} else {
connectionConfiguration = new ConnectionConfiguration(getRegisteredXMPPServer(), getRegisteredXMPPPort());
}
@@ -75,13 +87,15 @@
AccountManager accountManager = new AccountManager(xmppConnection);
accountManager.createAccount(username, password);
Toast toast = Toast.makeText(getApplicationContext(), "Account " + username + " "
- + getString(R.string.create_account_successfull_after), NOTIFICATION_DURATION);
+ + getString(R.string.create_account_successfull_after), NOTIFICATION_DURATION);
toast.show();
} catch (XMPPException e) {
Log.e(getString(R.string.create_account_tag), e.getMessage());
createErrorDialog(e.getMessage());
+ return false;
}
xmppConnection.disconnect();
+ return true;
}
/**
@@ -113,7 +127,7 @@
private ProxyInfo getRegisteredProxy() {
if (getRegisteredProxyUse()) {
ProxyInfo proxyInfo = new ProxyInfo(getRegisteredProxyType(), getRegisteredProxyServer(),
- getRegisteredProxyPort(), getRegisteredProxyUsername(), getRegisteredProxyPassword());
+ getRegisteredProxyPort(), getRegisteredProxyUsername(), getRegisteredProxyPassword());
return (proxyInfo);
}
return (null);
@@ -153,15 +167,15 @@
*/
private ProxyInfo.ProxyType getRegisteredProxyType() {
switch (settings.getInt(getString(R.string.settings_key_proxy_type), DEFAULT_INT_VALUE)) {
- case 0:
- return ProxyInfo.ProxyType.HTTP;
- case 1:
- return ProxyInfo.ProxyType.SOCKS4;
- case 2:
- Log.i(getString(R.string.create_account_tag), "SOCKS5 PROXY");
- return ProxyInfo.ProxyType.SOCKS5;
- default:
- return ProxyInfo.ProxyType.NONE;
+ case 0:
+ return ProxyInfo.ProxyType.HTTP;
+ case 1:
+ return ProxyInfo.ProxyType.SOCKS4;
+ case 2:
+ Log.i(getString(R.string.create_account_tag), "SOCKS5 PROXY");
+ return ProxyInfo.ProxyType.SOCKS5;
+ default:
+ return ProxyInfo.ProxyType.NONE;
}
}
@@ -216,12 +230,11 @@
private void initCreateAccountButton() {
createAccountButton = (Button) findViewById(R.id.create_account_button);
createAccountButton.setOnClickListener(new View.OnClickListener() {
-
public void onClick(View v) {
String usernameFieldValue = ((EditText) findViewById(R.id.create_account_username)).getText()
- .toString();
+ .toString();
String passwordFieldValue = ((EditText) findViewById(R.id.create_account_password)).getText()
- .toString();
+ .toString();
if (!checkPasswords())
createErrorDialog(getString(R.string.create_account_err_passwords));
@@ -229,16 +242,26 @@
createAccount(usernameFieldValue, passwordFieldValue);
}
});
- }
+ Button createAccountLoginButton = (Button) findViewById(R.id.create_account_login_button);
+ createAccountLoginButton.setOnClickListener(new View.OnClickListener() {
+ public void onClick(View v) {
+ String usernameFieldValue = ((EditText) findViewById(R.id.create_account_username)).getText()
+ .toString();
+ String passwordFieldValue = ((EditText) findViewById(R.id.create_account_password)).getText()
+ .toString();
- /**
- * {@inheritDoc}
- */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.create_account);
- initCreateAccountButton();
- settings = getSharedPreferences(getString(R.string.settings_filename), MODE_PRIVATE);
- }
+ if (!checkPasswords())
+ createErrorDialog(getString(R.string.create_account_err_passwords));
+ else {
+ if (createAccount(usernameFieldValue, passwordFieldValue)) {
+ SharedPreferences.Editor settingsEditor = settings.edit();
+ settingsEditor.putString(getString(R.string.settings_key_account_username), usernameFieldValue);
+ settingsEditor.putString(getString(R.string.settings_key_account_password), passwordFieldValue);
+ settingsEditor.commit();
+ finish();
+ }
+ }
+ }
+ });
+ }
}
--- a/src/com/beem/project/beem/ui/SendIM.java Mon Jun 22 15:38:20 2009 +0200
+++ b/src/com/beem/project/beem/ui/SendIM.java Mon Jun 22 15:48:56 2009 +0200
@@ -2,6 +2,8 @@
import java.util.List;
+import org.jivesoftware.smack.util.StringUtils;
+
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
@@ -12,6 +14,7 @@
import android.os.Handler;
import android.os.IBinder;
import android.os.RemoteException;
+import android.text.util.Linkify;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
@@ -29,10 +32,13 @@
import com.beem.project.beem.R;
import com.beem.project.beem.service.Contact;
import com.beem.project.beem.service.Message;
+import com.beem.project.beem.service.PresenceAdapter;
+import com.beem.project.beem.service.aidl.IBeemRosterListener;
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;
+import com.beem.project.beem.service.aidl.IRoster;
import com.beem.project.beem.service.aidl.IXmppFacade;
/**
@@ -42,332 +48,382 @@
public class SendIM extends Activity implements OnClickListener, OnKeyListener {
- private static final String TAG = "SEND_IM";
- private EditText mToSend;
- private SendIMDialogSmiley mSmyDialog;
- private SharedPreferences mSet;
- private Handler mHandler;
- private Contact mContact;
- private IChatManager mChatManager;
- private IChatManagerListener mChatManagerListener;
- private IMessageListener mMessageListener;
- private IChat mChat;
- private TextView mText;
- private TextView mLogin;
- private ScrollView mScrolling;
- private char mSpeak;
-
- private final ServiceConnection mServConn = new BeemServiceConnection();
- private IXmppFacade xmppFacade;
-
- /**
- * Constructor.
- */
- public SendIM() {
- super();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void onClick(View view) {
- sendText();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void onCreate(Bundle saveBundle) {
- super.onCreate(saveBundle);
- mHandler = new Handler();
- mChatManagerListener = new OnChatListener();
- mMessageListener = new OnMessageListener();
- setContentView(R.layout.sendim);
- mToSend = (EditText) findViewById(R.id.userText);
- mSet = getSharedPreferences("lol", MODE_PRIVATE);
- mSmyDialog = new SendIMDialogSmiley(this, mSet);
- mToSend.setOnClickListener(this);
- mToSend.setOnKeyListener(this);
- mLogin = (TextView) findViewById(R.id.sendimlogin);
- mContact = new Contact(getIntent().getData());
- setViewHeader();
- mText = (TextView) findViewById(R.id.sendimlist);
- mScrolling = (ScrollView) findViewById(R.id.sendimscroll);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public final boolean onCreateOptionsMenu(Menu menu) {
- super.onCreateOptionsMenu(menu);
- MenuInflater inflater = getMenuInflater();
- inflater.inflate(R.menu.sendimmenu, menu);
- return true;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void onDestroy() {
- super.onDestroy();
- if (mChatManager != null) {
- try {
- mChatManager.removeChatCreationListener(mChatManagerListener);
- // TODO trouver quand detruire le chat
- // mChatManager.destroyChat(mChat);
- } catch (RemoteException e) {
- Log.e(TAG, "mchat manager and SendIM destroy", e);
- }
- }
- }
+ private static final String TAG = "SEND_IM";
+ private EditText mToSend;
+ private SendIMDialogSmiley mSmyDialog;
+ private SharedPreferences mSet;
+ private Handler mHandler;
+ private Contact mContact;
+ private IChatManager mChatManager;
+ private IChatManagerListener mChatManagerListener;
+ private IMessageListener mMessageListener;
+ private IChat mChat;
+ private TextView mText;
+ private TextView mLogin;
+ private ScrollView mScrolling;
+ private char mSpeak;
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean onKey(View v, int keyCode, KeyEvent event) {
- if (event.getAction() == KeyEvent.ACTION_DOWN) {
- switch (keyCode) {
- case KeyEvent.KEYCODE_DPAD_CENTER:
- case KeyEvent.KEYCODE_ENTER:
- sendText();
- return true;
- default:
- return false;
- }
- }
- return false;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void onNewIntent(Intent intent) {
- super.onNewIntent(intent);
- mContact = new Contact(intent.getData());
- setViewHeader();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public final boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case R.id.sendim_smiley:
- mSmyDialog.show();
- return true;
- default:
- return false;
- }
- }
+ private final ServiceConnection mServConn = new BeemServiceConnection();
+ private IXmppFacade xmppFacade;
+ public IRoster mRoster;
+ private TextView mStatusText;
- /**
- * {@inheritDoc}
- */
- @Override
- protected void onPause() {
- super.onPause();
- try {
- mChat.setOpen(false);
- } catch (RemoteException e) {
- Log.d(TAG, "Error while closing chat", e);
- }
- unbindService(mServConn);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void onResume() {
- super.onResume();
- bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
- mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void onStart() {
- super.onStart();
- // TODO cancel the notification if any
- if (mContact == null)
- mContact = getIntent().getParcelableExtra("contact");
- setViewHeader();
-
- }
-
- private class BeemServiceConnection implements ServiceConnection {
-
- @Override
- public void onServiceConnected(ComponentName name, IBinder service) {
- xmppFacade = IXmppFacade.Stub.asInterface(service);
- try {
- if (mChatManager == null) {
- mChatManager = xmppFacade.getChatManager();
- mChatManager.addChatCreationListener(mChatManagerListener);
- }
- switchChat(mContact);
- } catch (RemoteException e) {
- Log.e(TAG, "Error during chat manager creation", e);
- }
+ /**
+ * Constructor.
+ */
+ public SendIM() {
+ super();
}
- @Override
- public void onServiceDisconnected(ComponentName name) {
- xmppFacade = null;
- }
- }
-
- /**
- * Send a message to the contact over the XMPP connection. Also display it on activity view. TODO : Gerer
- * l'exception si la connexion se coupe pendant la conversation
- */
- private void sendText() {
- String text = mToSend.getText().toString();
- if (!text.equals("")) {
- Message msg = new Message(mContact.getJID(), Message.MSG_TYPE_CHAT);
- msg.setBody(text);
- try {
- // TODO: PAs connecter au serveur BING grosse Error ! INTERDICTION !
- mChat.sendMessage(msg);
- if (mSpeak != 1)
- mText.append(getString(R.string.SendIMYouSay) + text + '\n');
- else
- mText.append(text + "\n");
- mToSend.setText(null);
- mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
- mToSend.requestFocus();
- mSpeak = 1;
- } catch (RemoteException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
-
- /**
- * Set the header information in the window.
- */
- private void setViewHeader() {
- Drawable avatar = getResources().getDrawable(R.drawable.avatar);
- ImageView imgV = (ImageView) findViewById(R.id.sendimavatar);
- imgV.setImageDrawable(avatar);
- mLogin = (TextView) findViewById(R.id.sendimlogin);
- mLogin.setText(mContact.getJID());
- TextView status = (TextView) findViewById(R.id.sendimstatus);
- status.setTextSize(12);
- mLogin.setTextColor(getResources().getColor(R.color.white));
- String statmsg = mContact.getMsgState();
- if (statmsg != null)
- status.setText(statmsg);
- }
-
- /**
- * Show the message history.
- * @param messages list of message to display
- */
- private void showMessageList(List<Message> messages) {
- mText.setText("");
- mSpeak = 0;
- for (Message message : messages) {
- String from = message.getFrom();
- if (from == null) {
- if (mSpeak != 1)
- mText.append(getString(R.string.SendIMYouSay));
- mSpeak = 1;
- } else {
- if (mSpeak != 2) {
- String str = String.format(getString(R.string.SendIMSays), from);
- mText.append(str);
- }
- mSpeak = 2;
- }
- mText.append(message.getBody() + '\n');
- }
- mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
- }
-
- /**
- * Change the correspondant of the chat.
- * @param newContact New contact to chat with
- * @throws RemoteException if an errors occurs in the connection with the service
- */
- private void switchChat(Contact newContact) throws RemoteException {
- if (mChat != null)
- mChat.setOpen(false);
- mChat = mChatManager.createChat(newContact, mMessageListener);
- showMessageList(mChat.getMessages());
- mChat.setOpen(true);
- mContact = newContact;
- mToSend.requestFocus();
- }
-
- /**
- * Listener for chat creation. (maybe not necessary)
- * @author darisk
- */
- private class OnChatListener extends IChatManagerListener.Stub {
/**
* {@inheritDoc}
*/
@Override
- public void chatCreated(IChat chat, boolean locally) throws RemoteException {
- Log.i("LOG", "chatCreated");
+ public void onClick(View view) {
+ sendText();
}
- }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void onCreate(Bundle saveBundle) {
+ super.onCreate(saveBundle);
+ mHandler = new Handler();
+ mChatManagerListener = new OnChatListener();
+ mMessageListener = new OnMessageListener();
+ setContentView(R.layout.sendim);
+ mToSend = (EditText) findViewById(R.id.userText);
+ mSet = getSharedPreferences("lol", MODE_PRIVATE);
+ mSmyDialog = new SendIMDialogSmiley(this, mSet);
+ mToSend.setOnClickListener(this);
+ mToSend.setOnKeyListener(this);
+ mLogin = (TextView) findViewById(R.id.sendimlogin);
+ mContact = new Contact(getIntent().getData());
+ mText = (TextView) findViewById(R.id.sendimlist);
+ mScrolling = (ScrollView) findViewById(R.id.sendimscroll);
+ mStatusText = (TextView) findViewById(R.id.sendimstatus);
+ setViewHeader();
+ }
- /**
- * Listener for new chat messages.
- * @author darisk
- */
- private class OnMessageListener extends IMessageListener.Stub {
+ /**
+ * Set the header information in the window.
+ */
+ private void setViewHeader() {
+ Drawable avatar = getResources().getDrawable(R.drawable.avatar);
+ ImageView imgV = (ImageView) findViewById(R.id.sendimavatar);
+ imgV.setImageDrawable(avatar);
+ mStatusText.setTextSize(12);
+ mLogin.setText(mContact.getJID());
+ mLogin.setTextColor(getResources().getColor(R.color.white));
+ }
/**
* {@inheritDoc}
*/
@Override
- public void processMessage(IChat chat, Message msg) throws RemoteException {
+ public final boolean onCreateOptionsMenu(Menu menu) {
+ super.onCreateOptionsMenu(menu);
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.sendimmenu, menu);
+ return true;
+ }
- if (chat != mChat)
- return;
- final Message m = msg;
- mHandler.post(new Runnable() {
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ if (mChatManager != null) {
+ try {
+ mChatManager.removeChatCreationListener(mChatManagerListener);
+ // TODO trouver quand detruire le chat
+ // mChatManager.destroyChat(mChat);
+ } catch (RemoteException e) {
+ Log.e(TAG, "mchat manager and SendIM destroy", e);
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean onKey(View v, int keyCode, KeyEvent event) {
+ if (event.getAction() == KeyEvent.ACTION_DOWN) {
+ switch (keyCode) {
+ case KeyEvent.KEYCODE_DPAD_CENTER:
+ case KeyEvent.KEYCODE_ENTER:
+ sendText();
+ return true;
+ default:
+ return false;
+ }
+ }
+ return false;
+ }
- @Override
- public void run() {
- if (m.getBody() != null) {
- if (mSpeak == 2)
- mText.append(m.getBody() + "\n");
- else {
- String str = String.format(getString(R.string.SendIMSays), m.getFrom());
- mText.append(str);
- mText.append(m.getBody() + "\n");
- }
- mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
- mToSend.requestFocus();
- mSpeak = 2;
- }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void onNewIntent(Intent intent) {
+ super.onNewIntent(intent);
+ mContact = new Contact(intent.getData());
+ setViewHeader();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public final boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.sendim_smiley:
+ mSmyDialog.show();
+ return true;
+ default:
+ return false;
}
- });
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void onPause() {
+ super.onPause();
+ try {
+ mChat.setOpen(false);
+ } catch (RemoteException e) {
+ Log.d(TAG, "Error while closing chat", e);
+ }
+ unbindService(mServConn);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void onResume() {
+ super.onResume();
+ bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
+ mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
}
/**
* {@inheritDoc}
*/
@Override
- public void stateChanged(IChat chat) throws RemoteException {
- // TODO: a integrer dans l'ui
- // Log.d(TAG, "state changed");
+ protected void onStart() {
+ super.onStart();
+ // TODO cancel the notification if any
+ if (mContact == null)
+ mContact = getIntent().getParcelableExtra("contact");
+ setViewHeader();
+
+ }
+
+ private class BeemServiceConnection implements ServiceConnection {
+
+ @Override
+ public void onServiceConnected(ComponentName name, IBinder service) {
+ xmppFacade = IXmppFacade.Stub.asInterface(service);
+ try {
+ if (mChatManager == null) {
+ mChatManager = xmppFacade.getChatManager();
+ mChatManager.addChatCreationListener(mChatManagerListener);
+ }
+ switchChat(mContact);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Error during chat manager creation", e);
+ }
+ try {
+ mRoster = xmppFacade.getRoster();
+ if (mRoster != null) {
+ mRoster.addRosterListener(new BeemRosterListener());
+ mContact.setStatus(mRoster.getPresence(mContact.getJID()));
+ mStatusText.setText(mContact.getMsgState());
+ Linkify.addLinks(mStatusText, Linkify.WEB_URLS);
+ }
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName name) {
+ xmppFacade = null;
+ }
+ }
+
+ /**
+ * Send a message to the contact over the XMPP connection. Also display it on activity view. TODO : Gerer
+ * l'exception si la connexion se coupe pendant la conversation
+ */
+ private void sendText() {
+ String text = mToSend.getText().toString();
+ if (!text.equals("")) {
+ Message msg = new Message(mContact.getJID(), Message.MSG_TYPE_CHAT);
+ msg.setBody(text);
+ try {
+ // TODO: PAs connecter au serveur BING grosse Error ! INTERDICTION !
+ mChat.sendMessage(msg);
+ if (mSpeak != 1)
+ mText.append(getString(R.string.SendIMYouSay) + text + '\n');
+ else
+ mText.append(text + "\n");
+ mToSend.setText(null);
+ mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
+ mToSend.requestFocus();
+ mSpeak = 1;
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * Show the message history.
+ * @param messages list of message to display
+ */
+ private void showMessageList(List<Message> messages) {
+ mText.setText("");
+ mSpeak = 0;
+ for (Message message : messages) {
+ String from = message.getFrom();
+ if (from == null) {
+ if (mSpeak != 1)
+ mText.append(getString(R.string.SendIMYouSay));
+ mSpeak = 1;
+ } else {
+ if (mSpeak != 2) {
+ String str = String.format(getString(R.string.SendIMSays), from);
+ mText.append(str);
+ }
+ mSpeak = 2;
+ }
+ mText.append(message.getBody() + '\n');
+ }
+ mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
}
- }
+
+ /**
+ * Change the correspondant of the chat.
+ * @param newContact New contact to chat with
+ * @throws RemoteException if an errors occurs in the connection with the service
+ */
+ private void switchChat(Contact newContact) throws RemoteException {
+ if (mChat != null)
+ mChat.setOpen(false);
+ mChat = mChatManager.createChat(newContact, mMessageListener);
+ showMessageList(mChat.getMessages());
+ mChat.setOpen(true);
+ mContact = newContact;
+ mToSend.requestFocus();
+ }
+
+ /**
+ * Listener for chat creation. (maybe not necessary)
+ * @author darisk
+ */
+ private class OnChatListener extends IChatManagerListener.Stub {
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void chatCreated(IChat chat, boolean locally) throws RemoteException {
+ Log.i("LOG", "chatCreated");
+ }
+
+ }
+ private class BeemRosterListener extends IBeemRosterListener.Stub {
+
+ @Override
+ public void onEntriesAdded(List<String> addresses)
+ throws RemoteException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void onEntriesDeleted(List<String> addresses)
+ throws RemoteException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void onEntriesUpdated(List<String> addresses)
+ throws RemoteException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void onPresenceChanged(PresenceAdapter presence)
+ throws RemoteException {
+ if (mContact.getJID().equals(StringUtils.parseBareAddress(presence.getFrom()))) {
+ mContact.setStatus(mRoster.getPresence(StringUtils.parseBareAddress(presence.getFrom())));
+ mHandler.post(new RunnableChange());
+ }
+ }
+
+ private class RunnableChange implements Runnable {
+ @Override
+ public void run() {
+ mStatusText.setText(mContact.getMsgState());
+ Linkify.addLinks(mStatusText, Linkify.WEB_URLS);
+ }
+ }
+
+ }
+
+ /**
+ * Listener for new chat messages.
+ * @author darisk
+ */
+ private class OnMessageListener extends IMessageListener.Stub {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void processMessage(IChat chat, Message msg) throws RemoteException {
+
+ if (chat != mChat)
+ return;
+ final Message m = msg;
+ mHandler.post(new Runnable() {
+
+ @Override
+ public void run() {
+ if (m.getBody() != null) {
+ if (mSpeak == 2)
+ mText.append(m.getBody() + "\n");
+ else {
+ String str = String.format(getString(R.string.SendIMSays), m.getFrom());
+ mText.append(str);
+ mText.append(m.getBody() + "\n");
+ }
+ mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
+ mToSend.requestFocus();
+ mSpeak = 2;
+ }
+ }
+ });
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void stateChanged(IChat chat) throws RemoteException {
+ // TODO: a integrer dans l'ui
+ // Log.d(TAG, "state changed");
+ }
+ }
}
--- a/src/com/beem/project/beem/ui/Subscription.java Mon Jun 22 15:38:20 2009 +0200
+++ b/src/com/beem/project/beem/ui/Subscription.java Mon Jun 22 15:48:56 2009 +0200
@@ -6,13 +6,17 @@
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Presence.Type;
-import com.beem.project.beem.BeemApplication;
+import com.beem.project.beem.BeemService;
import com.beem.project.beem.R;
import com.beem.project.beem.service.PresenceAdapter;
import com.beem.project.beem.service.aidl.IXmppFacade;
import android.app.Activity;
+import android.content.ComponentName;
+import android.content.Intent;
+import android.content.ServiceConnection;
import android.os.Bundle;
+import android.os.IBinder;
import android.os.RemoteException;
import android.view.View;
import android.view.View.OnClickListener;
@@ -25,53 +29,72 @@
*/
public class Subscription extends Activity {
- private IXmppFacade mService;
- private String mContact;
+ public static final String TAG = "Subscription";
+ private IXmppFacade mService;
+ private String mContact;
+ private ServiceConnection mServConn = new BeemServiceConnection();
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.subscription);
- findViewById(R.id.SubscriptionAccept).setOnClickListener(mClickListener);
- findViewById(R.id.SubscriptionRefuse).setOnClickListener(mClickListener);
- mContact = getIntent().getStringExtra("from");
- TextView tv = (TextView) findViewById(R.id.SubscriptionText);
- String str = String.format(getString(R.string.SubscriptText), mContact);
- tv.setText(str);
- mService = BeemApplication.getApplication(this).getXmppFacade();
- }
-
- private OnClickListener mClickListener = new OnClickListener() {
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.subscription);
+ bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
+ findViewById(R.id.SubscriptionAccept).setOnClickListener(mClickListener);
+ findViewById(R.id.SubscriptionRefuse).setOnClickListener(mClickListener);
+ mContact = getIntent().getStringExtra("from");
+ TextView tv = (TextView) findViewById(R.id.SubscriptionText);
+ String str = String.format(getString(R.string.SubscriptText), mContact);
+ tv.setText(str);
+ }
@Override
- public void onClick(View v) {
- switch (v.getId()) {
- case R.id.SubscriptionAccept:
- Presence presence = new Presence(Type.subscribed);
- presence.setTo(mContact);
- PresenceAdapter preAdapt = new PresenceAdapter(presence);
- try {
- mService.sendPresencePacket(preAdapt);
- Toast.makeText(Subscription.this, getString(R.string.SubscriptAccept),
- Toast.LENGTH_SHORT).show();
- finish();
- } catch (RemoteException e) {
- Toast.makeText(Subscription.this, getString(R.string.SubscriptError),
- Toast.LENGTH_SHORT).show();
- e.printStackTrace();
- }
- break ;
- case R.id.SubscriptionRefuse:
- Toast.makeText(Subscription.this, getString(R.string.SubscriptRefused),
- Toast.LENGTH_SHORT).show();
-
- break ;
- default:
- Toast.makeText(Subscription.this, getString(R.string.SubscriptError),
- Toast.LENGTH_SHORT).show();
- };
-
+ protected void onDestroy() {
+ super.onDestroy();
+ unbindService(mServConn);
}
- };
+ private OnClickListener mClickListener = new OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ switch (v.getId()) {
+ case R.id.SubscriptionAccept:
+ Presence presence = new Presence(Type.subscribed);
+ presence.setTo(mContact);
+ PresenceAdapter preAdapt = new PresenceAdapter(presence);
+ try {
+ mService.sendPresencePacket(preAdapt);
+ Toast.makeText(Subscription.this, getString(R.string.SubscriptAccept),
+ Toast.LENGTH_SHORT).show();
+ finish();
+ } catch (RemoteException e) {
+ Toast.makeText(Subscription.this, getString(R.string.SubscriptError),
+ Toast.LENGTH_SHORT).show();
+ e.printStackTrace();
+ }
+ break ;
+ case R.id.SubscriptionRefuse:
+ Toast.makeText(Subscription.this, getString(R.string.SubscriptRefused),
+ Toast.LENGTH_SHORT).show();
+
+ break ;
+ default:
+ Toast.makeText(Subscription.this, getString(R.string.SubscriptError),
+ Toast.LENGTH_SHORT).show();
+ };
+ }
+ };
+
+ private class BeemServiceConnection implements ServiceConnection {
+
+ @Override
+ public void onServiceConnected(ComponentName name, IBinder service) {
+ mService = IXmppFacade.Stub.asInterface(service);
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName name) {
+ mService = null;
+ }
+ }
}