# HG changeset patch # User marseille@marseille-desktop # Date 1245262451 -7200 # Node ID 66ea747448ea8d5b131b554f676ffd3a726faeeb # Parent 23647e075321b9532b5e8198a1b47706e9e03cd8 Suppression de la beemapplication dans contactlist. diff -r 23647e075321 -r 66ea747448ea src/com/beem/project/beem/service/RosterAdapter.java --- a/src/com/beem/project/beem/service/RosterAdapter.java Wed Jun 17 19:03:11 2009 +0200 +++ b/src/com/beem/project/beem/service/RosterAdapter.java Wed Jun 17 20:14:11 2009 +0200 @@ -181,7 +181,7 @@ * {@inheritDoc} */ @Override - public void addConnectionListener(IBeemRosterListener listen) throws RemoteException { + public void addRosterListener(IBeemRosterListener listen) throws RemoteException { if (listen != null) mRemoteRosListeners.register(listen); } @@ -257,7 +257,7 @@ * {@inheritDoc} */ @Override - public void removeConnectionListener(IBeemRosterListener listen) throws RemoteException { + public void removeRosterListener(IBeemRosterListener listen) throws RemoteException { if (listen != null) mRemoteRosListeners.unregister(listen); } diff -r 23647e075321 -r 66ea747448ea src/com/beem/project/beem/service/aidl/IRoster.aidl --- a/src/com/beem/project/beem/service/aidl/IRoster.aidl Wed Jun 17 19:03:11 2009 +0200 +++ b/src/com/beem/project/beem/service/aidl/IRoster.aidl Wed Jun 17 20:14:11 2009 +0200 @@ -18,7 +18,7 @@ List getGroupsNames(); - void addConnectionListener(in IBeemRosterListener listen); - void removeConnectionListener(in IBeemRosterListener listen); + void addRosterListener(in IBeemRosterListener listen); + void removeRosterListener(in IBeemRosterListener listen); } \ No newline at end of file diff -r 23647e075321 -r 66ea747448ea src/com/beem/project/beem/ui/ContactList.java --- a/src/com/beem/project/beem/ui/ContactList.java Wed Jun 17 19:03:11 2009 +0200 +++ b/src/com/beem/project/beem/ui/ContactList.java Wed Jun 17 20:14:11 2009 +0200 @@ -8,11 +8,14 @@ import org.jivesoftware.smack.util.StringUtils; import android.app.ExpandableListActivity; +import android.content.ComponentName; import android.content.Intent; +import android.content.ServiceConnection; import android.database.DataSetObserver; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.Handler; +import android.os.IBinder; import android.os.RemoteException; import android.util.Log; import android.view.LayoutInflater; @@ -27,7 +30,7 @@ import android.widget.ImageView; import android.widget.TextView; -import com.beem.project.beem.BeemApplication; +import com.beem.project.beem.BeemService; import com.beem.project.beem.R; import com.beem.project.beem.service.Contact; import com.beem.project.beem.service.PresenceAdapter; @@ -40,15 +43,14 @@ private static final String TAG = "CONTACTLIST_ACT"; private static final String DEFAULT_GROUP = "Default"; - private IXmppFacade mService = null; private MyExpandableListAdapter mAdapter; - private BeemApplication mBeemApplication; - private BeemRosterListener mRosterListener; private IRoster mRoster; private Map> groupMap; private List groupName; private List mListContact; private Handler mHandler; + private IXmppFacade xmppFacade = null; + private final ServiceConnection mServConn = new BeemServiceConnection(); /** * Callback for menu creation. @@ -85,41 +87,10 @@ @Override protected void onCreate(Bundle saveBundle) { super.onCreate(saveBundle); + bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE); mHandler = new Handler(); - mRosterListener = new BeemRosterListener(); - mBeemApplication = BeemApplication.getApplication(this); groupMap = new HashMap>(); - groupName = new ArrayList(); - mBeemApplication.callWhenConnectedToServer(mHandler, new Runnable() { - - @Override - public void run() { - mService = mBeemApplication.getXmppFacade(); - try { - mRoster = mService.getRoster(); - } catch (RemoteException e1) { - Log.e(TAG, "Get roster failed", e1); - } - if (mRoster != null) { - try { - mRoster.addConnectionListener(mRosterListener); - } catch (RemoteException e) { - e.printStackTrace(); - } - } - callbackShowContactList(); - } - }); - } - - private void callbackShowContactList() { - if (mRoster != null) { - try { - buildContactList(mRoster.getContactList()); - } catch (RemoteException e) { - e.printStackTrace(); - } - } + groupName = new ArrayList(); } private void buildContactList(List listContact) { @@ -462,4 +433,25 @@ observers.remove(observer); } } + + private class BeemServiceConnection implements ServiceConnection { + + @Override + public void onServiceConnected(ComponentName name, IBinder service) { + xmppFacade = IXmppFacade.Stub.asInterface(service); + try { + mRoster = xmppFacade.getRoster(); + mRoster.addRosterListener(new BeemRosterListener()); + buildContactList(mRoster.getContactList()); + } catch (RemoteException e) { + e.printStackTrace(); + } + } + + @Override + public void onServiceDisconnected(ComponentName name) { + xmppFacade = null; + mRoster = null; + } + } }