src/com/beem/project/beem/ui/ContactList.java
changeset 132 728adc0feb4e
parent 131 64cd99927c28
child 135 efdae5f9289f
--- a/src/com/beem/project/beem/ui/ContactList.java	Tue Apr 21 22:49:38 2009 +0200
+++ b/src/com/beem/project/beem/ui/ContactList.java	Tue Apr 21 23:49:22 2009 +0200
@@ -49,11 +49,11 @@
     @SuppressWarnings("unchecked")
     @Override
     public boolean onChildClick(ExpandableListView parent, View v,
-	    int groupPosition, int childPosition, long id) {
+	int groupPosition, int childPosition, long id) {
 	Intent i = new Intent(this, SendIM.class);
 	Map<String, Contact> child = (HashMap<String, Contact>) parent
-		.getExpandableListAdapter().getChild(groupPosition,
-			childPosition);
+	.getExpandableListAdapter().getChild(groupPosition,
+	    childPosition);
 	i.putExtra("contact", child.get("CHILD"));
 	startActivity(i);
 	return true;
@@ -66,7 +66,7 @@
 	mHandler = new Handler();
 	mBeemApplication = BeemApplication.getApplication(this);
 	mSettings = getSharedPreferences(
-		getString(R.string.PreferenceFileName), MODE_PRIVATE);
+	    getString(R.string.PreferenceFileName), MODE_PRIVATE);
 	mRosterListener = new BeemRosterListener();
     }
 
@@ -74,12 +74,12 @@
     protected void onStart() {
 	super.onStart();
     }
-    
+
     @Override
     protected void onDestroy() {
-        // TODO Auto-generated method stub
-        super.onDestroy();
- //       mBeemApplication.unbindBeemService();
+	// TODO Auto-generated method stub
+	super.onDestroy();
+	//       mBeemApplication.unbindBeemService();
     }
 
     @Override
@@ -118,7 +118,7 @@
 	if (mRoster != null)
 	    try {
 		showContactList(mRoster.getGroupsNames(), mRoster
-			.getContactList());
+		    .getContactList());
 	    } catch (RemoteException e) {
 		e.printStackTrace();
 	    }
@@ -157,24 +157,27 @@
 	    case R.id.account_create:
 		startActivity(new Intent(this, AccountCreation.class));
 		return true;
+	    case R.id.add_contact:
+		startActivity(new Intent(this, AddContact.class));
+		return true;
 	    default:
 		return false;
 	}
     }
-    
+
     protected void onActivityResult(int requestCode, int resultCode,
-            Intent data) {
-        if (requestCode == PREFERENCECHANGED) {
-            if (resultCode == RESULT_OK) {
-                mBeemApplication.stopBeemService();
-                mBeemApplication.startBeemService();
-            }            
-        }
+	Intent data) {
+	if (requestCode == PREFERENCECHANGED) {
+	    if (resultCode == RESULT_OK) {
+		mBeemApplication.stopBeemService();
+		mBeemApplication.startBeemService();
+	    }            
+	}
     }
 
 
     private void showContactList(List<String> listGroup,
-	    List<Contact> listContact) {
+	List<Contact> listContact) {
 	ExpandableListAdapter Adapter;
 	List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
 	List<List<Map<String, Contact>>> childData = new ArrayList<List<Map<String, Contact>>>();
@@ -199,11 +202,11 @@
 	}
 
 	Adapter = new ContactExpandableListAdapter(this, groupData,
-		R.layout.contactlistgroup, new String[] { "GROUP" },
-		new int[] { R.id.textgroup }, childData,
-		R.layout.contactlistcontact, new String[] { "CHILD" },
-		new int[] { R.id.contactliststatus, R.id.contactlistpseudo,
-			R.id.contactlistmsgperso, R.id.contactlistavatar });
+	    R.layout.contactlistgroup, new String[] { "GROUP" },
+	    new int[] { R.id.textgroup }, childData,
+	    R.layout.contactlistcontact, new String[] { "CHILD" },
+	    new int[] { R.id.contactliststatus, R.id.contactlistpseudo,
+	    R.id.contactlistmsgperso, R.id.contactlistavatar });
 	setListAdapter(Adapter);
     }
 
@@ -213,19 +216,19 @@
      * getGroupView() to define the layout of parents)
      */
     private class ContactExpandableListAdapter extends
