Contact List OK.
authormarseille@marseille-desktop
Thu, 19 Mar 2009 22:27:28 +0100
changeset 21 b9f4a0ef574a
parent 19 213b84d2e743
child 22 280112cd9602
Contact List OK. A faire jolie ... Je me comprend !
AndroidManifest.xml
res/drawable/avatar.png
res/layout/contactlist.xml
res/layout/contactlistgroup.xml
src/com/beem/project/beem/Beem.java
src/com/beem/project/beem/BeemService.java
src/com/beem/project/beem/UIContactList.java
src/com/beem/project/beem/service/IXMPPFacade.aidl
--- a/AndroidManifest.xml	Thu Mar 19 12:40:29 2009 +0100
+++ b/AndroidManifest.xml	Thu Mar 19 22:27:28 2009 +0100
@@ -11,6 +11,8 @@
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
+	<activity android:name=".UIContactList" android:label="@string/app_name"/>
+        
     <service android:name="BeemService" android:enabled="true" android:label="Beem Service" android:permission="com.beem.project.beem.BEEM_SERVICE"><intent-filter><action android:name="com.beem.project.beem.BeemService"></action>
 </intent-filter>
 </service>
Binary file res/drawable/avatar.png has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/res/layout/contactlist.xml	Thu Mar 19 22:27:28 2009 +0100
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ 	android:layout_width="fill_parent"
+    android:layout_height="wrap_content"
+    android:orientation="vertical">
+                    	         	
+	<ImageView android:id="@+id/avatar"
+		android:src="@drawable/avatar"
+		android:paddingLeft="50sp"
+		android:layout_width="wrap_content"
+		android:layout_height="wrap_content"/>
+ 
+     <TextView android:id="@+id/textchild"
+         android:textSize="16sp"         
+         android:paddingLeft="100sp"
+         android:layout_width="fill_parent"
+         android:layout_height="wrap_content"/>
+		
+ </LinearLayout>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/res/layout/contactlistgroup.xml	Thu Mar 19 22:27:28 2009 +0100
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+	android:layout_width="fill_parent"
+    android:layout_height="wrap_content"
+    android:orientation="vertical">
+
+	<TextView android:id="@+id/textgroup"
+		android:height="50sp"
+		android:textSize="20sp"
+       	android:textStyle="bold"
+       	android:paddingTop="10sp"
+       	android:paddingLeft="40sp"
+       	android:layout_width="fill_parent"
+       	android:layout_height="wrap_content" />	
+
+ </LinearLayout>
--- a/src/com/beem/project/beem/Beem.java	Thu Mar 19 12:40:29 2009 +0100
+++ b/src/com/beem/project/beem/Beem.java	Thu Mar 19 22:27:28 2009 +0100
@@ -4,6 +4,7 @@
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.os.Bundle;
+import android.util.Log;
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
@@ -25,13 +26,13 @@
         setContentView(R.layout.main);
         mSettings = getSharedPreferences(getString(R.string.PreferenceFileName), MODE_PRIVATE);
         showJID();
+
         Button btConnection = (Button) findViewById(R.id.connection);
         btConnection.setOnClickListener(new OnClickListener() {
-
+;
 	    @Override
 	    public void onClick(View v) {
-		// TODO Auto-generated method stub
-		startService(new Intent(Beem.this,BeemService.class));
+		startActivity(new Intent(Beem.this, UIContactList.class));
 	    }
         });
     }
--- a/src/com/beem/project/beem/BeemService.java	Thu Mar 19 12:40:29 2009 +0100
+++ b/src/com/beem/project/beem/BeemService.java	Thu Mar 19 22:27:28 2009 +0100
@@ -8,96 +8,125 @@
 import org.jivesoftware.smack.XMPPConnection;
 import org.jivesoftware.smack.XMPPException;
 
-import com.beem.project.beem.service.IXMPPFacade;
-
 import android.app.Notification;
 import android.app.NotificationManager;
 import android.app.PendingIntent;
 import android.app.Service;
 import android.content.Intent;
 import android.content.SharedPreferences;
-import android.content.res.Resources;
 import android.os.IBinder;
 import android.os.RemoteException;
-import android.widget.TextView;
 import android.widget.Toast;
 
