# HG changeset patch # User marseille@marseille-desktop # Date 1245349376 -7200 # Node ID a81519fc402420df3d3fb70ecab62c4ea7ce6af5 # Parent f879726d62955823de09958c1e7b901c86ac8f5d Suppression du Beemapplication dans ContactDialog diff -r f879726d6295 -r a81519fc4024 src/com/beem/project/beem/ui/ContactDialog.java --- a/src/com/beem/project/beem/ui/ContactDialog.java Thu Jun 18 11:53:00 2009 +0200 +++ b/src/com/beem/project/beem/ui/ContactDialog.java Thu Jun 18 20:22:56 2009 +0200 @@ -4,14 +4,18 @@ import android.app.Activity; import android.app.Dialog; +import android.app.Service; +import android.content.ComponentName; import android.content.Context; import android.content.Intent; +import android.content.ServiceConnection; +import android.os.IBinder; import android.os.RemoteException; import android.util.Log; import android.view.View; import android.widget.Button; -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; @@ -19,6 +23,34 @@ public class ContactDialog extends Dialog { + public static final String TAG = "Option Dialog"; + private final Contact mContact; + private final Context mContext; + private IXmppFacade xmppFacade = null; + private final ServiceConnection mServConn = new BeemServiceConnection(); + + public ContactDialog(final Context context, Contact curContact) { + super(context); + mContext = context; + + setContentView(R.layout.contactdialog); + mContact = curContact; + setTitle(curContact.getJID()); + + Button button = (Button) findViewById(R.id.CDChat); + button.setOnClickListener(new chatListener()); + button = (Button) findViewById(R.id.CDAlias); + button.setOnClickListener(new aliasListener()); + button = (Button) findViewById(R.id.CDGroup); + button.setOnClickListener(new groupListener()); + button = (Button) findViewById(R.id.CDResend); + 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); + } + class aliasListener implements View.OnClickListener { @Override @@ -72,7 +104,7 @@ Presence presencePacket = new Presence(Presence.Type.subscribe); presencePacket.setTo(mContact.getJID()); try { - mService.sendPresencePacket(new PresenceAdapter(presencePacket)); + xmppFacade.sendPresencePacket(new PresenceAdapter(presencePacket)); } catch (RemoteException e) { Log.e(TAG, "resend subscription error", e); } @@ -81,36 +113,17 @@ } - public static final String TAG = "Option Dialog"; - - private final Contact mContact; - - private final Context mContext; - - private IXmppFacade mService; - - public ContactDialog(final Context context, Contact curContact) { - super(context); - mContext = context; + private class BeemServiceConnection implements ServiceConnection { - setContentView(R.layout.contactdialog); - mContact = curContact; - setTitle(curContact.getJID()); + @Override + public void onServiceConnected(ComponentName name, IBinder service) { + xmppFacade = IXmppFacade.Stub.asInterface(service); + } - Button chat = (Button) findViewById(R.id.CDChat); - chat.setOnClickListener(new chatListener()); - Button alias = (Button) findViewById(R.id.CDAlias); - alias.setOnClickListener(new aliasListener()); - Button group = (Button) findViewById(R.id.CDGroup); - group.setOnClickListener(new groupListener()); - Button resend = (Button) findViewById(R.id.CDResend); - resend.setOnClickListener(new resendListener()); - Button infos = (Button) findViewById(R.id.CDInfos); - infos.setOnClickListener(new infosListener()); - } - - public void initService() { - mService = BeemApplication.getApplication(ContactDialog.this.getOwnerActivity()).getXmppFacade(); + @Override + public void onServiceDisconnected(ComponentName name) { + xmppFacade = null; + } } } diff -r f879726d6295 -r a81519fc4024 src/com/beem/project/beem/ui/ContactList.java --- a/src/com/beem/project/beem/ui/ContactList.java Thu Jun 18 11:53:00 2009 +0200 +++ b/src/com/beem/project/beem/ui/ContactList.java Thu Jun 18 20:22:56 2009 +0200 @@ -1,13 +1,11 @@ package com.beem.project.beem.ui; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.SortedMap; import org.jivesoftware.smack.util.StringUtils; @@ -30,7 +28,6 @@ import android.view.ViewGroup; import android.view.View.OnClickListener; import android.view.View.OnLongClickListener; -import android.widget.ArrayAdapter; import android.widget.ExpandableListAdapter; import android.widget.ImageView; import android.widget.TextView; @@ -105,16 +102,13 @@ } class ComparatorContactListByName implements Comparator { - @Override public int compare(T c1, T c2) { return ((Contact) c1).getName().compareToIgnoreCase(((Contact) c2).getName()); } - } class ComparatorContactListByStatusAndName implements Comparator { - @Override public int compare(T c1, T c2) { if (((Contact) c1).getStatus() < ((Contact) c2).getStatus()) { @@ -124,14 +118,12 @@ } else return ((Contact) c1).getName().compareToIgnoreCase(((Contact) c2).getName()); } - } private void buildContactList(List listContact) { - Collections.sort(listContact, new ComparatorContactListByStatusAndName()); - // Collections.sort(listContact, new ComparatorContactListByName()); mListContact = listContact; - for (Contact contact : listContact) { + Collections.sort(mListContact, new ComparatorContactListByStatusAndName()); + for (Contact contact : mListContact) { for (String group : contact.getGroups()) { if (!groupMap.containsKey(group)) { groupMap.put(group, new ArrayList()); @@ -344,7 +336,6 @@ void createDialog(Contact contact) { ContactDialog dialogContact = new ContactDialog(ContactList.this, contact); dialogContact.setOwnerActivity(ContactList.this); - dialogContact.initService(); dialogContact.show(); }