-	    SimpleExpandableListAdapter {
+    SimpleExpandableListAdapter {
 
 	private List<? extends List<? extends Map<String, ?>>> mChildData;
 	private String[] mChildFrom;
 	private int[] mChildTo;
 
 	public ContactExpandableListAdapter(Context context,
-		List<? extends Map<String, ?>> groupData, int groupLayout,
+	    List<? extends Map<String, ?>> groupData, int groupLayout,
 		String[] groupFrom, int[] groupTo,
 		List<? extends List<? extends Map<String, ?>>> childData,
-		int childLayout, String[] childFrom, int[] childTo) {
+		    int childLayout, String[] childFrom, int[] childTo) {
 	    super(context, groupData, groupLayout, groupFrom, groupTo,
-		    childData, childLayout, childFrom, childTo);
+		childData, childLayout, childFrom, childTo);
 
 	    mChildData = childData;
 	    mChildFrom = childFrom;
@@ -235,7 +238,7 @@
 
 	@Override
 	public View getChildView(int groupPosition, int childPosition,
-		boolean isLastChild, View convertView, ViewGroup parent) {
+	    boolean isLastChild, View convertView, ViewGroup parent) {
 
 	    View v;
 	    if (convertView == null) {
@@ -244,12 +247,12 @@
 		v = convertView;
 	    }
 	    bindView(v, mChildData.get(groupPosition).get(childPosition),
-		    mChildFrom, mChildTo, groupPosition, childPosition);
+		mChildFrom, mChildTo, groupPosition, childPosition);
 	    return v;
 	}
 
 	private void bindView(View view, Map<String, ?> data, String[] from,
-		int[] to, int groupPosition, int childPosition) {
+	    int[] to, int groupPosition, int childPosition) {
 	    Contact c = (Contact) data.get(from[0]);
 
 	    if (c != null) {
@@ -259,32 +262,32 @@
 		switch (c.getStatus()) {
 		    case Status.CONTACT_STATUS_AVAILABLE:
 			imageDrawable = (Drawable) getResources().getDrawable(
-				R.drawable.online);
+			    R.drawable.online);
 			break;
 		    case Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT:
 			imageDrawable = (Drawable) getResources().getDrawable(
-				R.drawable.chat);
+			    R.drawable.chat);
 			break;
 		    case Status.CONTACT_STATUS_AWAY:
 			imageDrawable = (Drawable) getResources().getDrawable(
-				R.drawable.away);
+			    R.drawable.away);
 			break;
 		    case Status.CONTACT_STATUS_BUSY:
 			imageDrawable = (Drawable) getResources().getDrawable(
-				R.drawable.dnd);
+			    R.drawable.dnd);
 			break;
 		    case Status.CONTACT_STATUS_DISCONNECT:
 			imageDrawable = (Drawable) getResources().getDrawable(
-				R.drawable.offline);
+			    R.drawable.offline);
 			break;
 		    case Status.CONTACT_STATUS_UNAVAILABLE:
 			imageDrawable = (Drawable) getResources().getDrawable(
-				R.drawable.requested);
+			    R.drawable.requested);
 			break;
 		    default:
 			imageDrawable = (Drawable) getResources().getDrawable(
-				R.drawable.error);
-			break;
+			    R.drawable.error);
+		    break;
 		}
 		imgV.setImageDrawable(imageDrawable);
 
@@ -297,7 +300,7 @@
 		if (v != null) {
 		    v.setText(c.getMsgState());
 		}
-		
+
 		/*
 		 * TODO: Rajouter l'avatar du contact getAvatar() dans la
 		 * classe
@@ -305,7 +308,7 @@
 		imgV = (ImageView) view.findViewById(to[3]);
 		if (imgV != null) {
 		    imageDrawable = (Drawable) getResources().getDrawable(
-			    R.drawable.avatar);
+			R.drawable.avatar);
 		    imgV.setImageDrawable(imageDrawable);
 		}
 	    }
@@ -316,28 +319,28 @@
 
 	@Override
 	public void onEntriesAdded(List<String> addresses)
-		throws RemoteException {
+	throws RemoteException {
 	    Log.i(TAG, "ENTRIES ADDED");
 
 	}
 
 	@Override
 	public void onEntriesDeleted(List<String> addresses)
-		throws RemoteException {
+	throws RemoteException {
 	    Log.i(TAG, "ENTRIES DEL");
 
 	}
 
 	@Override
 	public void onEntriesUpdated(List<String> addresses)
-		throws RemoteException {
+	throws RemoteException {
 	    Log.i(TAG, "ENTRIES UPD");
 
 	}
 
 	@Override
 	public void onPresenceChanged(PresenceAdapter presence)
-		throws RemoteException {
+	throws RemoteException {
 	    Log.i(TAG, "PRESENCE CHANGED");
 
 	}