# HG changeset patch # User marseille@marseille-desktop # Date 1245690998 -7200 # Node ID ff0b4790a5edaf0ab178b28249117e401e3bafd9 # Parent 0548b407992ac1a485131aa0e2391f5b4a92cacc La gestion de la connection et des changement de settings a ete revu. diff -r 0548b407992a -r ff0b4790a5ed AndroidManifest.xml --- a/AndroidManifest.xml Mon Jun 22 18:07:29 2009 +0200 +++ b/AndroidManifest.xml Mon Jun 22 19:16:38 2009 +0200 @@ -20,7 +20,8 @@ - + diff -r 0548b407992a -r ff0b4790a5ed src/com/beem/project/beem/BeemService.java --- a/src/com/beem/project/beem/BeemService.java Mon Jun 22 18:07:29 2009 +0200 +++ b/src/com/beem/project/beem/BeemService.java Mon Jun 22 19:16:38 2009 +0200 @@ -16,6 +16,7 @@ import android.app.PendingIntent; import android.app.Service; import android.content.Intent; +import android.content.ServiceConnection; import android.content.SharedPreferences; import android.os.IBinder; import android.os.RemoteException; @@ -210,9 +211,8 @@ */ @Override public IBinder onBind(Intent intent) { + Log.e("BEEMSERVICE", "ONBIND()"); return mBind; - // to forbid a client to bind - // return null; } /** @@ -228,6 +228,7 @@ mHost = mSettings.getString(getString(R.string.settings_key_xmpp_server), ""); mPort = Integer.parseInt(mSettings.getString(getString(R.string.settings_key_xmpp_port), "5222")); + Log.i("BEEEMSERVICE", mLogin); if (mHost.equals("talk.google.com")) mService = "gmail.com"; else @@ -244,8 +245,11 @@ */ @Override public void onDestroy() { + super.onDestroy(); + Log.e("BEEEMSERVICE", "ONDESTROY"); closeConnection(); mNotificationManager.cancel(NOTIFICATION_STATUS_ID); + Log.e("BEEEMSERVICE", "ONDESTROY"); } /** @@ -253,6 +257,7 @@ */ @Override public void onStart(Intent intent, int startId) { + super.onStart(intent, startId); try { mConnection.connectAsync(); } catch (RemoteException e) { diff -r 0548b407992a -r ff0b4790a5ed src/com/beem/project/beem/service/XmppConnectionAdapter.java --- a/src/com/beem/project/beem/service/XmppConnectionAdapter.java Mon Jun 22 18:07:29 2009 +0200 +++ b/src/com/beem/project/beem/service/XmppConnectionAdapter.java Mon Jun 22 19:16:38 2009 +0200 @@ -228,7 +228,8 @@ for (int i = 0; i < n; i++) { IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i); try { - listener.connectionClosed(); + if (listener != null) + listener.connectionClosed(); } catch (RemoteException e) { // The RemoteCallbackList will take care of removing the // dead listeners. @@ -249,7 +250,8 @@ for (int i = 0; i < n; i++) { IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i); try { - listener.connectionClosedOnError(); + if (listener != null) + listener.connectionClosedOnError(); } catch (RemoteException e) { // The RemoteCallbackList will take care of removing the // dead listeners. @@ -266,7 +268,8 @@ for (int i = 0; i < n; i++) { IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i); try { - listener.connectionFailed(errorMsg); + if (listener != null) + listener.connectionFailed(errorMsg); } catch (RemoteException e) { // The RemoteCallbackList will take care of removing the // dead listeners. @@ -285,7 +288,8 @@ for (int i = 0; i < n; i++) { IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i); try { - listener.onConnect(); + if (listener != null) + listener.onConnect(); } catch (RemoteException e) { // The RemoteCallbackList will take care of removing the // dead listeners. @@ -305,7 +309,8 @@ for (int i = 0; i < n; i++) { IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i); try { - listener.reconnectingIn(arg0); + if (listener != null) + listener.reconnectingIn(arg0); } catch (RemoteException e) { // The RemoteCallbackList will take care of removing the // dead listeners. @@ -325,7 +330,8 @@ for (int i = 0; i < r; i++) { IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i); try { - listener.reconnectionFailed(); + if (listener != null) + listener.reconnectionFailed(); } catch (RemoteException e) { // The RemoteCallbackList will take care of removing the // dead listeners. @@ -345,7 +351,8 @@ for (int i = 0; i < n; i++) { IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i); try { - listener.reconnectionSuccessful(); + if (listener != null) + listener.reconnectionSuccessful(); } catch (RemoteException e) { // The RemoteCallbackList will take care of removing the // dead listeners. diff -r 0548b407992a -r ff0b4790a5ed src/com/beem/project/beem/ui/ContactList.java --- a/src/com/beem/project/beem/ui/ContactList.java Mon Jun 22 18:07:29 2009 +0200 +++ b/src/com/beem/project/beem/ui/ContactList.java Mon Jun 22 19:16:38 2009 +0200 @@ -44,449 +44,466 @@ public class ContactList extends ExpandableListActivity { - private static final String TAG = "CONTACTLIST_ACT"; - private static final String DEFAULT_GROUP = "Default"; - private MyExpandableListAdapter mAdapter; - 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(); + private static final String TAG = "CONTACTLIST_ACT"; + private static final String DEFAULT_GROUP = "Default"; + private MyExpandableListAdapter mAdapter; + 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(); + private int REQUEST_CODE = 1; + + /** + * Callback for menu creation. + * @param menu the menu created + * @return true on success, false otherwise + */ + @Override + public final boolean onCreateOptionsMenu(Menu menu) { + super.onCreateOptionsMenu(menu); + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.contact_list, menu); + return true; + } - /** - * Callback for menu creation. - * @param menu the menu created - * @return true on success, false otherwise - */ + /** + * Callback for menu item selected. + * @param item the item selected + * @return true on success, false otherwise + */ + @Override + public final boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.contact_list_menu_settings: + startActivityForResult(new Intent(this, EditSettings.class), REQUEST_CODE); + return true; + case R.id.contact_list_menu_add_contact: + startActivity(new Intent(ContactList.this, AddContact.class)); + return true; + default: + return false; + } + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (requestCode == REQUEST_CODE) { + if (resultCode == 69) { + stopService(new Intent(this, BeemService.class)); + finish(); + startActivity(new Intent(this, Login.class)); + } + } + } + + @Override + protected void onCreate(Bundle saveBundle) { + super.onCreate(saveBundle); + mHandler = new Handler(); + groupMap = new HashMap>(); + groupName = new ArrayList(); + } + + @Override + protected void onStart() { + super.onStart(); + bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE); + } + + @Override + protected void onStop() { + super.onStop(); + unbindService(mServConn); + } + + class ComparatorContactListByName implements Comparator { @Override - public final boolean onCreateOptionsMenu(Menu menu) { - super.onCreateOptionsMenu(menu); - MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.contact_list, menu); - return true; + public int compare(T c1, T c2) { + return ((Contact) c1).getName().compareToIgnoreCase(((Contact) c2).getName()); } + } - /** - * Callback for menu item selected. - * @param item the item selected - * @return true on success, false otherwise - */ + class ComparatorContactListByStatusAndName implements Comparator { @Override - public final boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.contact_list_menu_settings: - startActivity(new Intent(this, EditSettings.class)); - return true; - case R.id.contact_list_menu_add_contact: - startActivity(new Intent(ContactList.this, AddContact.class)); - return true; - default: - return false; + public int compare(T c1, T c2) { + if (((Contact) c1).getStatus() < ((Contact) c2).getStatus()) { + return 1; + } else if (((Contact) c1).getStatus() > ((Contact) c2).getStatus()) { + return -1; + } else + return ((Contact) c1).getName().compareToIgnoreCase(((Contact) c2).getName()); + } + } + + private void buildContactList(List listContact) { + mListContact = listContact; + Collections.sort(mListContact, new ComparatorContactListByStatusAndName()); + for (Contact contact : mListContact) { + for (String group : contact.getGroups()) { + if (!groupMap.containsKey(group)) { + groupMap.put(group, new ArrayList()); + Collections.sort(groupMap.get(group), new ComparatorContactListByStatusAndName()); + groupName.add(group); } + try { + if (!groupMap.get(group).contains(contact)) + groupMap.get(group).add(contact); + } catch (NullPointerException e) { + Log.e(TAG, "Failed to find group in groupMap", e); + } + } + if (contact.getGroups().isEmpty()) { + if (!groupMap.containsKey(DEFAULT_GROUP)) { + groupMap.put(DEFAULT_GROUP, new ArrayList()); + groupName.add(DEFAULT_GROUP); + } + groupMap.get(DEFAULT_GROUP).add(contact); + } } + mAdapter = new MyExpandableListAdapter(); + setListAdapter(mAdapter); + } + + private class BeemRosterListener extends IBeemRosterListener.Stub { @Override - protected void onCreate(Bundle saveBundle) { - super.onCreate(saveBundle); - bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE); - mHandler = new Handler(); - groupMap = new HashMap>(); - groupName = new ArrayList(); + public void onEntriesAdded(List addresses) throws RemoteException { + for (String str : addresses) { + Contact curContact = mRoster.getContact(str); + for (String group : curContact.getGroups()) { + if (!groupMap.containsKey(group)) { + groupMap.put(group, new ArrayList()); + groupName.add(group); + } + try { + groupMap.get(group).add(curContact); + } catch (NullPointerException e) { + Log.e(TAG, "Failed to find group in groupMap", e); + } + } + } + mHandler.post(new RunnableChange()); } @Override - protected void onDestroy() { - super.onDestroy(); - unbindService(mServConn); - } - - 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()) { - return 1; - } else if (((Contact) c1).getStatus() > ((Contact) c2).getStatus()) { - return -1; - } else - return ((Contact) c1).getName().compareToIgnoreCase(((Contact) c2).getName()); + public void onEntriesDeleted(List addresses) throws RemoteException { + for (List cList : groupMap.values()) { + for (Contact curContact : cList) { + for (String addr : addresses) { + if (addr.equals(curContact.getJID())) { + cList.remove(curContact); + if (cList.isEmpty()) { + groupMap.values().remove(cList); + } + } + } } - } - - private void buildContactList(List listContact) { - mListContact = listContact; - Collections.sort(mListContact, new ComparatorContactListByStatusAndName()); - for (Contact contact : mListContact) { - for (String group : contact.getGroups()) { - if (!groupMap.containsKey(group)) { - groupMap.put(group, new ArrayList()); - Collections.sort(groupMap.get(group), new ComparatorContactListByStatusAndName()); - groupName.add(group); - } - try { - if (!groupMap.get(group).contains(contact)) - groupMap.get(group).add(contact); - } catch (NullPointerException e) { - Log.e(TAG, "Failed to find group in groupMap", e); - } - } - if (contact.getGroups().isEmpty()) { - if (!groupMap.containsKey(DEFAULT_GROUP)) { - groupMap.put(DEFAULT_GROUP, new ArrayList()); - groupName.add(DEFAULT_GROUP); - } - groupMap.get(DEFAULT_GROUP).add(contact); - } - } - mAdapter = new MyExpandableListAdapter(); - setListAdapter(mAdapter); + } + mHandler.post(new RunnableChange()); } - private class BeemRosterListener extends IBeemRosterListener.Stub { - - @Override - public void onEntriesAdded(List addresses) throws RemoteException { - for (String str : addresses) { - Contact curContact = mRoster.getContact(str); - for (String group : curContact.getGroups()) { - if (!groupMap.containsKey(group)) { - groupMap.put(group, new ArrayList()); - groupName.add(group); - } - try { - groupMap.get(group).add(curContact); - } catch (NullPointerException e) { - Log.e(TAG, "Failed to find group in groupMap", e); - } - } + @Override + public void onEntriesUpdated(List addresses) throws RemoteException { + for (String str : addresses) { + Contact curContact = mRoster.getContact(str); + for (String group : curContact.getGroups()) { + if (!groupMap.containsKey(group)) { + groupMap.put(group, new ArrayList()); + groupName.add(group); + groupMap.get(group).add(curContact); + } else { + boolean found = false; + for (Contact tempContact : groupMap.get(group)) { + if (tempContact.getJID().equals(str)) { + found = true; + break; + } } - mHandler.post(new RunnableChange()); + if (!found) { + groupMap.get(group).add(curContact); + } + } } - - @Override - public void onEntriesDeleted(List addresses) throws RemoteException { - for (List cList : groupMap.values()) { - for (Contact curContact : cList) { - for (String addr : addresses) { - if (addr.equals(curContact.getJID())) { - cList.remove(curContact); - if (cList.isEmpty()) { - groupMap.values().remove(cList); - } - } - } - } - } - mHandler.post(new RunnableChange()); - } + } + mHandler.post(new RunnableChange()); + } - @Override - public void onEntriesUpdated(List addresses) throws RemoteException { - for (String str : addresses) { - Contact curContact = mRoster.getContact(str); - for (String group : curContact.getGroups()) { - if (!groupMap.containsKey(group)) { - groupMap.put(group, new ArrayList()); - groupName.add(group); - groupMap.get(group).add(curContact); - } else { - boolean found = false; - for (Contact tempContact : groupMap.get(group)) { - if (tempContact.getJID().equals(str)) { - found = true; - break; - } - } - if (!found) { - groupMap.get(group).add(curContact); - } - } - } - } - mHandler.post(new RunnableChange()); + @Override + public void onPresenceChanged(PresenceAdapter presence) throws RemoteException { + for (Contact curContact : mListContact) { + if (curContact.getJID().equals(StringUtils.parseBareAddress(presence.getFrom()))) { + curContact.setStatus(mRoster.getPresence(StringUtils.parseBareAddress(presence.getFrom()))); + mHandler.post(new RunnableChange()); + return; } + } + } - @Override - public void onPresenceChanged(PresenceAdapter presence) throws RemoteException { - for (Contact curContact : mListContact) { - if (curContact.getJID().equals(StringUtils.parseBareAddress(presence.getFrom()))) { - curContact.setStatus(mRoster.getPresence(StringUtils.parseBareAddress(presence.getFrom()))); - mHandler.post(new RunnableChange()); - return; - } - } - } + private class RunnableChange implements Runnable { + @Override + public void run() { + mAdapter.changed(); + } + } + + } + + private class MyExpandableListAdapter implements ExpandableListAdapter { + + class MyOnClickListener implements OnClickListener { - private class RunnableChange implements Runnable { - @Override - public void run() { - mAdapter.changed(); - } - } + private final Contact mContact; + + public MyOnClickListener(Contact contact) { + mContact = contact; + } + + @Override + public void onClick(View v) { + Intent i = new Intent(ContactList.this, SendIM.class); + i.setData(mContact.toUri()); + startActivity(i); + } } - private class MyExpandableListAdapter implements ExpandableListAdapter { + class MyOnLongClickListener implements OnLongClickListener { - class MyOnClickListener implements OnClickListener { + private final Contact mContact; - private final Contact mContact; - - public MyOnClickListener(Contact contact) { - mContact = contact; - } + public MyOnLongClickListener(Contact contact) { + mContact = contact; + } - @Override - public void onClick(View v) { - Intent i = new Intent(ContactList.this, SendIM.class); - i.setData(mContact.toUri()); - startActivity(i); - } + @Override + public boolean onLongClick(View v) { + createDialog(mContact); + return true; + } + } + + private final List observers; - } + public MyExpandableListAdapter() { + observers = new ArrayList(); + } - class MyOnLongClickListener implements OnLongClickListener { + @Override + public boolean areAllItemsEnabled() { + return true; + } + + private void bindView(View view, Contact curContact) { - private final Contact mContact; - - public MyOnLongClickListener(Contact contact) { - mContact = contact; - } - - @Override - public boolean onLongClick(View v) { - createDialog(mContact); - return true; - } + if (curContact != null) { + ImageView imgV = (ImageView) view.findViewById(R.id.contactliststatus); + Drawable imageDrawable = null; + switch (curContact.getStatus()) { + case Status.CONTACT_STATUS_AVAILABLE: + imageDrawable = getResources().getDrawable(R.drawable.online); + break; + case Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT: + imageDrawable = getResources().getDrawable(R.drawable.chat); + break; + case Status.CONTACT_STATUS_AWAY: + imageDrawable = getResources().getDrawable(R.drawable.away); + break; + case Status.CONTACT_STATUS_BUSY: + imageDrawable = getResources().getDrawable(R.drawable.dnd); + break; + case Status.CONTACT_STATUS_DISCONNECT: + imageDrawable = getResources().getDrawable(R.drawable.offline); + break; + case Status.CONTACT_STATUS_UNAVAILABLE: + imageDrawable = getResources().getDrawable(R.drawable.requested); + break; + default: + imageDrawable = getResources().getDrawable(R.drawable.error); + break; } - - private final List observers; + imgV.setImageDrawable(imageDrawable); - public MyExpandableListAdapter() { - observers = new ArrayList(); - } - - - @Override - public boolean areAllItemsEnabled() { - return true; + TextView v = (TextView) view.findViewById(R.id.contactlistpseudo); + if (v != null) { + v.setText(curContact.getName()); } - private void bindView(View view, Contact curContact) { - - if (curContact != null) { - ImageView imgV = (ImageView) view.findViewById(R.id.contactliststatus); - Drawable imageDrawable = null; - switch (curContact.getStatus()) { - case Status.CONTACT_STATUS_AVAILABLE: - imageDrawable = getResources().getDrawable(R.drawable.online); - break; - case Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT: - imageDrawable = getResources().getDrawable(R.drawable.chat); - break; - case Status.CONTACT_STATUS_AWAY: - imageDrawable = getResources().getDrawable(R.drawable.away); - break; - case Status.CONTACT_STATUS_BUSY: - imageDrawable = getResources().getDrawable(R.drawable.dnd); - break; - case Status.CONTACT_STATUS_DISCONNECT: - imageDrawable = getResources().getDrawable(R.drawable.offline); - break; - case Status.CONTACT_STATUS_UNAVAILABLE: - imageDrawable = getResources().getDrawable(R.drawable.requested); - break; - default: - imageDrawable = getResources().getDrawable(R.drawable.error); - break; - } - imgV.setImageDrawable(imageDrawable); - - TextView v = (TextView) view.findViewById(R.id.contactlistpseudo); - if (v != null) { - v.setText(curContact.getName()); - } - - v = (TextView) view.findViewById(R.id.contactlistmsgperso); - if (v != null) { - v.setText(curContact.getMsgState()); - Linkify.addLinks(v, Linkify.WEB_URLS); - } - - // TODO: Rajouter l'avatar du contact getAvatar() dans la classe - imgV = (ImageView) view.findViewById(R.id.contactlistavatar); - if (imgV != null) { - imageDrawable = getResources().getDrawable(R.drawable.avatar); - imgV.setImageDrawable(imageDrawable); - } - } - } - - public void changed() { - for (String name : groupName) { - Collections.sort(groupMap.get(name), new ComparatorContactListByStatusAndName()); - } - for (DataSetObserver obs : observers) { - obs.onChanged(); - } - } - - void createDialog(Contact contact) { - ContactDialog dialogContact = new ContactDialog(ContactList.this, contact); - dialogContact.setOwnerActivity(ContactList.this); - dialogContact.show(); - } - - @Override - public Object getChild(int groupPosition, int childPosition) { - try { - return groupMap.get(groupName.get(groupPosition)).get(childPosition); - } catch (NullPointerException e) { - Log.e(TAG, "Child not found", e); - return null; - } + v = (TextView) view.findViewById(R.id.contactlistmsgperso); + if (v != null) { + v.setText(curContact.getMsgState()); + Linkify.addLinks(v, Linkify.WEB_URLS); } - @Override - public long getChildId(int groupPosition, int childPosition) { - try { - groupMap.get(groupName.get(groupPosition)).get(childPosition); - } catch (NullPointerException e) { - Log.e(TAG, "Child not found", e); - return 0; - } - return childPosition; + // TODO: Rajouter l'avatar du contact getAvatar() dans la classe + imgV = (ImageView) view.findViewById(R.id.contactlistavatar); + if (imgV != null) { + imageDrawable = getResources().getDrawable(R.drawable.avatar); + imgV.setImageDrawable(imageDrawable); } - - @Override - public int getChildrenCount(int groupPosition) { - try { - return groupMap.get(groupName.get(groupPosition)).size(); - } catch (NullPointerException e) { - Log.e(TAG, "Child not found", e); - return 0; - } - } + } + } - @Override - public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, - ViewGroup parent) { - View v; - if (convertView == null) { - v = LayoutInflater.from(ContactList.this).inflate(R.layout.contactlistcontact, null); - } else { - v = convertView; - } - Contact contact = groupMap.get(groupName.get(groupPosition)).get(childPosition); - bindView(v, contact); + public void changed() { + for (String name : groupName) { + Collections.sort(groupMap.get(name), new ComparatorContactListByStatusAndName()); + } + for (DataSetObserver obs : observers) { + obs.onChanged(); + } + } - v.setOnLongClickListener(new MyOnLongClickListener(contact)); - v.setOnClickListener(new MyOnClickListener(contact)); - return v; - } + void createDialog(Contact contact) { + ContactDialog dialogContact = new ContactDialog(ContactList.this, contact); + dialogContact.setOwnerActivity(ContactList.this); + dialogContact.show(); + } - @Override - public long getCombinedChildId(long groupId, long childId) { - return 1000 * groupId + childId; - } - - @Override - public long getCombinedGroupId(long groupId) { - return 1000 * groupId; - } + @Override + public Object getChild(int groupPosition, int childPosition) { + try { + return groupMap.get(groupName.get(groupPosition)).get(childPosition); + } catch (NullPointerException e) { + Log.e(TAG, "Child not found", e); + return null; + } + } - @Override - public Object getGroup(int groupPosition) { - try { - return groupMap.get(groupName.get(groupPosition)); - } catch (NullPointerException e) { - Log.e(TAG, "Group not found", e); - return null; - } - } - - @Override - public int getGroupCount() { - return groupMap.size(); - } + @Override + public long getChildId(int groupPosition, int childPosition) { + try { + groupMap.get(groupName.get(groupPosition)).get(childPosition); + } catch (NullPointerException e) { + Log.e(TAG, "Child not found", e); + return 0; + } + return childPosition; + } - @Override - public long getGroupId(int groupPosition) { - return groupPosition; - } - - @Override - public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { - if (convertView == null) { - convertView = LayoutInflater.from(ContactList.this).inflate(R.layout.contactlistgroup, null); - } - TextView groupTextView = (TextView) convertView.findViewById(R.id.textgroup); - groupTextView.setText(groupName.get(groupPosition)); - return convertView; - } + @Override + public int getChildrenCount(int groupPosition) { + try { + return groupMap.get(groupName.get(groupPosition)).size(); + } catch (NullPointerException e) { + Log.e(TAG, "Child not found", e); + return 0; + } + } - @Override - public boolean hasStableIds() { - return false; - } - - @Override - public boolean isChildSelectable(int groupPosition, int childPosition) { - return true; - } - - @Override - public boolean isEmpty() { - return groupMap.isEmpty(); - } + @Override + public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, + ViewGroup parent) { + View v; + if (convertView == null) { + v = LayoutInflater.from(ContactList.this).inflate(R.layout.contactlistcontact, null); + } else { + v = convertView; + } + Contact contact = groupMap.get(groupName.get(groupPosition)).get(childPosition); + bindView(v, contact); - @Override - public void onGroupCollapsed(int groupPosition) { - } - - @Override - public void onGroupExpanded(int groupPosition) { - } + v.setOnLongClickListener(new MyOnLongClickListener(contact)); + v.setOnClickListener(new MyOnClickListener(contact)); + return v; + } - @Override - public void registerDataSetObserver(DataSetObserver observer) { - observers.add(observer); - } + @Override + public long getCombinedChildId(long groupId, long childId) { + return 1000 * groupId + childId; + } - @Override - public void unregisterDataSetObserver(DataSetObserver observer) { - observers.remove(observer); - } + @Override + public long getCombinedGroupId(long groupId) { + return 1000 * groupId; } - private class BeemServiceConnection implements ServiceConnection { + @Override + public Object getGroup(int groupPosition) { + try { + return groupMap.get(groupName.get(groupPosition)); + } catch (NullPointerException e) { + Log.e(TAG, "Group not found", e); + return null; + } + } + + @Override + public int getGroupCount() { + return groupMap.size(); + } + + @Override + public long getGroupId(int groupPosition) { + return groupPosition; + } + + @Override + public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { + if (convertView == null) { + convertView = LayoutInflater.from(ContactList.this).inflate(R.layout.contactlistgroup, null); + } + TextView groupTextView = (TextView) convertView.findViewById(R.id.textgroup); + groupTextView.setText(groupName.get(groupPosition)); + return convertView; + } + + @Override + public boolean hasStableIds() { + return false; + } + + @Override + public boolean isChildSelectable(int groupPosition, int childPosition) { + return true; + } - @Override - public void onServiceConnected(ComponentName name, IBinder service) { - xmppFacade = IXmppFacade.Stub.asInterface(service); - try { - mRoster = xmppFacade.getRoster(); - if (mRoster != null) { - mRoster.addRosterListener(new BeemRosterListener()); - buildContactList(mRoster.getContactList()); - } - } catch (RemoteException e) { - e.printStackTrace(); - } + @Override + public boolean isEmpty() { + return groupMap.isEmpty(); + } + + @Override + public void onGroupCollapsed(int groupPosition) { + } + + @Override + public void onGroupExpanded(int groupPosition) { + } + + @Override + public void registerDataSetObserver(DataSetObserver observer) { + observers.add(observer); + } + + @Override + public void unregisterDataSetObserver(DataSetObserver observer) { + 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(); + if (mRoster != null) { + mRoster.addRosterListener(new BeemRosterListener()); + buildContactList(mRoster.getContactList()); } + } catch (RemoteException e) { + e.printStackTrace(); + } + } - @Override - public void onServiceDisconnected(ComponentName name) { - xmppFacade = null; - mRoster = null; - } + @Override + public void onServiceDisconnected(ComponentName name) { + xmppFacade = null; + mRoster = null; } + } } diff -r 0548b407992a -r ff0b4790a5ed src/com/beem/project/beem/ui/EditSettings.java --- a/src/com/beem/project/beem/ui/EditSettings.java Mon Jun 22 18:07:29 2009 +0200 +++ b/src/com/beem/project/beem/ui/EditSettings.java Mon Jun 22 19:16:38 2009 +0200 @@ -20,7 +20,6 @@ import android.widget.TabHost; import android.widget.Toast; -import com.beem.project.beem.BeemService; import com.beem.project.beem.R; /** @@ -291,6 +290,7 @@ public void onClick(View v) { saveSettings(); + setResult(69); } }); } @@ -351,7 +351,6 @@ startActivity(i); return true; case R.id.settings_menu_login: - setResult(69); finish(); return true; } @@ -487,7 +486,5 @@ displayNotification(getText(R.string.settings_saved_ok)); Log.i(getString(R.string.edit_settings_tag), LOG_MSG_SETTINGS_SAVED); } - - stopService(new Intent(this, BeemService.class)); } } diff -r 0548b407992a -r ff0b4790a5ed src/com/beem/project/beem/ui/Login.java --- a/src/com/beem/project/beem/ui/Login.java Mon Jun 22 18:07:29 2009 +0200 +++ b/src/com/beem/project/beem/ui/Login.java Mon Jun 22 19:16:38 2009 +0200 @@ -72,7 +72,7 @@ @Override public void onClick(View v) { - startActivityForResult(new Intent(Login.this, EditSettings.class), REQUEST_CODE); + startActivity(new Intent(Login.this, EditSettings.class)); } }); @@ -82,16 +82,20 @@ @Override public void onClick(View v) { bindService(Login.SERVICE_INTENT, mServConn, BIND_AUTO_CREATE); + Log.e("LOGIN", "bindService()"); } }); + progressDialog = new ProgressDialog(this); } @Override protected void onDestroy() { super.onDestroy(); - if (mIsConnected) + if (mIsConnected) { + Log.e("LOGIN", "unbindService()"); unbindService(mServConn); + } } /** @@ -100,10 +104,8 @@ @Override public void onStart() { super.onStart(); - Log.i(TAG, "OnStart()"); - progressDialog = new ProgressDialog(this); - if (!mIsConnected) - bindService(Login.SERVICE_INTENT, mServConn, BIND_AUTO_CREATE); + Log.e("Login", "bindService"); + bindService(Login.SERVICE_INTENT, mServConn, BIND_AUTO_CREATE); } private class BeemConnectionListener extends IBeemConnectionListener.Stub { @@ -125,11 +127,10 @@ @Override public void connectionClosed() throws RemoteException { - if (mIsConnected) { - mIsConnected = false; - Login.this.unbindService(mServConn); - Login.this.stopService(SERVICE_INTENT); - } + mIsConnected = false; + Log.e("Login", "CONNECTIONCLOSED"); + Login.this.unbindService(mServConn); + Login.this.stopService(SERVICE_INTENT); } @Override @@ -144,8 +145,6 @@ @Override public void connectionFailed(String errorMsg) throws RemoteException { mIsConnected = false; - Login.this.unbindService(mServConn); - Login.this.stopService(SERVICE_INTENT); connectionHandler.post(new ErrorRunnable(errorMsg)); dismissProgressDialog(); showToast(errorMsg);