+import com.beem.project.beem.service.IXMPPFacade;
+
 /**
  * @author darisk
- *
+ * 
  */
 public class BeemService extends Service {
 
     private NotificationManager notificationManager;
 
     private XMPPConnection connection;
+
     private SharedPreferences settings;
+
     private String login;
+
     private String password;
+
     private String host;
-    
+
     private IXMPPFacade.Stub bind = new IXMPPFacade.Stub() {
-    
+
         @Override
         public List<String> getContactList() throws RemoteException {
-    	// TODO Auto-generated method stub
-    	return null;
+            return null;
+        }
+
+        @Override
+        public List<String> getGroupList() throws RemoteException {
+            return null;
         }
     };
-    
-    /* (non-Javadoc)
+
+    /*
+     * (non-Javadoc)
+     * 
      * @see android.app.Service#onBind(android.content.Intent)
      */
     @Override
     public IBinder onBind(Intent arg0) {
-	// TODO Auto-generated method stub
-	return null;
+        try {
+            connection = new XMPPConnection("10.0.2.2"); // address du pc host
+            // de l'emulateur
+            connection.connect();
+            connection.login(login, password);
+            notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
+            showBasicNotification(R.string.BeemServiceCreated);
+        } catch (XMPPException e) {
+            // TODO Auto-generated catch block
+            Toast toast = Toast.makeText(this, "ERREUR " + e.getMessage(),
+                    Toast.LENGTH_LONG);
+            toast.show();
+            notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
+            showBasicNotification(R.string.PreferenceFileName);
+        }
+        return bind;
     }
-    
+
     private void showBasicNotification(int stringResource) {
-	String text = (String) getText(stringResource);
-	Notification notif = new Notification(R.drawable.logo, text, System.currentTimeMillis());
-	notif.defaults = Notification.DEFAULT_ALL;
-	notif.setLatestEventInfo(this, text, text, PendingIntent.getActivity(this, 0, new Intent(),0));
-	notificationManager.notify(stringResource, notif);
-	Toast toast = Toast.makeText(this, R.string.BeemServiceCreated, Toast.LENGTH_LONG);
-	toast.show();
+        String text = (String) getText(stringResource);
+        Notification notif = new Notification(R.drawable.logo, text, System
+                .currentTimeMillis());
+        notif.defaults = Notification.DEFAULT_ALL;
+        notif.setLatestEventInfo(this, text, text, PendingIntent.getActivity(
+                this, 0, new Intent(), 0));
+        notificationManager.notify(stringResource, notif);
+        Toast toast = Toast.makeText(this, R.string.BeemServiceCreated,
+                Toast.LENGTH_LONG);
+        toast.show();
     }
-    
+
     @Override
-    public void onCreate(){
-	super.onCreate();
-	settings = getSharedPreferences(getString(R.string.PreferenceFileName),	MODE_PRIVATE);
-	login = settings.getString(getString(R.string.PreferenceLoginKey), "");
-	password = settings.getString(getString(R.string.PreferencePasswordKey), "");
-	host = settings.getString(getString(R.string.PreferenceHostKey), "");
+    public void onCreate() {
+        super.onCreate();
+        settings = getSharedPreferences(getString(R.string.PreferenceFileName),
+                MODE_PRIVATE);
+        login = settings.getString(getString(R.string.PreferenceLoginKey), "");
+        password = settings.getString(
+                getString(R.string.PreferencePasswordKey), "");
+        host = settings.getString(getString(R.string.PreferenceHostKey), "");
     }
-    
+
     @Override
     public void onStart(Intent intent, int startId) {
-	try {
-	    connection = new XMPPConnection("10.0.2.2"); // address du pc host de l'emulateur
-	    connection.connect();
-	    connection.login(login, password);
-	    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
-	    showBasicNotification(R.string.BeemServiceCreated);
-	} catch (XMPPException e) {
-	    // TODO Auto-generated catch block
-	    Toast toast = Toast.makeText(this, "ERREUR " + e.getMessage(), Toast.LENGTH_LONG);
-	    toast.show();
-	    e.printStackTrace();
-	}
+        try {
+            connection = new XMPPConnection("10.0.2.2"); // address du pc host
+            // de l'emulateur
+            connection.connect();
+            connection.login(login, password);
+            notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
+            showBasicNotification(R.string.BeemServiceCreated);
+        } catch (XMPPException e) {
+            // TODO Auto-generated catch block
+            Toast toast = Toast.makeText(this, "ERREUR " + e.getMessage(),
+                    Toast.LENGTH_LONG);
+            toast.show();
+            notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
+            showBasicNotification(R.string.PreferenceFileName);
+        }
     }
-    
+
     private void closeConnection() {
-	if (connection != null)
-	    connection.disconnect();
+        if (connection != null)
+            connection.disconnect();
     }
-    
+
     @Override
     public void onDestroy() {
-	closeConnection();
-	showBasicNotification(R.string.BeemServiceDestroyed); 
-    }
+        closeConnection();
+            }
 
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/UIContactList.java	Thu Mar 19 22:27:28 2009 +0100
@@ -0,0 +1,81 @@
+package com.beem.project.beem;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.beem.project.beem.service.IXMPPFacade;
+
+import android.app.ExpandableListActivity;
+import android.content.ComponentName;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.os.Bundle;
+import android.os.IBinder;
+import android.util.Log;
+import android.widget.ExpandableListAdapter;
+import android.widget.SimpleExpandableListAdapter;
+
+public class UIContactList extends ExpandableListActivity {
+
+    private IXMPPFacade mService = null;
+
+    @Override
+    public void onCreate(Bundle saveBundle) {
+        super.onCreate(saveBundle);
+        bindService(new Intent(this, BeemService.class), mConnection,
+                BIND_AUTO_CREATE | BIND_DEBUG_UNBIND);
+        showContactList();
+    }
+
+    private void showContactList() {
+        ExpandableListAdapter Adapter;
+        List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
+        List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();
+
+        for (int i = 0; i < 2; i++) {
+            Map<String, String> curGroupMap = new HashMap<String, String>();
+            groupData.add(curGroupMap);
+            curGroupMap.put("NAME", "Group " + i);
+            
+            List<Map<String, String>> children = new ArrayList<Map<String, String>>();
+            for (int j = 0; j < 5; j++) {
+                Map<String, String> curChildMap = new HashMap<String, String>();
+                children.add(curChildMap);
+                curChildMap.put("NAME 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);
+            /*
+             * mService.getGroupList(); mService.getContactList();
+             */
+            showContactList();
+        }
+
+        @Override
+        public void onServiceDisconnected(ComponentName name) {
+        }
+
+    };
+
+    @Override
+    public void onDestroy() {
+        super.onDestroy();
+        unbindService(mConnection);
+    }
+
+}
--- a/src/com/beem/project/beem/service/IXMPPFacade.aidl	Thu Mar 19 12:40:29 2009 +0100
+++ b/src/com/beem/project/beem/service/IXMPPFacade.aidl	Thu Mar 19 22:27:28 2009 +0100
@@ -7,5 +7,6 @@
   //  org.jivesoftware.smack.XMPPConnection getXMPPConnection();
   
   List<String> getContactList();
+  List<String> getGroupList();
 
 }