# HG changeset patch # User marseille@KungFuh # Date 1238525166 -7200 # Node ID 743ccc7961dca597a291c0ff0ff1bc3475b690eb # Parent d5a36d8206459697126cf545188c5d60b968b40d Contact liste recuperer. Cest pas encore au top! diff -r d5a36d820645 -r 743ccc7961dc res/layout/contactlist.xml --- a/res/layout/contactlist.xml Tue Mar 31 22:21:42 2009 +0200 +++ b/res/layout/contactlist.xml Tue Mar 31 20:46:06 2009 +0200 @@ -1,19 +1,16 @@ - - - - - - + android:orientation="vertical" + android:layout_width="fill_parent" + android:layout_height="fill_parent"> + + + + + + \ No newline at end of file diff -r d5a36d820645 -r 743ccc7961dc res/layout/contactlistcontact.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/res/layout/contactlistcontact.xml Tue Mar 31 20:46:06 2009 +0200 @@ -0,0 +1,26 @@ + + + + + + + + + + + + \ No newline at end of file diff -r d5a36d820645 -r 743ccc7961dc res/layout/contactlistgroup.xml --- a/res/layout/contactlistgroup.xml Tue Mar 31 22:21:42 2009 +0200 +++ b/res/layout/contactlistgroup.xml Tue Mar 31 20:46:06 2009 +0200 @@ -1,16 +1,18 @@ + android:orientation="horizontal" + android:layout_width="fill_parent" + android:layout_height="50sp" + android:paddingTop="5sp" + android:gravity="center_vertical"> - + - + + + \ No newline at end of file diff -r d5a36d820645 -r 743ccc7961dc src/com/beem/project/beem/BeemApplication.java --- a/src/com/beem/project/beem/BeemApplication.java Tue Mar 31 22:21:42 2009 +0200 +++ b/src/com/beem/project/beem/BeemApplication.java Tue Mar 31 20:46:06 2009 +0200 @@ -31,6 +31,7 @@ private Resources mPrivateResources; private static BeemApplication mBeemApp; private List mQueue = new LinkedList(); + private boolean mIsConnected; public static BeemApplication getApplication(Activity activity) { if (mBeemApp == null) { @@ -68,12 +69,13 @@ } public synchronized void startBeemService() { - if (mFacade == null) { + if (!mIsConnected) { // Intent intent = new Intent(this, BeemService.class); Intent intent = new Intent(); intent.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService")); mApplicationContext.startService(intent); mApplicationContext.bindService(intent, mServConn, BIND_AUTO_CREATE); + mIsConnected = true; } } @@ -82,7 +84,7 @@ @Override public void onServiceDisconnected(ComponentName name) { mFacade = null; - + mIsConnected = false; } @Override @@ -110,7 +112,7 @@ public void callWhenServiceConnected(Handler target, Runnable callback) { Message msg = Message.obtain(target, callback); - if (mFacade != null) { + if (!mIsConnected) { msg.sendToTarget(); } else { startBeemService(); diff -r d5a36d820645 -r 743ccc7961dc src/com/beem/project/beem/ui/ContactList.java --- a/src/com/beem/project/beem/ui/ContactList.java Tue Mar 31 22:21:42 2009 +0200 +++ b/src/com/beem/project/beem/ui/ContactList.java Tue Mar 31 20:46:06 2009 +0200 @@ -6,145 +6,161 @@ import java.util.Map; import android.app.ExpandableListActivity; -import android.content.ComponentName; -import android.content.Intent; -import android.content.ServiceConnection; +import android.app.ProgressDialog; +import android.content.Context; +import android.graphics.drawable.Drawable; import android.os.Bundle; -import android.os.IBinder; +import android.os.Handler; import android.os.RemoteException; import android.util.Log; +import android.view.View; +import android.view.ViewGroup; import android.widget.ExpandableListAdapter; +import android.widget.ImageView; import android.widget.SimpleExpandableListAdapter; +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.aidl.IBeemConnectionListener; -import com.beem.project.beem.service.aidl.IRoster; -import com.beem.project.beem.service.aidl.IXMPPConnection; import com.beem.project.beem.service.aidl.IXMPPFacade; public class ContactList extends ExpandableListActivity { - private static final String TAG = "CONTACTLIST_ACT"; - - private IXMPPFacade mService = null; - - private BeemApplication mBeemApplication; - - @Override - public void onCreate(Bundle saveBundle) { - super.onCreate(saveBundle); - mBeemApplication = BeemApplication.getApplication(this); - mBeemApplication.startBeemService(); - mService = mBeemApplication.getXmppFacade(); - /* bindService(new Intent(this, BeemService.class), mConnection, - BIND_AUTO_CREATE | BIND_DEBUG_UNBIND); */ - showContactList(); - } - - private void showContactList() { - ExpandableListAdapter Adapter; - - List> groupData = new ArrayList>(); - List>> childData = new ArrayList>>(); - - for (int i = 0; i < 2; i++) { - Map curGroupMap = new HashMap(); - groupData.add(curGroupMap); - curGroupMap.put("NAME", "Group " + i); - - List> children = new ArrayList>(); - for (int j = 0; j < 5; j++) { - Map curChildMap = new HashMap(); - children.add(curChildMap); - curChildMap.put("NAOME CHILD", "Child " + j); - } - childData.add(children); - } - - Adapter = new SimpleExpandableListAdapter(this, - groupData, R.layout.contactlistgroup, - new String[] {"NAME"}, new int[] {R.id.textgroup}, - childData, R.layout.contactlist, - new String[] {"NAME CHILD"}, new int[] {R.id.textchild}); - setListAdapter(Adapter); - } - - private ServiceConnection mConnection = new ServiceConnection() { - @Override - public void onServiceConnected(ComponentName name, IBinder service) { - mService = IXMPPFacade.Stub.asInterface(service); - try { - IXMPPConnection con = mService.createConnection(); - con.addConnectionListener(new TestConnectionListener()); - mService.connectSync(); - Log.i("BEEM", "Connected !!!"); - } catch (RemoteException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - /* - * mService.getGroupList(); mService.getContactList(); - */ - } - - @Override - public void onServiceDisconnected(ComponentName name) { - } - - }; - - @Override - public void onDestroy() { - super.onDestroy(); - unbindService(mConnection); - } - - private class TestConnectionListener extends IBeemConnectionListener.Stub { + private static final String TAG = "CONTACTLIST_ACT"; + private IXMPPFacade mService = null; + private Handler mHandler; + private BeemApplication mBeemApplication; @Override - public void connectionClosed() throws RemoteException { - // TODO Auto-generated method stub - - } + public void onCreate(Bundle saveBundle) { + super.onCreate(saveBundle); + mHandler = new Handler(); + mBeemApplication = BeemApplication.getApplication(this); + - @Override - public void connectionClosedOnError() throws RemoteException { - // TODO Auto-generated method stub - } - + @Override - public void onConnect() throws RemoteException { - // TODO Auto-generated method stub - IRoster roster = mService.getRoster(); - for (Contact contact : roster.getContactList()) { - Log.v(TAG,"Contact name " + contact.getJID() ); - } - showContactList(); + public void onStart() { + super.onStart(); + mBeemApplication.startBeemService(); + mBeemApplication.callWhenServiceConnected(mHandler, new Runnable() { + @Override + public void run() { + mService = mBeemApplication.getXmppFacade(); + try { + showContactList(mService.getRoster().getContactList(), + mService.getRoster().getContactList()); + } catch (RemoteException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + }); } - @Override - public void reconnectingIn(int seconds) throws RemoteException { - // TODO Auto-generated method stub - + private void showContactList(List listGroup, + List listContact) { + ExpandableListAdapter Adapter; + + List> groupData = new ArrayList>(); + List>> childData = new ArrayList>>(); + + if (listGroup.size() == 0) + listGroup.add(new Contact()); + for (int i = 0; i < listGroup.size() ; i++) { + Map curGroupMap = new HashMap(); + + groupData.add(curGroupMap); + curGroupMap.put("NAME", "Default"); + + List> children = new ArrayList>(); + for (int j = 0; j < listContact.size() ; ++j) { + Map curChildMap = new HashMap(); + children.add(curChildMap); + curChildMap.put("NAME_CHILD", listContact.get(j).getJID()); + curChildMap.put("MSG", "Taper votre message perso"); + } + childData.add(children); + } + + Adapter = new ContactExpandableListAdapter(this, groupData, + R.layout.contactlistgroup, new String[] { "NAME" }, + new int[] { R.id.textgroup }, childData, + R.layout.contactlistcontact, + new String[] { "NAME_CHILD", "MSG" }, new int[] { + R.id.textchild1, R.id.textchild2, R.id.avatar }); + setListAdapter(Adapter); + } + + /** + * A simple adapter which allows you to bind data to specific Views defined + * within the layout of an Expandable Lists children (Implement + * getGroupView() to define the layout of parents) + */ + public class ContactExpandableListAdapter extends + SimpleExpandableListAdapter { + + private List>> mChildData; + private String[] mChildFrom; + private int[] mChildTo; + + public ContactExpandableListAdapter(Context context, + List> groupData, int groupLayout, + String[] groupFrom, int[] groupTo, + List>> childData, + int childLayout, String[] childFrom, int[] childTo) { + super(context, groupData, groupLayout, groupFrom, groupTo, + childData, childLayout, childFrom, childTo); + + mChildData = childData; + mChildFrom = childFrom; + mChildTo = childTo; + + } + + @Override + public View getChildView(int groupPosition, int childPosition, + boolean isLastChild, View convertView, ViewGroup parent) { + + View v; + if (convertView == null) { + v = newChildView(isLastChild, parent); + } else { + v = convertView; + } + bindView(v, mChildData.get(groupPosition).get(childPosition), + mChildFrom, mChildTo, groupPosition, childPosition); + return v; + } + + // This method binds my data to the Views specified in the child + // xmllayout + private void bindView(View view, Map data, String[] from, + int[] to, int groupPosition, int childPosition) { + // Apply TextViews + TextView v1 = (TextView) view.findViewById(to[0]); + if (v1 != null) { + Log.i("CONTACT LIST 1", (String) data.get(from[0]) + " " + + to[0]); + v1.setText((String) data.get(from[0])); + } + TextView v2 = (TextView) view.findViewById(to[1]); + if (v2 != null) { + Log.i("CONTACT LIST 2", (String) data.get(from[1]) + " " + + to[1]); + v2.setText((String) data.get(from[1])); + } + // Apply ImageView + ImageView imgV = (ImageView) view.findViewById(to[2]); + if (imgV != null) { + Drawable avatar = (Drawable) getResources().getDrawable( + R.drawable.avatar); + imgV.setImageDrawable(avatar); + } + } } - @Override - public void reconnectionFailed() throws RemoteException { - // TODO Auto-generated method stub - - } - - @Override - public void reconnectionSuccessful() throws RemoteException { - // TODO Auto-generated method stub - - } - - } - }