# HG changeset patch # User nikita@nikita-rack # Date 1237823682 -3600 # Node ID 4145f456d73be52526545f08e5d64ca726c94119 # Parent d97efe278ca18ecf8d1d252eeeb712e1b426fb54# Parent e612d4a075adff4cd4bdfa0e97a1ebd4aacf089c merge diff -r e612d4a075ad -r 4145f456d73b .classpath --- a/.classpath Sat Mar 14 22:19:51 2009 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ - - - - - - - - - - - diff -r e612d4a075ad -r 4145f456d73b .hgignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Mon Mar 23 16:54:42 2009 +0100 @@ -0,0 +1,2 @@ +bin/* +R.java diff -r e612d4a075ad -r 4145f456d73b .project --- a/.project Sat Mar 14 22:19:51 2009 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +0,0 @@ - - - smack - - - - - - com.android.ide.eclipse.adt.ResourceManagerBuilder - - - - - com.android.ide.eclipse.adt.PreCompilerBuilder - - - - - org.eclipse.jdt.core.javabuilder - - - - - com.android.ide.eclipse.adt.ApkBuilder - - - - - - com.android.ide.eclipse.adt.AndroidNature - org.eclipse.jdt.core.javanature - - diff -r e612d4a075ad -r 4145f456d73b AndroidManifest.xml --- a/AndroidManifest.xml Sat Mar 14 22:19:51 2009 +0100 +++ b/AndroidManifest.xml Mon Mar 23 16:54:42 2009 +0100 @@ -1,15 +1,26 @@ - - - - - - - - + package="com.beem.project.beem" android:versionCode="1" + android:versionName="1.0"> + + + + + + + + + + + + + + + + + + diff -r e612d4a075ad -r 4145f456d73b Beem-ecipse-formatter.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Beem-ecipse-formatter.xml Mon Mar 23 16:54:42 2009 +0100 @@ -0,0 +1,267 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r e612d4a075ad -r 4145f456d73b checkstyle.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/checkstyle.xml Mon Mar 23 16:54:42 2009 +0100 @@ -0,0 +1,225 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r e612d4a075ad -r 4145f456d73b libs/new-android-r1.diff --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libs/new-android-r1.diff Mon Mar 23 16:54:42 2009 +0100 @@ -0,0 +1,436 @@ +Index: source/org/jivesoftware/smack/XMPPConnection.java +=================================================================== +--- source/org/jivesoftware/smack/XMPPConnection.java (révision 10982) ++++ source/org/jivesoftware/smack/XMPPConnection.java (copie de travail) +@@ -1082,7 +1082,7 @@ + catch (Exception ex) { + try { + debuggerClass = +- Class.forName("org.jivesoftware.smack.debugger.LiteDebugger"); ++ Class.forName("org.jivesoftware.smack.debugger.ConsoleDebugger"); + } + catch (Exception ex2) { + ex2.printStackTrace(); +Index: source/org/jivesoftware/smack/sasl/SASLMechanism.java +=================================================================== +--- source/org/jivesoftware/smack/sasl/SASLMechanism.java (révision 10982) ++++ source/org/jivesoftware/smack/sasl/SASLMechanism.java (copie de travail) +@@ -20,24 +20,18 @@ + + package org.jivesoftware.smack.sasl; + +-import org.jivesoftware.smack.XMPPException; +-import org.jivesoftware.smack.SASLAuthentication; +-import org.jivesoftware.smack.util.Base64; +- + import java.io.IOException; +-import java.util.Map; + import java.util.HashMap; ++import java.util.Map; ++ ++import javax.security.auth.callback.Callback; + import javax.security.auth.callback.CallbackHandler; + import javax.security.auth.callback.UnsupportedCallbackException; +-import javax.security.auth.callback.Callback; +-import javax.security.auth.callback.NameCallback; +-import javax.security.auth.callback.PasswordCallback; +-import javax.security.sasl.RealmCallback; +-import javax.security.sasl.RealmChoiceCallback; +-import javax.security.sasl.Sasl; +-import javax.security.sasl.SaslClient; +-import javax.security.sasl.SaslException; + ++import org.jivesoftware.smack.SASLAuthentication; ++import org.jivesoftware.smack.XMPPException; ++import org.jivesoftware.smack.util.Base64; ++ + /** + * Base class for SASL mechanisms. Subclasses must implement these methods: + *
    +@@ -56,7 +50,7 @@ + public abstract class SASLMechanism implements CallbackHandler { + + private SASLAuthentication saslAuthentication; +- protected SaslClient sc; ++ //protected SaslClient sc; + protected String authenticationId; + protected String password; + protected String hostname; +@@ -88,7 +82,7 @@ + + String[] mechanisms = { getName() }; + Map props = new HashMap(); +- sc = Sasl.createSaslClient(mechanisms, username, "xmpp", host, props, this); ++ //sc = Sasl.createSaslClient(mechanisms, username, "xmpp", host, props, this); + authenticate(); + } + +@@ -105,7 +99,7 @@ + public void authenticate(String username, String host, CallbackHandler cbh) throws IOException, XMPPException { + String[] mechanisms = { getName() }; + Map props = new HashMap(); +- sc = Sasl.createSaslClient(mechanisms, username, "xmpp", host, props, cbh); ++ //sc = Sasl.createSaslClient(mechanisms, username, "xmpp", host, props, cbh); + authenticate(); + } + +@@ -113,17 +107,17 @@ + StringBuilder stanza = new StringBuilder(); + stanza.append(""); +- try { +- if(sc.hasInitialResponse()) { +- byte[] response = sc.evaluateChallenge(new byte[0]); +- String authenticationText = Base64.encodeBytes(response,Base64.DONT_BREAK_LINES); +- if(authenticationText != null && !authenticationText.equals("")) { +- stanza.append(authenticationText); +- } +- } +- } catch (SaslException e) { +- throw new XMPPException("SASL authentication failed", e); +- } ++// try { ++// if(sc.hasInitialResponse()) { ++// byte[] response = sc.evaluateChallenge(new byte[0]); ++// String authenticationText = Base64.encodeBytes(response,Base64.DONT_BREAK_LINES); ++// if(authenticationText != null && !authenticationText.equals("")) { ++// stanza.append(authenticationText); ++// } ++// } ++// } catch (SaslException e) { ++// throw new XMPPException("SASL authentication failed", e); ++// } + stanza.append(""); + + // Send the authentication to the server +@@ -142,12 +136,12 @@ + // Build the challenge response stanza encoding the response text + StringBuilder stanza = new StringBuilder(); + +- byte response[]; +- if(challenge != null) { +- response = sc.evaluateChallenge(Base64.decode(challenge)); +- } else { +- response = sc.evaluateChallenge(null); +- } ++ byte response[] = null; ++// if(challenge != null) { ++// response = sc.evaluateChallenge(Base64.decode(challenge)); ++// } else { ++// response = sc.evaluateChallenge(null); ++// } + + String authenticationText = Base64.encodeBytes(response,Base64.DONT_BREAK_LINES); + if(authenticationText.equals("")) { +@@ -179,21 +173,21 @@ + */ + public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { + for (int i = 0; i < callbacks.length; i++) { +- if (callbacks[i] instanceof NameCallback) { +- NameCallback ncb = (NameCallback)callbacks[i]; +- ncb.setName(authenticationId); +- } else if(callbacks[i] instanceof PasswordCallback) { +- PasswordCallback pcb = (PasswordCallback)callbacks[i]; +- pcb.setPassword(password.toCharArray()); +- } else if(callbacks[i] instanceof RealmCallback) { +- RealmCallback rcb = (RealmCallback)callbacks[i]; +- rcb.setText(hostname); +- } else if(callbacks[i] instanceof RealmChoiceCallback){ +- //unused +- //RealmChoiceCallback rccb = (RealmChoiceCallback)callbacks[i]; +- } else { ++// if (callbacks[i] instanceof NameCallback) { ++// NameCallback ncb = (NameCallback)callbacks[i]; ++// ncb.setName(authenticationId); ++// } else if(callbacks[i] instanceof PasswordCallback) { ++// PasswordCallback pcb = (PasswordCallback)callbacks[i]; ++// pcb.setPassword(password.toCharArray()); ++// } else if(callbacks[i] instanceof RealmCallback) { ++// RealmCallback rcb = (RealmCallback)callbacks[i]; ++// rcb.setText(hostname); ++// } else if(callbacks[i] instanceof RealmChoiceCallback){ ++// //unused ++// //RealmChoiceCallback rccb = (RealmChoiceCallback)callbacks[i]; ++// } else { + throw new UnsupportedCallbackException(callbacks[i]); +- } ++ //} + } + } + } +Index: source/org/jivesoftware/smack/sasl/SASLGSSAPIMechanism.java +=================================================================== +--- source/org/jivesoftware/smack/sasl/SASLGSSAPIMechanism.java (révision 10982) ++++ source/org/jivesoftware/smack/sasl/SASLGSSAPIMechanism.java (copie de travail) +@@ -25,8 +25,6 @@ + import java.io.IOException; + import java.util.Map; + import java.util.HashMap; +-import javax.security.sasl.Sasl; +-import javax.security.sasl.SaslClient; + import javax.security.auth.callback.CallbackHandler; + + /** +@@ -62,8 +60,8 @@ + public void authenticate(String username, String host, CallbackHandler cbh) throws IOException, XMPPException { + String[] mechanisms = { getName() }; + Map props = new HashMap(); +- props.put(Sasl.SERVER_AUTH,"TRUE"); +- sc = Sasl.createSaslClient(mechanisms, username, "xmpp", host, props, cbh); ++ //props.put(Sasl.SERVER_AUTH,"TRUE"); ++ //sc = Sasl.createSaslClient(mechanisms, username, "xmpp", host, props, cbh); + authenticate(); + } + +@@ -81,8 +79,8 @@ + public void authenticate(String username, String host, String password) throws IOException, XMPPException { + String[] mechanisms = { getName() }; + Map props = new HashMap(); +- props.put(Sasl.SERVER_AUTH,"TRUE"); +- sc = Sasl.createSaslClient(mechanisms, username, "xmpp", host, props, this); ++ //props.put(Sasl.SERVER_AUTH,"TRUE"); ++ //sc = Sasl.createSaslClient(mechanisms, username, "xmpp", host, props, this); + authenticate(); + } + +Index: source/org/jivesoftware/smack/ConnectionConfiguration.java +=================================================================== +--- source/org/jivesoftware/smack/ConnectionConfiguration.java (révision 10982) ++++ source/org/jivesoftware/smack/ConnectionConfiguration.java (copie de travail) +@@ -57,13 +57,13 @@ + + private boolean compressionEnabled = false; + +- private boolean saslAuthenticationEnabled = true; ++ private boolean saslAuthenticationEnabled = false; + /** + * Used to get information from the user + */ + private CallbackHandler callbackHandler; + +- private boolean debuggerEnabled = XMPPConnection.DEBUG_ENABLED; ++ private boolean debuggerEnabled = true;//XMPPConnection.DEBUG_ENABLED; + + // Flag that indicates if a reconnection should be attempted when abruptly disconnected + private boolean reconnectionAllowed = true; +@@ -517,7 +517,7 @@ + * logging into the server. + */ + public void setSASLAuthenticationEnabled(boolean saslAuthenticationEnabled) { +- this.saslAuthenticationEnabled = saslAuthenticationEnabled; ++ //this.saslAuthenticationEnabled = saslAuthenticationEnabled; + } + + /** +Index: source/org/jivesoftware/smack/util/DNSUtil.java +=================================================================== +--- source/org/jivesoftware/smack/util/DNSUtil.java (révision 10982) ++++ source/org/jivesoftware/smack/util/DNSUtil.java (copie de travail) +@@ -24,9 +24,6 @@ + + import javax.naming.NamingEnumeration; + import javax.naming.directory.Attribute; +-import javax.naming.directory.Attributes; +-import javax.naming.directory.DirContext; +-import javax.naming.directory.InitialDirContext; + + /** + * Utilty class to perform DNS lookups for XMPP services. +@@ -41,13 +38,13 @@ + */ + private static Map cache = new Cache(100, 1000*60*10); + +- private static DirContext context; ++// private static DirContext context; + + static { + try { + Hashtable env = new Hashtable(); + env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory"); +- context = new InitialDirContext(env); ++ // context = new InitialDirContext(env); + } + catch (Exception e) { + // Ignore. +@@ -79,64 +76,7 @@ + * server can be reached at for the specified domain. + */ + public static HostAddress resolveXMPPDomain(String domain) { +- if (context == null) { + return new HostAddress(domain, 5222); +- } +- String key = "c" + domain; +- // Return item from cache if it exists. +- if (cache.containsKey(key)) { +- HostAddress address = (HostAddress)cache.get(key); +- if (address != null) { +- return address; +- } +- } +- String bestHost = domain; +- int bestPort = 5222; +- int bestPriority = 0; +- int bestWeight = 0; +- try { +- Attributes dnsLookup = context.getAttributes("_xmpp-client._tcp." + domain, new String[]{"SRV"}); +- Attribute srvAttribute = dnsLookup.get("SRV"); +- NamingEnumeration srvRecords = srvAttribute.getAll(); +- while(srvRecords.hasMore()) { +- String srvRecord = (String) srvRecords.next(); +- String [] srvRecordEntries = srvRecord.split(" "); +- int priority = Integer.parseInt(srvRecordEntries[srvRecordEntries.length - 4]); +- int port = Integer.parseInt(srvRecordEntries[srvRecordEntries.length-2]); +- int weight = Integer.parseInt(srvRecordEntries[srvRecordEntries.length - 3]); +- String host = srvRecordEntries[srvRecordEntries.length-1]; +- +- // Randomize the weight. +- weight *= Math.random() * weight; +- +- if ((bestPriority == 0) || (priority < bestPriority)) { +- // Choose a server with the lowest priority. +- bestPriority = priority; +- bestWeight = weight; +- bestHost = host; +- bestPort = port; +- } else if (priority == bestPriority) { +- // When we have like priorities then randomly choose a server based on its weight +- // The weights were randomized above. +- if (weight > bestWeight) { +- bestWeight = weight; +- bestHost = host; +- bestPort = port; +- } +- } +- } +- } +- catch (Exception e) { +- // Ignore. +- } +- // Host entries in DNS should end with a ".". +- if (bestHost.endsWith(".")) { +- bestHost = bestHost.substring(0, bestHost.length()-1); +- } +- HostAddress address = new HostAddress(bestHost, bestPort); +- // Add item to cache. +- cache.put(key, address); +- return address; + } + + /** +@@ -157,49 +97,7 @@ + * server can be reached at for the specified domain. + */ + public static HostAddress resolveXMPPServerDomain(String domain) { +- if (context == null) { + return new HostAddress(domain, 5269); +- } +- String key = "s" + domain; +- // Return item from cache if it exists. +- if (cache.containsKey(key)) { +- HostAddress address = (HostAddress)cache.get(key); +- if (address != null) { +- return address; +- } +- } +- String host = domain; +- int port = 5269; +- try { +- Attributes dnsLookup = +- context.getAttributes("_xmpp-server._tcp." + domain, new String[]{"SRV"}); +- String srvRecord = (String)dnsLookup.get("SRV").get(); +- String [] srvRecordEntries = srvRecord.split(" "); +- port = Integer.parseInt(srvRecordEntries[srvRecordEntries.length-2]); +- host = srvRecordEntries[srvRecordEntries.length-1]; +- } +- catch (Exception e) { +- // Attempt lookup with older "jabber" name. +- try { +- Attributes dnsLookup = +- context.getAttributes("_jabber._tcp." + domain, new String[]{"SRV"}); +- String srvRecord = (String)dnsLookup.get("SRV").get(); +- String [] srvRecordEntries = srvRecord.split(" "); +- port = Integer.parseInt(srvRecordEntries[srvRecordEntries.length-2]); +- host = srvRecordEntries[srvRecordEntries.length-1]; +- } +- catch (Exception e2) { +- // Ignore. +- } +- } +- // Host entries in DNS should end with a ".". +- if (host.endsWith(".")) { +- host = host.substring(0, host.length()-1); +- } +- HostAddress address = new HostAddress(host, port); +- // Add item to cache. +- cache.put(key, address); +- return address; + } + + /** +@@ -253,4 +151,4 @@ + return port == address.port; + } + } +-} +\ No newline at end of file ++} +Index: source/org/jivesoftware/smack/util/PacketParserUtils.java +=================================================================== +--- source/org/jivesoftware/smack/util/PacketParserUtils.java (révision 10982) ++++ source/org/jivesoftware/smack/util/PacketParserUtils.java (copie de travail) +@@ -25,7 +25,7 @@ + import org.jivesoftware.smack.provider.ProviderManager; + import org.xmlpull.v1.XmlPullParser; + +-import java.beans.PropertyDescriptor; ++//import java.beans.PropertyDescriptor; + import java.io.ByteArrayInputStream; + import java.io.ObjectInputStream; + import java.util.ArrayList; +@@ -428,26 +428,26 @@ + { + boolean done = false; + Object object = objectClass.newInstance(); +- while (!done) { +- int eventType = parser.next(); +- if (eventType == XmlPullParser.START_TAG) { +- String name = parser.getName(); +- String stringValue = parser.nextText(); +- PropertyDescriptor descriptor = new PropertyDescriptor(name, objectClass); +- // Load the class type of the property. +- Class propertyType = descriptor.getPropertyType(); +- // Get the value of the property by converting it from a +- // String to the correct object type. +- Object value = decode(propertyType, stringValue); +- // Set the value of the bean. +- descriptor.getWriteMethod().invoke(object, value); +- } +- else if (eventType == XmlPullParser.END_TAG) { +- if (parser.getName().equals(elementName)) { +- done = true; +- } +- } +- } ++// while (!done) { ++// int eventType = parser.next(); ++// if (eventType == XmlPullParser.START_TAG) { ++// String name = parser.getName(); ++// String stringValue = parser.nextText(); ++// PropertyDescriptor descriptor = new PropertyDescriptor(name, objectClass); ++// // Load the class type of the property. ++// Class propertyType = descriptor.getPropertyType(); ++// // Get the value of the property by converting it from a ++// // String to the correct object type. ++// Object value = decode(propertyType, stringValue); ++// // Set the value of the bean. ++// descriptor.getWriteMethod().invoke(object, value); ++// } ++// else if (eventType == XmlPullParser.END_TAG) { ++// if (parser.getName().equals(elementName)) { ++// done = true; ++// } ++// } ++// } + return object; + } + diff -r e612d4a075ad -r 4145f456d73b libs/smack.jar Binary file libs/smack.jar has changed diff -r e612d4a075ad -r 4145f456d73b libs/smackx-debug.jar Binary file libs/smackx-debug.jar has changed diff -r e612d4a075ad -r 4145f456d73b libs/smackx-jingle.jar Binary file libs/smackx-jingle.jar has changed diff -r e612d4a075ad -r 4145f456d73b libs/smackx.jar Binary file libs/smackx.jar has changed diff -r e612d4a075ad -r 4145f456d73b res/drawable/avatar.png Binary file res/drawable/avatar.png has changed diff -r e612d4a075ad -r 4145f456d73b res/drawable/bart.jpg Binary file res/drawable/bart.jpg has changed diff -r e612d4a075ad -r 4145f456d73b res/drawable/logo.jpg Binary file res/drawable/logo.jpg has changed diff -r e612d4a075ad -r 4145f456d73b res/layout/beem.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/res/layout/beem.xml Mon Mar 23 16:54:42 2009 +0100 @@ -0,0 +1,35 @@ + + + + + + + + + + + \ No newline at end of file diff -r e612d4a075ad -r 4145f456d73b res/layout/contactlist.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/res/layout/contactlist.xml Mon Mar 23 16:54:42 2009 +0100 @@ -0,0 +1,19 @@ + + + + + + + + diff -r e612d4a075ad -r 4145f456d73b res/layout/contactlistgroup.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/res/layout/contactlistgroup.xml Mon Mar 23 16:54:42 2009 +0100 @@ -0,0 +1,16 @@ + + + + + + diff -r e612d4a075ad -r 4145f456d73b res/layout/main.xml --- a/res/layout/main.xml Sat Mar 14 22:19:51 2009 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ - - - - - diff -r e612d4a075ad -r 4145f456d73b res/menu/beemmenu.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/res/menu/beemmenu.xml Mon Mar 23 16:54:42 2009 +0100 @@ -0,0 +1,4 @@ + + + + diff -r e612d4a075ad -r 4145f456d73b res/values/strings.xml --- a/res/values/strings.xml Sat Mar 14 22:19:51 2009 +0100 +++ b/res/values/strings.xml Mon Mar 23 16:54:42 2009 +0100 @@ -1,4 +1,20 @@ - Beem + Beem + + + Creer un compte + Jabber ID + + + Use the Beem Service + BeemService Created + BeemService destroyed + + + Beem + login + host + password + port diff -r e612d4a075ad -r 4145f456d73b src/com/beem/project/beem/Beem.java --- a/src/com/beem/project/beem/Beem.java Sat Mar 14 22:19:51 2009 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -package com.beem.project.beem; - -import android.app.Activity; -import android.os.Bundle; - -public class Beem extends Activity { - - /** Called when the activity is first created. - * @param savedInstanceState toto - */ - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.main); - } -} diff -r e612d4a075ad -r 4145f456d73b src/com/beem/project/beem/BeemException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/BeemException.java Mon Mar 23 16:54:42 2009 +0100 @@ -0,0 +1,67 @@ +/** + * + */ +package com.beem.project.beem; + +import android.os.Parcel; +import android.os.Parcelable; + +/** + * @author darisk + * + */ +public class BeemException extends Exception implements Parcelable { + + public static final Parcelable.Creator CREATOR = new Creator() { + + @Override + public BeemException[] newArray(int size) { + // TODO Auto-generated method stub + return new BeemException[size]; + } + + @Override + public BeemException createFromParcel(Parcel source) { + // TODO Auto-generated method stub + return new BeemException(source); + } + }; + + public BeemException() { + super(); + // TODO Auto-generated constructor stub + } + + public BeemException(String detailMessage, Throwable throwable) { + super(detailMessage, throwable); + // TODO Auto-generated constructor stub + } + + public BeemException(String detailMessage) { + super(detailMessage); + // TODO Auto-generated constructor stub + } + + public BeemException(Throwable throwable) { + super(throwable); + // TODO Auto-generated constructor stub + } + + private BeemException(Parcel parcel){ + this(parcel.readString()); + } + + @Override + public int describeContents() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + // TODO Auto-generated method stub + dest.writeString(getLocalizedMessage()); + } + + +} diff -r e612d4a075ad -r 4145f456d73b src/com/beem/project/beem/BeemService.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/BeemService.java Mon Mar 23 16:54:42 2009 +0100 @@ -0,0 +1,134 @@ +/** + * + */ +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; +import android.app.Service; +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.aidl.IXMPPConnection; +import com.beem.project.beem.service.aidl.IXMPPFacade; +/** + * @author darisk + * + */ +public class BeemService extends Service { + + private NotificationManager notificationManager; + + private IXMPPConnection connection; + private SharedPreferences settings; + private String mLogin; + private String mPassword; + private String mHost; + + private IXMPPFacade.Stub bind = new IXMPPFacade.Stub() { + + @Override + public IXMPPConnection getXMPPConnection() throws RemoteException { + return connection; + } + + @Override + public void disconnect() throws RemoteException { + connection.disconnect(); + } + + + @Override + public void connectAsync() throws RemoteException { + connection.connectAsync(mLogin, mPassword, "BEEM"); + } + + + @Override + public void connectSync() throws RemoteException { + connection.connectSync(mLogin, mPassword, "BEEM"); + } + }; + + /* + * (non-Javadoc) + * + * @see android.app.Service#onBind(android.content.Intent) + */ + @Override + public IBinder onBind(Intent intent) { + showBasicNotification(R.string.BeemServiceCreated); + return bind; + // to forbid a client to bind + // return null; + } + + @Override + public void onCreate() { + super.onCreate(); + settings = getSharedPreferences(getString(R.string.PreferenceFileName), + MODE_PRIVATE); + mLogin = settings.getString(getString(R.string.PreferenceLoginKey), ""); + mPassword = settings.getString( + getString(R.string.PreferencePasswordKey), ""); + mHost = settings.getString(getString(R.string.PreferenceHostKey), ""); + notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + connection = new XMPPConnectionAdapter("10.0.2.2"); // address + } + + private void showBasicNotification(int stringResource) { + String text = (String) getText(stringResource); + Notification notif = new Notification(R.drawable.logo, text, System + .currentTimeMillis()); + notif.defaults = Notification.DEFAULT_ALL; + notif.setLatestEventInfo(this, text, text, PendingIntent.getActivity( + this, 0, new Intent(), 0)); + notificationManager.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(mLogin, mPassword, "BEEM"); + } catch (RemoteException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Override + public void onDestroy() { + closeConnection(); + showBasicNotification(R.string.BeemServiceDestroyed); + } + + private void closeConnection() { + if (connection != null) + try { + connection.disconnect(); + } catch (RemoteException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + +} diff -r e612d4a075ad -r 4145f456d73b src/com/beem/project/beem/service/RosterAdapter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/RosterAdapter.java Mon Mar 23 16:54:42 2009 +0100 @@ -0,0 +1,61 @@ +/** + * + */ +package com.beem.project.beem.service; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.jivesoftware.smack.Roster; +import org.jivesoftware.smack.RosterEntry; +import org.jivesoftware.smack.XMPPException; + +import android.os.RemoteException; + +import com.beem.project.beem.service.aidl.IRosterEntry; +import com.beem.project.beem.service.aidl.IRoster.Stub; + +/** + * @author darisk + * + */ +public class RosterAdapter extends com.beem.project.beem.service.aidl.IRoster.Stub { + + private Roster adaptee; + + public RosterAdapter(Roster roster) { + adaptee = roster; + } + + @Override + public IRosterEntry createEntry(String user, String name, String[] groups) + throws RemoteException { + try { + adaptee.createEntry(user, name, groups); + } catch (XMPPException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } + + @Override + public void createGroup(String groupname) throws RemoteException { + // TODO Auto-generated method stub + adaptee.createGroup(groupname); + } + + @Override + public List getEntries() throws RemoteException { + // TODO Auto-generated method stub + Collection col = adaptee.getEntries(); + ArrayList result = new ArrayList(col.size()); + for (RosterEntry rosterEntry : col ) { + result.add(new RosterEntryAdapter(rosterEntry)); + } + return result; + } + + +} diff -r e612d4a075ad -r 4145f456d73b src/com/beem/project/beem/service/RosterEntryAdapter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/RosterEntryAdapter.java Mon Mar 23 16:54:42 2009 +0100 @@ -0,0 +1,42 @@ +/** + * + */ +package com.beem.project.beem.service; + +import org.jivesoftware.smack.RosterEntry; +import org.jivesoftware.smack.XMPPConnection; +import org.jivesoftware.smack.packet.RosterPacket.ItemStatus; +import org.jivesoftware.smack.packet.RosterPacket.ItemType; + +import android.os.IBinder; +import android.os.RemoteException; + +import com.beem.project.beem.service.aidl.IRosterEntry; + +/** + * @author darisk + * + */ +public class RosterEntryAdapter extends IRosterEntry.Stub { + + private RosterEntry adaptee; + + public RosterEntryAdapter(RosterEntry entry) { + adaptee = entry; + } + + @Override + public String getName() throws RemoteException { + return adaptee.getName(); + } + + @Override + public String getUser() throws RemoteException { + return adaptee.getUser(); + } + + @Override + public void setName(String name) throws RemoteException { + adaptee.setName(name); + } +} diff -r e612d4a075ad -r 4145f456d73b src/com/beem/project/beem/service/XMPPConnectionAdapter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/XMPPConnectionAdapter.java Mon Mar 23 16:54:42 2009 +0100 @@ -0,0 +1,263 @@ +/** + * + */ +package com.beem.project.beem.service; + +import org.jivesoftware.smack.ConnectionConfiguration; +import org.jivesoftware.smack.ConnectionListener; +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 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; + +/** + * @author darisk + * + */ +public class XMPPConnectionAdapter extends IXMPPConnection.Stub { + + private XMPPConnection adaptee; + private BeemException lastException; + + private RemoteCallbackList mRemoteConnListeners = new RemoteCallbackList(); + private ConnexionListenerAdapter mConListener = new ConnexionListenerAdapter(); + + public XMPPConnectionAdapter(XMPPConnection con) { + adaptee = con; + + } + + public XMPPConnectionAdapter(String serviceName) { + this(new XMPPConnection(serviceName)); + } + + public XMPPConnectionAdapter(ConnectionConfiguration config) { + this(new XMPPConnection(config)); + } + + @Override + public boolean connectSync(String username, String password, String resource) + throws RemoteException { + try { + adaptee.connect(); + this.initFeatures(); // pour declarer les features xmpp qu'on supporte + adaptee.addConnectionListener(mConListener); + adaptee.login(username, password, resource); + lastException = null; + triggerAsynchronousConnectEvent(); + return true; + } catch (XMPPException e) { + lastException = new BeemException(e); + } + return false; + } + + public boolean disconnect() { + adaptee.disconnect(); + lastException = null; + return true; + } + + @Override + public IRoster getRoster() throws RemoteException { + return new RosterAdapter(adaptee.getRoster()); + } + + @Override + public void connectAsync(final String username, final String password, final String resource) + throws RemoteException { + Thread t = new Thread(new Runnable() { + + @Override + public void run() { + try { + connectSync(username,password,resource); + } catch (RemoteException e) { + + } + } + }); + t.start(); + } + + @Override + public void addConnectionListener(IBeemConnectionListener listen) + throws RemoteException { + if (listen != null) + mRemoteConnListeners.register(listen); + } + + @Override + public void removeConnectionListener(IBeemConnectionListener listen) + throws RemoteException { + if (listen != null) + mRemoteConnListeners.unregister(listen); + } + + private void triggerAsynchronousConnectEvent() { + mConListener.onConnect(); + } + + private class ConnexionListenerAdapter implements ConnectionListener { + + 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. + } + } + mRemoteConnListeners.finishBroadcast(); + } + + @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. + } + } + mRemoteConnListeners.finishBroadcast(); + } + + @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. + } + } + mRemoteConnListeners.finishBroadcast(); + } + + @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(); + } + + @Override + public void reconnectionFailed(Exception arg0) { + final int N = mRemoteConnListeners.beginBroadcast(); + + for (int i = 0; i < N; i++) { + IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i); + try { + listener.reconnectionFailed(); + } catch (RemoteException e) { + // The RemoteCallbackList will take care of removing the + // dead listeners. + } + } + mRemoteConnListeners.finishBroadcast(); + } + + @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. + } + } + mRemoteConnListeners.finishBroadcast(); + } + + } + /** + * @brief: enregistre les featues 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(adaptee); + sdm.addFeature("http://jabber.org/protocol/disco#info"); + //sdm.addFeature("http://jabber.org/protocol/nick"); + + } + + +} diff -r e612d4a075ad -r 4145f456d73b src/com/beem/project/beem/service/aidl/IBeemConnectionListener.aidl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/aidl/IBeemConnectionListener.aidl Mon Mar 23 16:54:42 2009 +0100 @@ -0,0 +1,17 @@ +package com.beem.project.beem.service.aidl; + +interface IBeemConnectionListener { + + void connectionClosed(); + + void onConnect(); + + //void connectionClosedOnError(in Exception e); + void connectionClosedOnError(); + + void reconnectingIn(in int seconds); + + void reconnectionFailed(); + + void reconnectionSuccessful(); +} diff -r e612d4a075ad -r 4145f456d73b src/com/beem/project/beem/service/aidl/IRoster.aidl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/aidl/IRoster.aidl Mon Mar 23 16:54:42 2009 +0100 @@ -0,0 +1,14 @@ +package com.beem.project.beem.service.aidl; + +import com.beem.project.beem.service.aidl.IRosterEntry; + +interface IRoster { + + IRosterEntry createEntry(in String user, in String name, in String[] groups); + + void createGroup(in String groupname); + + // List + List getEntries(); + +} \ No newline at end of file diff -r e612d4a075ad -r 4145f456d73b src/com/beem/project/beem/service/aidl/IRosterEntry.aidl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/aidl/IRosterEntry.aidl Mon Mar 23 16:54:42 2009 +0100 @@ -0,0 +1,12 @@ +package com.beem.project.beem.service.aidl; + +interface IRosterEntry { + + String getName(); + String getUser(); + void setName(in String name); + //TODO + // getStatus() + // getType + +} \ No newline at end of file diff -r e612d4a075ad -r 4145f456d73b src/com/beem/project/beem/service/aidl/IXMPPConnection.aidl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/aidl/IXMPPConnection.aidl Mon Mar 23 16:54:42 2009 +0100 @@ -0,0 +1,20 @@ +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(in String username, in String password, in String resource); + + void connectAsync(in String username, in String password, in String resource); + + boolean disconnect(); + + // void login(String username, String password, String resource); + + IRoster getRoster(); + + void addConnectionListener(in IBeemConnectionListener listen); + void removeConnectionListener(in IBeemConnectionListener listen); +} \ No newline at end of file diff -r e612d4a075ad -r 4145f456d73b src/com/beem/project/beem/service/aidl/IXMPPFacade.aidl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/aidl/IXMPPFacade.aidl Mon Mar 23 16:54:42 2009 +0100 @@ -0,0 +1,15 @@ +package com.beem.project.beem.service.aidl; + +import com.beem.project.beem.service.aidl.IXMPPConnection; + +interface IXMPPFacade { + + IXMPPConnection getXMPPConnection(); + + void connectSync(); + + void connectAsync(); + + void disconnect(); + +} diff -r e612d4a075ad -r 4145f456d73b src/com/beem/project/beem/ui/Beem.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/ui/Beem.java Mon Mar 23 16:54:42 2009 +0100 @@ -0,0 +1,109 @@ +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 com.beem.project.beem.R; + +/** + * La principale activite to be continuous. + */ +public class Beem extends Activity { + + private SharedPreferences mSettings; + private BeemDialogSettings mDialog; + private Button mButton; + private Handler mHandler; + + /** + * Default constructor. + */ + public Beem() { + super(); + mHandler= new Handler(); + } + + /** + * Called when the activity is first created. + * @param savedInstanceState + * previous state. + */ + @Override + public final void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.beem); + mSettings = getSharedPreferences( + getString(R.string.PreferenceFileName), MODE_PRIVATE); + mDialog = new BeemDialogSettings(this, mSettings); + + mButton = (Button) findViewById(R.id.connection); + mButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + if (mButton.getText() == getString(R.string.BeemCreateAccount)) + mDialog.show(); + else + startActivity(new Intent(Beem.this, ContactList.class)); + } + }); + showJID(); + } + + /** + * Callback for menu creation. + * @param menu + * the menu created + * @return true on success, false otherwise + */ + @Override + public final boolean onCreateOptionsMenu(Menu menu) { + super.onCreateOptionsMenu(menu); + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.beemmenu, menu); + return true; + } + + /** + * Callback for menu item selected. + * @param item + * the item selected + * @return true on success, false otherwise + */ + @Override + public final boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.account_edit: + mDialog.show(); + return true; + case R.id.account_about: + return true; + default: + return false; + } + } + + /** + * Show jabber id in button. + */ + public final void showJID() { + String jid = mSettings.getString( + getString(R.string.PreferenceLoginKey), "") + + "@" + + mSettings + .getString(getString(R.string.PreferenceHostKey), ""); + if (jid.length() == 1) + jid = getString(R.string.BeemCreateAccount); + mButton.setText(jid); + } + + +} diff -r e612d4a075ad -r 4145f456d73b src/com/beem/project/beem/ui/BeemDialogSettings.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/ui/BeemDialogSettings.java Mon Mar 23 16:54:42 2009 +0100 @@ -0,0 +1,76 @@ +package com.beem.project.beem.ui; + +import android.app.Dialog; +import android.content.Context; +import android.content.SharedPreferences; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; + +import com.beem.project.beem.R; + +/** + * + */ +public class BeemDialogSettings extends Dialog implements + android.view.View.OnClickListener { + + private Beem mbeem; + + private SharedPreferences mSettings; + + public BeemDialogSettings(Beem beem, SharedPreferences settings) { + super(beem); + this.mbeem = beem; + this.mSettings = settings; + } + + @Override + protected void onStart() { + super.onStart(); + setContentView(R.layout.beemdialogsettings); + getWindow().setFlags(4, 4); + setTitle("Jabber Account Settings"); + showSettings(); + Button ok = (Button) findViewById(R.id.ok); + ok.setOnClickListener(this); + } + + @Override + public void onClick(View v) { + SharedPreferences.Editor editor = mSettings.edit(); + Context ctx = getContext(); + editor.putString(ctx.getString(R.string.PreferenceHostKey), + getWidgetText(R.id.host)); + editor.putString(ctx.getString(R.string.PreferencePortKey), + getWidgetText(R.id.port)); + editor.putString(ctx.getString(R.string.PreferenceLoginKey), + getWidgetText(R.id.userid)); + editor.putString(ctx.getString(R.string.PreferencePasswordKey), + getWidgetText(R.id.password)); + editor.commit(); + this.mbeem.showJID(); + dismiss(); + } + + private void showSettings() { + String tmp; + EditText eHost = (EditText) findViewById(R.id.host); + if ((tmp = mSettings.getString("host", "")) != "") + eHost.setText(tmp); + EditText ePort = (EditText) findViewById(R.id.port); + if ((tmp = mSettings.getString("port", "")) != "") + ePort.setText(tmp); + EditText eLogin = (EditText) findViewById(R.id.userid); + if ((tmp = mSettings.getString("login", "")) != "") + eLogin.setText(tmp); + EditText ePwd = (EditText) findViewById(R.id.password); + if ((tmp = mSettings.getString("password", "")) != "") + ePwd.setText(tmp); + } + + private String getWidgetText(int id) { + EditText widget = (EditText) this.findViewById(id); + return widget.getText().toString(); + } +} diff -r e612d4a075ad -r 4145f456d73b src/com/beem/project/beem/ui/ContactList.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/ui/ContactList.java Mon Mar 23 16:54:42 2009 +0100 @@ -0,0 +1,134 @@ +package com.beem.project.beem.ui; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import android.app.ExpandableListActivity; +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.util.Log; +import android.widget.ExpandableListAdapter; +import android.widget.SimpleExpandableListAdapter; + +import com.beem.project.beem.BeemService; +import com.beem.project.beem.R; +import com.beem.project.beem.service.aidl.IBeemConnectionListener; +import com.beem.project.beem.service.aidl.IXMPPConnection; +import com.beem.project.beem.service.aidl.IXMPPFacade; + +public class ContactList extends ExpandableListActivity { + + private IXMPPFacade mService = null; + + @Override + public void onCreate(Bundle saveBundle) { + super.onCreate(saveBundle); + bindService(new Intent(this, BeemService.class), mConnection, + BIND_AUTO_CREATE | BIND_DEBUG_UNBIND); + } + + private void showContactList() { + ExpandableListAdapter Adapter; + List> groupData = new ArrayList>(); + List>> childData = new ArrayList>>(); + + for (int i = 0; i < 2; i++) { + Map curGroupMap = new HashMap(); + groupData.add(curGroupMap); + curGroupMap.put("NAME", "Group " + i); + + List> children = new ArrayList>(); + for (int j = 0; j < 5; j++) { + Map curChildMap = new HashMap(); + children.add(curChildMap); + curChildMap.put("NAOME CHILD", "Child " + j); + } + childData.add(children); + } + + Adapter = new SimpleExpandableListAdapter(this, + groupData, R.layout.contactlistgroup, + new String[] {"NAME"}, new int[] {R.id.textgroup}, + childData, R.layout.contactlist, + new String[] {"NAME CHILD"}, new int[] {R.id.textchild}); + setListAdapter(Adapter); + } + + private ServiceConnection mConnection = new ServiceConnection() { + @Override + public void onServiceConnected(ComponentName name, IBinder service) { + mService = IXMPPFacade.Stub.asInterface(service); + try { + IXMPPConnection con = mService.getXMPPConnection(); + con.addConnectionListener(new TestConnectionListener()); + mService.connectSync(); + Log.i("BEEM", "Connected !!!"); + } catch (RemoteException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + /* + * mService.getGroupList(); mService.getContactList(); + */ + } + + @Override + public void onServiceDisconnected(ComponentName name) { + } + + }; + + @Override + public void onDestroy() { + super.onDestroy(); + unbindService(mConnection); + } + + private class TestConnectionListener extends IBeemConnectionListener.Stub { + + @Override + public void connectionClosed() throws RemoteException { + // TODO Auto-generated method stub + + } + + @Override + public void connectionClosedOnError() throws RemoteException { + // TODO Auto-generated method stub + + } + + @Override + public void onConnect() throws RemoteException { + // TODO Auto-generated method stub + showContactList(); + } + + @Override + public void reconnectingIn(int seconds) throws RemoteException { + // TODO Auto-generated method stub + + } + + @Override + public void reconnectionFailed() throws RemoteException { + // TODO Auto-generated method stub + + } + + @Override + public void reconnectionSuccessful() throws RemoteException { + // TODO Auto-generated method stub + + } + + } + +}