# HG changeset patch # User Marseille # Date 1245787290 -7200 # Node ID 8979375c19f0a7e1c9edccca3e9bb8caeba92f92 # Parent 1b87dbca7ea2644ed6b0c0ceb760227def29478e Suppression de contact. diff -r 1b87dbca7ea2 -r 8979375c19f0 res/values/strings.xml --- a/res/values/strings.xml Tue Jun 23 19:22:46 2009 +0200 +++ b/res/values/strings.xml Tue Jun 23 22:01:30 2009 +0200 @@ -80,6 +80,7 @@ Group: Ok Contact added + Error Contact not added Bad form diff -r 1b87dbca7ea2 -r 8979375c19f0 src/com/beem/project/beem/service/RosterAdapter.java --- a/src/com/beem/project/beem/service/RosterAdapter.java Tue Jun 23 19:22:46 2009 +0200 +++ b/src/com/beem/project/beem/service/RosterAdapter.java Tue Jun 23 22:01:30 2009 +0200 @@ -22,6 +22,7 @@ import android.util.Log; import com.beem.project.beem.service.aidl.IBeemRosterListener; +import com.beem.project.beem.ui.ContactList; /** * This class implement a Roster adapter for BEEM. @@ -81,7 +82,7 @@ res.addGroup(groupStr); found = true; } catch (XMPPException e) { - e.printStackTrace(); + Log.e(TAG, "add new contact", e); } } } @@ -124,12 +125,15 @@ */ @Override public void deleteContact(Contact contact, String group) throws RemoteException { - mContacts.get(contact.getJID()).delGroup(group); try { - if (mAdaptee != null) { - RosterEntry entry = mAdaptee.getEntry(contact.getJID()); - if (entry != null) - mAdaptee.getGroup(group).removeEntry(entry); + RosterEntry entry = mAdaptee.getEntry(contact.getJID()); + if (entry.getGroups().size() == 0) { + mContacts.remove(contact.getJID()); + mAdaptee.removeEntry(entry); + } else { + mContacts.get(contact.getJID()).delGroup(group); + mAdaptee.getGroup(group).removeEntry(entry); + mRosterListener.onEntryDeleteFromGroup(group, contact.getJID()); } } catch (XMPPException e) { e.printStackTrace(); @@ -198,7 +202,7 @@ return new PresenceAdapter(mAdaptee.getPresence(jid)); } - private Contact getContactFromRosterEntry(RosterEntry entry) { + private Contact getContactFromRosterEntry(RosterEntry entry) { String user = StringUtils.parseBareAddress(entry.getUser()); Contact c = new Contact(user); c.setStatus(mAdaptee.getPresence(user)); @@ -207,7 +211,6 @@ return c; } - /** * Listener for the roster events. It will call the remote listeners registered. * @author darisk @@ -220,6 +223,21 @@ public RosterListenerAdapter() { } + public void onEntryDeleteFromGroup(String group, String jid) { + Log.i(TAG, "Roster error listener"); + final int n = mRemoteRosListeners.beginBroadcast(); + for (int i = 0; i < n; i++) { + IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i); + try { + listener.onEntryDeleteFromGroup(group, jid); + } catch (RemoteException e) { + Log.w(TAG, "Roster error listener", e); + } + } + mRemoteRosListeners.finishBroadcast(); + + } + /** * {@inheritDoc} */ diff -r 1b87dbca7ea2 -r 8979375c19f0 src/com/beem/project/beem/service/aidl/IBeemRosterListener.aidl --- a/src/com/beem/project/beem/service/aidl/IBeemRosterListener.aidl Tue Jun 23 19:22:46 2009 +0200 +++ b/src/com/beem/project/beem/service/aidl/IBeemRosterListener.aidl Tue Jun 23 22:01:30 2009 +0200 @@ -7,4 +7,5 @@ void onEntriesUpdated(in List addresses); void onEntriesDeleted(in List addresses); void onPresenceChanged(in PresenceAdapter presence); + void onEntryDeleteFromGroup(in String group, in String jid); } \ No newline at end of file diff -r 1b87dbca7ea2 -r 8979375c19f0 src/com/beem/project/beem/ui/AddContact.java --- a/src/com/beem/project/beem/ui/AddContact.java Tue Jun 23 19:22:46 2009 +0200 +++ b/src/com/beem/project/beem/ui/AddContact.java Tue Jun 23 22:01:30 2009 +0200 @@ -28,79 +28,77 @@ */ public class AddContact extends Activity { - protected static final String TAG = "AddContact"; - private String mLogin; - private String mAlias; - private final List mGroup = new ArrayList(); - private IXmppFacade xmppFacade; - private final ServiceConnection mServConn = new BeemServiceConnection(); + protected static final String TAG = "AddContact"; + private String mLogin; + private String mAlias; + private final List mGroup = new ArrayList(); + private IXmppFacade xmppFacade; + private final ServiceConnection mServConn = new BeemServiceConnection(); + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.addcontact); + Button ok = (Button) findViewById(R.id.addc_ok); + ok.setOnClickListener(mOkListener); + bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + unbindService(mServConn); + } + + private class BeemServiceConnection implements ServiceConnection { @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.addcontact); - Button ok = (Button) findViewById(R.id.addc_ok); - ok.setOnClickListener(mOkListener); - bindService(new Intent(this, BeemService.class), mServConn, - BIND_AUTO_CREATE); + public void onServiceConnected(ComponentName name, IBinder service) { + xmppFacade = IXmppFacade.Stub.asInterface(service); } @Override - protected void onDestroy() { - super.onDestroy(); - unbindService(mServConn); + public void onServiceDisconnected(ComponentName name) { + xmppFacade = null; } - - private class BeemServiceConnection implements ServiceConnection { + } - @Override - public void onServiceConnected(ComponentName name, IBinder service) { - xmppFacade = IXmppFacade.Stub.asInterface(service); - } + private String getWidgetText(int id) { + EditText widget = (EditText) this.findViewById(id); + return widget.getText().toString(); + } - @Override - public void onServiceDisconnected(ComponentName name) { - xmppFacade = null; - } - } - - private String getWidgetText(int id) { - EditText widget = (EditText) this.findViewById(id); - return widget.getText().toString(); - } + private final OnClickListener mOkListener = new OnClickListener() { - private final OnClickListener mOkListener = new OnClickListener() { - - @Override - public void onClick(View v) { - boolean valid = true; - mLogin = getWidgetText(R.id.addc_login); - mAlias = getWidgetText(R.id.addc_alias); - if (mLogin.length() == 0) - valid = false; - if (getWidgetText(R.id.addc_group).length() != 0) - mGroup.add(getWidgetText(R.id.addc_group)); - if (valid) { - try { - xmppFacade.getRoster().addContact(mLogin, mAlias, - mGroup.toArray(new String[mGroup.size()])); - Toast.makeText(AddContact.this, - getString(R.string.AddCContactAdded), - Toast.LENGTH_SHORT).show(); - finish(); - } catch (RemoteException e) { - Toast.makeText(AddContact.this, e.getMessage(), - Toast.LENGTH_SHORT).show(); - e.printStackTrace(); - } - setResult(RESULT_OK); - } else { - Toast.makeText(AddContact.this, - getString(R.string.AddCBadForm), Toast.LENGTH_SHORT) - .show(); - setResult(RESULT_CANCELED); - } - + @Override + public void onClick(View v) { + boolean valid = true; + mLogin = getWidgetText(R.id.addc_login); + mAlias = getWidgetText(R.id.addc_alias); + if (mLogin.length() == 0) + valid = false; + if (getWidgetText(R.id.addc_group).length() != 0) + mGroup.add(getWidgetText(R.id.addc_group)); + if (valid) { + try { + if (xmppFacade.getRoster().addContact(mLogin, mAlias, mGroup.toArray(new String[mGroup.size()])) == null) { + Toast.makeText(AddContact.this, getString(R.string.AddCContactAddedError), Toast.LENGTH_SHORT) + .show(); + } else { + Toast.makeText(AddContact.this, getString(R.string.AddCContactAdded), Toast.LENGTH_SHORT) + .show(); + } + finish(); + } catch (RemoteException e) { + Toast.makeText(AddContact.this, e.getMessage(), Toast.LENGTH_SHORT).show(); + e.printStackTrace(); } - }; + setResult(RESULT_OK); + } else { + Toast.makeText(AddContact.this, getString(R.string.AddCBadForm), Toast.LENGTH_SHORT).show(); + setResult(RESULT_CANCELED); + } + + } + }; } diff -r 1b87dbca7ea2 -r 8979375c19f0 src/com/beem/project/beem/ui/ContactList.java --- a/src/com/beem/project/beem/ui/ContactList.java Tue Jun 23 19:22:46 2009 +0200 +++ b/src/com/beem/project/beem/ui/ContactList.java Tue Jun 23 22:01:30 2009 +0200 @@ -45,7 +45,7 @@ public class ContactList extends ExpandableListActivity { private static final String TAG = "CONTACTLIST_ACT"; - private static final String DEFAULT_GROUP = "Default"; + public static final String DEFAULT_GROUP = "Default"; private MyExpandableListAdapter mAdapter; private IRoster mRoster; private Map> groupMap; @@ -232,9 +232,8 @@ break; } } - if (!found) { + if (!found) groupMap.get(group).add(curContact); - } } } } @@ -259,6 +258,19 @@ } } + @Override + public void onEntryDeleteFromGroup(String group, String jid) throws RemoteException { + for (Contact contact : mListContact) { + if (jid.equals(contact.getJID())) { + groupMap.get(group).remove(contact); + if (groupMap.get(group).size() == 0) { + groupMap.remove(group); + groupName.remove(group); + } + } + } + mHandler.post(new RunnableChange()); + } } private class MyExpandableListAdapter implements ExpandableListAdapter { @@ -497,6 +509,7 @@ } private class BeemServiceConnection implements ServiceConnection { + BeemRosterListener mBeemRosterListener = new BeemRosterListener(); @Override public void onServiceConnected(ComponentName name, IBinder service) { @@ -504,7 +517,7 @@ try { mRoster = xmppFacade.getRoster(); if (mRoster != null) { - mRoster.addRosterListener(new BeemRosterListener()); + mRoster.addRosterListener(mBeemRosterListener); buildContactList(mRoster.getContactList()); } } catch (RemoteException e) { @@ -515,6 +528,11 @@ @Override public void onServiceDisconnected(ComponentName name) { xmppFacade = null; + try { + mRoster.removeRosterListener(mBeemRosterListener); + } catch (RemoteException e) { + e.printStackTrace(); + } mRoster = null; } } diff -r 1b87dbca7ea2 -r 8979375c19f0 src/com/beem/project/beem/ui/SendIM.java --- a/src/com/beem/project/beem/ui/SendIM.java Tue Jun 23 19:22:46 2009 +0200 +++ b/src/com/beem/project/beem/ui/SendIM.java Tue Jun 23 22:01:30 2009 +0200 @@ -255,6 +255,7 @@ } private class BeemServiceConnection implements ServiceConnection { + BeemRosterListener mBeemRosterListener = new BeemRosterListener(); @Override public void onServiceConnected(ComponentName name, IBinder service) { @@ -266,7 +267,7 @@ } mRoster = xmppFacade.getRoster(); if (mRoster != null) { - mRoster.addRosterListener(new BeemRosterListener()); + mRoster.addRosterListener(mBeemRosterListener); // mContact.setStatus(mRoster.getPresence(mContact.getJID())); mContact = mRoster.getContact(mContact.getJID()); mStatusText.setText(mContact.getMsgState()); @@ -281,6 +282,11 @@ @Override public void onServiceDisconnected(ComponentName name) { xmppFacade = null; + try { + mRoster.removeRosterListener(mBeemRosterListener); + } catch (RemoteException e) { + e.printStackTrace(); + } } } @@ -417,6 +423,13 @@ } } + @Override + public void onEntryDeleteFromGroup(String group, String jid) throws RemoteException { + // TODO Auto-generated method stub + + } + + } /**