diff -r 5db64229be69 -r d8e2cb1eb895 src/com/beem/project/beem/service/Contact.java --- a/src/com/beem/project/beem/service/Contact.java Thu May 28 15:01:49 2009 +0200 +++ b/src/com/beem/project/beem/service/Contact.java Fri May 29 20:34:30 2009 +0200 @@ -9,7 +9,9 @@ import org.jivesoftware.smack.RosterGroup; import org.jivesoftware.smack.packet.Presence; +import org.jivesoftware.smack.util.StringUtils; +import android.net.Uri; import android.os.Parcel; import android.os.Parcelable; @@ -22,17 +24,6 @@ */ public class Contact implements Parcelable { - @SuppressWarnings("unused") - private static final String TAG = "Contact"; - - private int mID; - private int mStatus; - private String mJID; - private String mName; - private String mMsgState; - private List mRes; - private List mGroups; - /** * Parcelable.Creator needs by Android. */ @@ -49,11 +40,18 @@ } }; + private int mID; + private int mStatus; + private String mJID; + private String mMsgState; + private List mRes; + private List mGroups; + private String mName; + /** * Constructor. */ public Contact() { - // TODO Auto-generated constructor stub } /** @@ -89,12 +87,35 @@ mGroups = new ArrayList(); } + /** + * Create a contact from a Uri. + * + * @param uri + * an uri for the contact + * @throws IllegalArgumentException + * if it is not a xmpp uri + */ + public Contact(Uri uri) { + if (!uri.getScheme().equals("xmpp")) + throw new IllegalArgumentException(); + mJID = uri.getSchemeSpecificPart(); + } + + /** + * Add a group for the contact. + * + * @param group + * the group + */ public void addGroup(String group) { mGroups.add(group); } /** + * Add a resource for this contact. + * * @param res + * the resource to add */ public void addRes(String res) { if (!mRes.contains(res)) @@ -102,7 +123,10 @@ } /** + * Delete a resource for this contact. + * * @param res + * the resource de delete */ public void delRes(String res) { mRes.remove(res); @@ -118,6 +142,8 @@ } /** + * Get the groups the contact is in. + * * @return the mGroups */ public List getGroups() { @@ -143,6 +169,8 @@ } /** + * Get the list of resource for the contact. + * * @return the mRes */ public List getMRes() { @@ -174,13 +202,22 @@ return mStatus; } + /** + * Set the groups the contact is in. + * + * @param groups + * list of groups + */ public void setGroups(Collection groups) { + this.mGroups.clear(); for (RosterGroup rosterGroup : groups) { mGroups.add(rosterGroup.getName()); } } /** + * Set the groups the contact is in. + * * @param mGroups * the mGroups to set */ @@ -201,14 +238,16 @@ /** * Set the Jabber ID of the contact. * - * @param mjid + * @param jid * the jabber ID to set */ - public void setJID(String mjid) { - mJID = mjid; + public void setJID(String jid) { + mJID = jid; } /** + * Set a list of resource for the contact. + * * @param mRes * the mRes to set */ @@ -256,12 +295,21 @@ mMsgState = presence.getStatus(); } + /** + * Set status for the contact. + * + * @param presence + * The presence packet which contains the status + */ public void setStatus(PresenceAdapter presence) { mStatus = presence.getStatus(); mMsgState = presence.getStatusText(); } + /** + * {@inheritDoc} + */ @Override public String toString() { if (mJID != null) @@ -270,6 +318,18 @@ } /** + * Get a URI to access the contact. + * + * @return the URI + */ + public Uri toUri() { + StringBuilder build = new StringBuilder("xmpp:"); + build.append(StringUtils.parseName(mJID)).append('@').append(StringUtils.parseServer(mJID)); + Uri u = Uri.parse(build.toString()); + return u; + } + + /** * {@inheritDoc} */ @Override @@ -282,4 +342,5 @@ dest.writeStringList(getMRes()); dest.writeStringList(getGroups()); } + }