# HG changeset patch # User Da Risk # Date 1298170003 -3600 # Node ID 0ceee1f2b82973bf563d25062ad30ae323ef1700 # Parent d23d8ad3b9ba1ee6c261250113210b229db99c49 Show current avatar in ChangeStatus. diff -r d23d8ad3b9ba -r 0ceee1f2b829 src/com/beem/project/beem/BeemService.java --- a/src/com/beem/project/beem/BeemService.java Sun Feb 20 03:16:35 2011 +0100 +++ b/src/com/beem/project/beem/BeemService.java Sun Feb 20 03:46:43 2011 +0100 @@ -219,7 +219,7 @@ configure(ProviderManager.getInstance()); mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); - mConnection = new XmppConnectionAdapter(mConnectionConfiguration, mLogin, mPassword, this); + mConnection = new XmppConnectionAdapter(mConnectionConfiguration, tmpJid, mLogin, mPassword, this); Roster.setDefaultSubscriptionMode(SubscriptionMode.manual); mBind = new XmppFacade(mConnection); diff -r d23d8ad3b9ba -r 0ceee1f2b829 src/com/beem/project/beem/service/UserInfo.aidl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/UserInfo.aidl Sun Feb 20 03:46:43 2011 +0100 @@ -0,0 +1,46 @@ +/* + BEEM is a videoconference application on the Android Platform. + + Copyright (C) 2009 by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + This file is part of BEEM. + + BEEM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + BEEM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with BEEM. If not, see . + + Please send bug reports with examples or suggestions to + contact@beem-project.com or http://dev.beem-project.com/ + + Epitech, hereby disclaims all copyright interest in the program "Beem" + written by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + Nicolas Sadirac, November 26, 2009 + President of Epitech. + + Flavien Astraud, November 26, 2009 + Head of the EIP Laboratory. + +*/ +package com.beem.project.beem.service; + +parcelable UserInfo; diff -r d23d8ad3b9ba -r 0ceee1f2b829 src/com/beem/project/beem/service/UserInfo.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/UserInfo.java Sun Feb 20 03:46:43 2011 +0100 @@ -0,0 +1,71 @@ + +package com.beem.project.beem.service; + +import android.os.Parcel; +import android.os.Parcelable; +import org.jivesoftware.smack.util.StringUtils; + +/** + * This class contains information about the user of the connection. + * These informations are sent by the connection. + * + */ +public class UserInfo implements Parcelable { + + /** Parcelable.Creator needs by Android. */ + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + + @Override + public UserInfo createFromParcel(Parcel source) { + return new UserInfo(source); + } + + @Override + public UserInfo[] newArray(int size) { + return new UserInfo[size]; + } + }; + + private final String mBareJid; + private String mAvatarId; + + /** + * Construct a UserInfo from a parcel. + * @param in parcel to use for construction + */ + private UserInfo(final Parcel in) { + mBareJid= in.readString(); + mAvatarId = in.readString(); + } + + /** + * Constructor. + * @param jid jid of the user + */ + public UserInfo(final String jid) { + mBareJid = StringUtils.parseBareAddress(jid); + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeString(mBareJid); + dest.writeString(mAvatarId); + } + + @Override + public int describeContents() { + return 0; + } + + public String getAvatarId() { + return mAvatarId; + } + + public void setAvatarId(String avatarId) { + mAvatarId = avatarId; + } + + public String getJid() { + return mBareJid; + } +} diff -r d23d8ad3b9ba -r 0ceee1f2b829 src/com/beem/project/beem/service/XmppConnectionAdapter.java --- a/src/com/beem/project/beem/service/XmppConnectionAdapter.java Sun Feb 20 03:16:35 2011 +0100 +++ b/src/com/beem/project/beem/service/XmppConnectionAdapter.java Sun Feb 20 03:46:43 2011 +0100 @@ -67,6 +67,7 @@ import android.util.Log; import java.util.Iterator; +import java.util.List; import com.beem.project.beem.BeemService; import com.beem.project.beem.R; @@ -81,6 +82,8 @@ import com.beem.project.beem.utils.Status; import com.beem.project.beem.smack.pep.PepSubManager; import com.beem.project.beem.smack.avatar.AvatarCache; +import com.beem.project.beem.smack.avatar.AvatarListener; +import com.beem.project.beem.smack.avatar.AvatarMetadataExtension; /** * This class implements an adapter for XMPPConnection. @@ -118,6 +121,9 @@ private final ConnexionListenerAdapter mConListener = new ConnexionListenerAdapter(); + private UserInfo mUserInfo; + private final UserInfoManager mUserInfoManager = new UserInfoManager(); + /** * Constructor. * @param config Configuration to use in order to connect @@ -125,38 +131,41 @@ * @param password password to use on connect * @param service the background service associated with the connection. */ - public XmppConnectionAdapter(final ConnectionConfiguration config, final String login, final String password, - final BeemService service) { - this(new XMPPConnection(config), login, password, service); + public XmppConnectionAdapter(final ConnectionConfiguration config, final String jid, + final String login, final String password, final BeemService service) { + this(new XMPPConnection(config), jid, login, password, service); } /** * Constructor. * @param serviceName name of the service to connect to + * @param jid the jid of the user * @param login login to use on connect * @param password password to use on connect * @param service the background service associated with the connection. */ - public XmppConnectionAdapter(final String serviceName, final String login, final String password, - final BeemService service) { - this(new XMPPConnection(serviceName), login, password, service); + public XmppConnectionAdapter(final String serviceName, final String jid, + final String login, final String password, final BeemService service) { + this(new XMPPConnection(serviceName), jid, login, password, service); } /** * Constructor. * @param con The connection to adapt + * @param jid the jid of the user * @param login The login to use * @param password The password to use * @param service the background service associated with the connection. */ - public XmppConnectionAdapter(final XMPPConnection con, final String login, final String password, - final BeemService service) { + public XmppConnectionAdapter(final XMPPConnection con, final String jid, + final String login, final String password, final BeemService service) { mAdaptee = con; PrivacyListManager.getInstanceFor(mAdaptee); mLogin = login; mPassword = password; mService = service; Context ctx = mService.getApplicationContext(); + mUserInfo = new UserInfo(jid); if (ctx instanceof BeemApplication) { mApplication = (BeemApplication) ctx; } @@ -405,6 +414,9 @@ return mRoster; } + public UserInfo getUserInfo() { + return mUserInfo; + } /** * Returns true if currently authenticated by successfully calling the login method. @@ -502,6 +514,7 @@ mPepManager = new PepSubManager(mAdaptee); AvatarCache avatarCache = new BeemAvatarCache(mService); mAvatarManager = new BeemAvatarManager(mService, mAdaptee, mPepManager, avatarCache, true); + mAvatarManager.addAvatarListener(mUserInfoManager); } /** @@ -702,4 +715,17 @@ } } + private class UserInfoManager implements AvatarListener { + + public UserInfoManager() { + } + + public void onAvatarChange(String from, String avatarId, List avatarInfos){ + String jid = mUserInfo.getJid(); + if (jid.equals(from)) { + mUserInfo.setAvatarId(avatarId); + } + } + } + } diff -r d23d8ad3b9ba -r 0ceee1f2b829 src/com/beem/project/beem/service/XmppFacade.java --- a/src/com/beem/project/beem/service/XmppFacade.java Sun Feb 20 03:16:35 2011 +0100 +++ b/src/com/beem/project/beem/service/XmppFacade.java Sun Feb 20 03:46:43 2011 +0100 @@ -164,4 +164,9 @@ if (mgr != null) mgr.disableAvatarPublishing(); } + + @Override + public UserInfo getUserInfo() throws RemoteException { + return mConnexion.getUserInfo(); + } } diff -r d23d8ad3b9ba -r 0ceee1f2b829 src/com/beem/project/beem/service/aidl/IXmppFacade.aidl --- a/src/com/beem/project/beem/service/aidl/IXmppFacade.aidl Sun Feb 20 03:16:35 2011 +0100 +++ b/src/com/beem/project/beem/service/aidl/IXmppFacade.aidl Sun Feb 20 03:46:43 2011 +0100 @@ -43,11 +43,13 @@ */ package com.beem.project.beem.service.aidl; -import com.beem.project.beem.service.aidl.IXmppConnection; -import com.beem.project.beem.service.aidl.IRoster; -import com.beem.project.beem.service.aidl.IChatManager; -import com.beem.project.beem.service.aidl.IPrivacyListManager; +import com.beem.project.beem.service.aidl.IXmppConnection; +import com.beem.project.beem.service.aidl.IRoster; +import com.beem.project.beem.service.aidl.IChatManager; +import com.beem.project.beem.service.aidl.IPrivacyListManager; import com.beem.project.beem.service.PresenceAdapter; +import com.beem.project.beem.service.UserInfo; + import android.net.Uri; interface IXmppFacade { @@ -101,6 +103,7 @@ void disableAvatarPublishing(); + UserInfo getUserInfo(); IPrivacyListManager getPrivacyListManager(); } diff -r d23d8ad3b9ba -r 0ceee1f2b829 src/com/beem/project/beem/ui/ChangeStatus.java --- a/src/com/beem/project/beem/ui/ChangeStatus.java Sun Feb 20 03:16:35 2011 +0100 +++ b/src/com/beem/project/beem/ui/ChangeStatus.java Sun Feb 20 03:46:43 2011 +0100 @@ -70,6 +70,8 @@ import com.beem.project.beem.BeemApplication; import com.beem.project.beem.R; import com.beem.project.beem.service.aidl.IXmppFacade; +import com.beem.project.beem.service.UserInfo; +import com.beem.project.beem.providers.AvatarProvider; import com.beem.project.beem.utils.BeemBroadcastReceiver; import com.beem.project.beem.utils.BeemConnectivity; import com.beem.project.beem.utils.Status; @@ -109,6 +111,7 @@ private final ServiceConnection mServConn = new BeemServiceConnection(); private final OnClickListener mOnClickOk = new MyOnClickListener(); private final BeemBroadcastReceiver mReceiver = new BeemBroadcastReceiver(); + private boolean mShowCurrentAvatar = true; /** * Constructor. @@ -258,7 +261,18 @@ } catch (RemoteException e) { Log.e(TAG, "Error while publishing avatar", e); } + } + private void displayCurrentAvatar() { + try { + UserInfo ui = mXmppFacade.getUserInfo(); + String avatarId = ui.getAvatarId(); + Uri uri = AvatarProvider.CONTENT_URI.buildUpon().appendPath(avatarId).build(); + mAvatar.setImageURI(uri); + } catch (RemoteException e) { + Log.e(TAG, "Error while displaying current avatar", e); + } + mShowCurrentAvatar = false; } /** @@ -279,6 +293,8 @@ @Override public void onServiceConnected(ComponentName name, IBinder service) { mXmppFacade = IXmppFacade.Stub.asInterface(service); + if (mShowCurrentAvatar) + displayCurrentAvatar(); } /**