Added custom adapter for AccountSelectionSpinner and async details loading
diff --git a/res/layout/item_account.xml b/res/layout/item_account.xml
new file mode 100644
index 0000000..2ebaca8
--- /dev/null
+++ b/res/layout/item_account.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content" >
+
+    <TextView
+        android:id="@+id/account_alias"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentLeft="true"
+        android:layout_alignParentTop="true"
+        android:textAppearance="?android:attr/textAppearanceLarge" />
+
+    <TextView
+        android:id="@+id/account_host"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentLeft="true"
+        android:layout_below="@+id/account_alias"
+        android:textAppearance="?android:attr/textAppearanceSmall" />
+    
+    <RadioButton 
+        android:id="@+id/account_checked"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:focusable="false"
+        android:clickable="false"
+        android:layout_alignParentRight="true"
+        android:layout_centerVertical="true"/>
+
+</RelativeLayout>
\ No newline at end of file
diff --git a/src/com/savoirfairelinux/sflphone/account/AccountSelectionSpinner.java b/src/com/savoirfairelinux/sflphone/account/AccountSelectionSpinner.java
index 9642fdf..f0f63cc 100644
--- a/src/com/savoirfairelinux/sflphone/account/AccountSelectionSpinner.java
+++ b/src/com/savoirfairelinux/sflphone/account/AccountSelectionSpinner.java
@@ -32,23 +32,26 @@
 
 import java.util.ArrayList;
 
-import com.savoirfairelinux.sflphone.client.receiver.AccountListReceiver;
-
 import android.content.Context;
 import android.util.AttributeSet;
 import android.util.Log;
 import android.view.View;
 import android.widget.AdapterView;
-import android.widget.ArrayAdapter;
+import android.widget.RadioButton;
 import android.widget.Spinner;
-import android.widget.TextView;
+
+import com.savoirfairelinux.sflphone.R;
+import com.savoirfairelinux.sflphone.adapters.AccountSelectionAdapter;
+import com.savoirfairelinux.sflphone.client.receiver.AccountListReceiver;
+import com.savoirfairelinux.sflphone.service.ISipService;
 
 public class AccountSelectionSpinner extends Spinner implements AccountManagementUI {
-    private static final String TAG = "AccountSelectionButton";
+    private static final String TAG = AccountSelectionSpinner.class.getSimpleName();
+    public static final String DEFAULT_ACCOUNT_ID = "IP2IP";
     private Context mContext;
-    private ArrayList<String> mList = new ArrayList<String>();
     private AccountListReceiver mAccountList = null;
-    ArrayAdapter mListAdapter;
+    AccountSelectionAdapter mAdapter;
+    ISipService serviceRef;
 
     public AccountSelectionSpinner(Context context) {
         super(context);
@@ -60,27 +63,26 @@
         super(context, attrs);
         mContext = context;
 
-
     }
 
     public AccountSelectionSpinner(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
         mContext = context;
-        mListAdapter = new ArrayAdapter(mContext, android.R.layout.simple_expandable_list_item_1, mList.toArray());
 
-        setOnItemSelectedListener(onClick);
-        setAdapter(mListAdapter);
     }
 
     private AdapterView.OnItemSelectedListener onClick = new AdapterView.OnItemSelectedListener() {
 
         @Override
-        public void onItemSelected(AdapterView<?> arg0, View view, int arg2, long arg3) {
+        public void onItemSelected(AdapterView<?> arg0, View view, int pos, long arg3) {
             // public void onClick(DialogInterface dialog, int which) {
 
-            Log.i(TAG, "Selected Account: " + ((TextView) view).getText());
-            // mButton.setText(((TextView)view).getText());
-            accountSelectedNotifyAccountList(((TextView) view).getText().toString());
+            Log.i(TAG, "Selected Account: " + mAdapter.getItem(pos));
+            if (null != view) {
+                ((RadioButton) view.findViewById(R.id.account_checked)).toggle();
+            }
+            mAdapter.setSelectedAccount(pos);
+            accountSelectedNotifyAccountList(mAdapter.getItem(pos));
             // setSelection(cursor.getPosition(),true);
 
         }
@@ -93,16 +95,23 @@
 
     };
 
+    public void populate(ISipService service, ArrayList<String> accountList) {
+        Log.i(TAG, "populate");
+        serviceRef = service;
+        mAdapter = new AccountSelectionAdapter(mContext, serviceRef, accountList);
+        setOnItemSelectedListener(onClick);
+        setAdapter(mAdapter);
+    }
 
     /****************************************
      * AccountManagementUI Interface
      ****************************************/
-    
+
     @Override
     public void setAccountList(AccountListReceiver accountList) {
-        Log.i(TAG,"setAccountList");
+        Log.i(TAG, "setAccountList");
         mAccountList = accountList;
-        
+
     }
 
     @Override
@@ -115,16 +124,15 @@
 
     @Override
     public void setSelectedAccount(String accountID) {
-        Log.i(TAG,"Account Selected");
+        Log.i(TAG, "Account Selected");
         // setText(accountID);
     }
 
     @Override
     public void accountAdded(ArrayList<String> newList) {
-        mListAdapter = new ArrayAdapter(mContext, android.R.layout.simple_expandable_list_item_1, newList.toArray());
-
+        mAdapter = new AccountSelectionAdapter(mContext, serviceRef, newList);
         setOnItemSelectedListener(onClick);
-        setAdapter(mListAdapter);
+        setAdapter(mAdapter);
         // Log.i(TAG, "Account added");
         // mList = newList;
         //
@@ -135,11 +143,12 @@
 
     @Override
     public void accountRemoved() {
-        Log.i(TAG,"Account Removed");
+        Log.i(TAG, "Account Removed");
     }
 
     @Override
     public void accountUpdated() {
-        Log.i(TAG,"Account Updated");
+        Log.i(TAG, "Account Updated");
     }
+
 }
diff --git a/src/com/savoirfairelinux/sflphone/adapters/AccountSelectionAdapter.java b/src/com/savoirfairelinux/sflphone/adapters/AccountSelectionAdapter.java
new file mode 100644
index 0000000..7f4b099
--- /dev/null
+++ b/src/com/savoirfairelinux/sflphone/adapters/AccountSelectionAdapter.java
@@ -0,0 +1,232 @@
+package com.savoirfairelinux.sflphone.adapters;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Stack;
+
+import android.app.Activity;
+import android.content.Context;
+import android.net.Uri;
+import android.os.RemoteException;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.RadioButton;
+import android.widget.TextView;
+
+import com.savoirfairelinux.sflphone.R;
+import com.savoirfairelinux.sflphone.account.AccountDetailBasic;
+import com.savoirfairelinux.sflphone.service.ISipService;
+
+public class AccountSelectionAdapter extends BaseAdapter {
+
+    private static final String TAG = AccountSelectionAdapter.class.getSimpleName();
+
+    ArrayList<String> accountIDs;
+    Context mContext;
+    AccountManager accManager;
+    ISipService service;
+    int selectedAccount = 0;
+
+    public AccountSelectionAdapter(Context cont, ISipService s, ArrayList<String> newList) {
+        super();
+        accountIDs = newList;
+        mContext = cont;
+        service = s;
+        accManager = new AccountManager(mContext);
+    }
+
+    @Override
+    public int getCount() {
+        return accountIDs.size();
+    }
+
+    @Override
+    public String getItem(int pos) {
+        return accountIDs.get(pos);
+    }
+
+    @Override
+    public long getItemId(int pos) {
+        return 0;
+    }
+
+    @Override
+    public View getView(int pos, View convertView, ViewGroup parent) {
+        View rowView = convertView;
+        AccountView entryView = null;
+
+        if (rowView == null) {
+            LayoutInflater inflater = LayoutInflater.from(mContext);
+            rowView = inflater.inflate(R.layout.item_account, null);
+
+            entryView = new AccountView();
+            entryView.alias = (TextView) rowView.findViewById(R.id.account_alias);
+            entryView.host = (TextView) rowView.findViewById(R.id.account_host);
+            entryView.select = (RadioButton) rowView.findViewById(R.id.account_checked);
+            rowView.setTag(entryView);
+        } else {
+            entryView = (AccountView) rowView.getTag();
+        }
+
+        accManager.displayAccountDetails(accountIDs.get(pos), entryView);
+        if(pos == selectedAccount){
+            entryView.select.setChecked(true);
+        }
+
+        return rowView;
+    }
+
+    /*********************
+     * ViewHolder Pattern
+     *********************/
+    public class AccountView {
+        public TextView alias;
+        public TextView host;
+        public RadioButton select;
+    }
+
+    /**
+     * Asynchronous account details retriever
+     */
+    public class AccountManager {
+
+        // private static final String TAG = ImageManager.class.getSimpleName();
+
+        private HashMap<String, HashMap<String, String>> accountMap = new HashMap<String, HashMap<String, String>>();
+        private AccountQueue accountQueue = new AccountQueue();
+        private Thread accountLoaderThread = new Thread(new AccountQueueManager());
+
+
+        public AccountManager(Context context) {
+            accountLoaderThread.setPriority(Thread.NORM_PRIORITY - 1);
+
+        }
+
+        public void displayAccountDetails(String id, AccountView account) {
+
+            if (accountMap.containsKey(id)) {
+
+                HashMap<String, String> details = accountMap.get(id);
+                account.alias.setText(details.get(AccountDetailBasic.CONFIG_ACCOUNT_ALIAS));
+                account.host.setText(details.get(AccountDetailBasic.CONFIG_ACCOUNT_HOSTNAME));
+
+            } else {
+                queueAccount(id, account);
+            }
+        }
+
+        private void queueAccount(String id, AccountView row) {
+            // This ImageView might have been used for other images, so we clear
+            // the queue of old tasks before starting.
+            accountQueue.Clean(row);
+            AccountRef p = new AccountRef(id, row);
+
+            synchronized (accountQueue.accountRefsStack) {
+                accountQueue.accountRefsStack.push(p);
+                accountQueue.accountRefsStack.notifyAll();
+            }
+
+            // Start thread if it's not started yet
+            if (accountLoaderThread.getState() == Thread.State.NEW) {
+                accountLoaderThread.start();
+            }
+        }
+
+        /** Classes **/
+
+        private class AccountRef {
+            public String accountID;
+            public AccountView row;
+
+            public AccountRef(String u, AccountView i) {
+                accountID = u;
+                row = i;
+            }
+        }
+
+        private class AccountQueue {
+            private Stack<AccountRef> accountRefsStack = new Stack<AccountRef>();
+
+            // removes all instances of this account
+            public void Clean(AccountView view) {
+
+                for (int i = 0; i < accountRefsStack.size();) {
+                    if (accountRefsStack.get(i).row == view)
+                        accountRefsStack.remove(i);
+                    else
+                        ++i;
+                }
+            }
+        }
+
+        private class AccountQueueManager implements Runnable {
+            @Override
+            public void run() {
+                try {
+                    while (true) {
+                        // Thread waits until there are accountsID in the queue to be retrieved
+                        if (accountQueue.accountRefsStack.size() == 0) {
+                            synchronized (accountQueue.accountRefsStack) {
+                                accountQueue.accountRefsStack.wait();
+                            }
+                        }
+
+                        // When we have accounts to load
+                        if (accountQueue.accountRefsStack.size() != 0) {
+                            AccountRef accountToLoad;
+
+                            synchronized (accountQueue.accountRefsStack) {
+                                accountToLoad = accountQueue.accountRefsStack.pop();
+                            }
+
+                            HashMap<String, String> details = (HashMap<String, String>) service.getAccountDetails(accountToLoad.accountID);
+                            accountMap.put(accountToLoad.accountID, details);
+                            AccountDisplayer accDisplayer = new AccountDisplayer(details, accountToLoad.row);
+                            Activity a = (Activity) mContext;
+
+                            a.runOnUiThread(accDisplayer);
+
+                        }
+
+                        if (Thread.interrupted())
+                            break;
+                    }
+                } catch (InterruptedException e) {
+                    Log.e(TAG, e.toString());
+                } catch (RemoteException e) {
+                    Log.e(TAG, e.toString());
+                }
+            }
+        }
+
+        // Used to display details in the UI thread
+        private class AccountDisplayer implements Runnable {
+            HashMap<String, String> displayDetails;
+            AccountView displayRow;
+
+            public AccountDisplayer(HashMap<String, String> details, AccountView row) {
+                displayRow = row;
+                displayDetails = details;
+            }
+
+            public void run() {
+                displayRow.alias.setText(displayDetails.get(AccountDetailBasic.CONFIG_ACCOUNT_ALIAS));
+                displayRow.host.setText(displayDetails.get(AccountDetailBasic.CONFIG_ACCOUNT_HOSTNAME));
+            }
+        }
+
+        public void removeFromCache(Uri uri) {
+            if (accountMap.containsKey(uri)) {
+                accountMap.remove(uri);
+            }
+        }
+    }
+
+    public void setSelectedAccount(int pos) {
+       selectedAccount = pos;
+    }
+
+}
diff --git a/src/com/savoirfairelinux/sflphone/adapters/CallElementAdapter.java b/src/com/savoirfairelinux/sflphone/adapters/CallElementAdapter.java
new file mode 100644
index 0000000..5196cf8
--- /dev/null
+++ b/src/com/savoirfairelinux/sflphone/adapters/CallElementAdapter.java
@@ -0,0 +1,87 @@
+package com.savoirfairelinux.sflphone.adapters;
+
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.ImageButton;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import com.savoirfairelinux.sflphone.R;
+import com.savoirfairelinux.sflphone.model.SipCall;
+
+/**
+ * A CursorAdapter that creates and update call elements using corresponding contact infos. TODO: handle contact list separatly to allow showing
+ * synchronized contacts on Call cards with multiple contacts etc.
+ */
+public class CallElementAdapter extends ArrayAdapter {
+    private ExecutorService infos_fetcher = Executors.newCachedThreadPool();
+    private Context mContext;
+    private final List mCallList;
+    private static final String CURRENT_STATE_LABEL = "    CURRENT STATE: ";
+
+    public CallElementAdapter(Context context, List callList) {
+        super(context, R.layout.item_contact, callList);
+        mContext = context;
+        mCallList = callList;
+    }
+
+    @Override
+    public View getView(int position, View convertView, ViewGroup parent) {
+        View rowView = convertView;
+        CallElementView entryView = null;
+
+        if (rowView == null) {
+            // Get a new instance of the row layout view
+            LayoutInflater inflater = LayoutInflater.from(mContext);
+            rowView = inflater.inflate(R.layout.item_contact, null);
+
+            // Hold the view objects in an object
+            // so they don't need to be re-fetched
+            entryView = new CallElementView();
+            entryView.toggleButton = (ImageButton) rowView.findViewById(R.id.toggleButton1);
+            entryView.button = (Button) rowView.findViewById(R.id.button2);
+            entryView.photo = (ImageView) rowView.findViewById(R.id.photo);
+            entryView.displayName = (TextView) rowView.findViewById(R.id.display_name);
+            entryView.phones = (TextView) rowView.findViewById(R.id.phones);
+            entryView.state = (TextView) rowView.findViewById(R.id.callstate);
+
+            // Cache the view obects in the tag
+            // so they can be re-accessed later
+            rowView.setTag(entryView);
+        } else {
+            entryView = (CallElementView) rowView.getTag();
+        }
+
+        // Transfer the stock data from the data object
+        // to the view objects
+        SipCall call = (SipCall) mCallList.get(position);
+        call.setAssociatedRowView(rowView);
+        entryView.displayName.setText(call.getDisplayName());
+        entryView.phones.setText(call.getPhone());
+        entryView.state.setText(CURRENT_STATE_LABEL + call.getCallStateString());
+
+        return rowView;
+    }
+
+    /*********************
+     * ViewHolder Pattern
+     *********************/
+    public class CallElementView {
+        protected ImageButton toggleButton;
+        protected Button button;
+        protected ImageView photo;
+        protected TextView displayName;
+        protected TextView phones;
+        public TextView state;
+    }
+    
+    
+}
diff --git a/src/com/savoirfairelinux/sflphone/client/SFLPhoneHomeActivity.java b/src/com/savoirfairelinux/sflphone/client/SFLPhoneHomeActivity.java
index ad06924..226a4a3 100644
--- a/src/com/savoirfairelinux/sflphone/client/SFLPhoneHomeActivity.java
+++ b/src/com/savoirfairelinux/sflphone/client/SFLPhoneHomeActivity.java
@@ -263,9 +263,6 @@
 			unbindService(mConnection);
 			mBound = false;
 		}
-		// Log.i(TAG, "onDestroy: stopping SipService...");
-		// stopService(new Intent(this, SipService.class));
-		// mApplication.setServiceRunning(false);
 
 		/* unregister broadcast receiver */
 		LocalBroadcastManager.getInstance(this).unregisterReceiver(mCallList);
@@ -273,6 +270,8 @@
 
 		super.onDestroy();
 	}
+	
+	
 
 	/** Defines callbacks for service binding, passed to bindService() */
 	private ServiceConnection mConnection = new ServiceConnection() {
@@ -283,6 +282,7 @@
 			mApplication.setSipService(service);
 			mBound = true;
 			mAccountList.setSipService(service);
+			mCallElementList.onServiceSipBinded(service);
 			Log.d(TAG, "Service connected service=" + service);
 		}
 
@@ -294,25 +294,6 @@
 		}
 	};
 
-	// private void startSipService() {
-	// Thread thread = new Thread("StartSFLphoneService") {
-	// public void run() {
-	// Intent sipServiceIntent = new Intent(SFLPhoneHome.this, SipService.class);
-	// //sipServiceIntent.putExtra(ServiceConstants.EXTRA_OUTGOING_ACTIVITY, new ComponentName(SFLPhoneHome.this, SFLPhoneHome.class));
-	// startService(sipServiceIntent);
-	// mApplication.setServiceRunning(true);
-	// };
-	// };
-	// try {
-	// thread.start();
-	// } catch (IllegalThreadStateException e) {
-	// AlertDialog.Builder builder = new AlertDialog.Builder(this);
-	// builder.setMessage("Cannot start SFLPhone SipService!");
-	// AlertDialog alert = builder.create();
-	// alert.show();
-	// finish();
-	// }
-	// }
 
 	@Override
 	public boolean onOptionsItemSelected(MenuItem item) {
diff --git a/src/com/savoirfairelinux/sflphone/fragments/AccountManagementFragment.java b/src/com/savoirfairelinux/sflphone/fragments/AccountManagementFragment.java
index 4881381..e4d72c9 100644
--- a/src/com/savoirfairelinux/sflphone/fragments/AccountManagementFragment.java
+++ b/src/com/savoirfairelinux/sflphone/fragments/AccountManagementFragment.java
@@ -180,8 +180,24 @@
         } catch (RemoteException e) {
             Log.e(TAG, "Cannot call service method", e);
         }
-
     }
+    
+    private void setAccountDetails(String accountID, HashMap<String, String> accountDetails) {
+        try {
+            service.setAccountDetails(accountID, accountDetails);
+        } catch (RemoteException e) {
+            Log.e(TAG, "Cannot call service method", e);
+        }
+    }
+    
+    private void deleteSelectedAccount(String accountID) {
+        Log.i(TAG, "DeleteSelectedAccount");
+        try {
+            service.removeAccount(accountID);
+        } catch (RemoteException e) {
+            Log.e(TAG, "Cannot call service method", e);
+        }
+    };
 
     private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
         @Override
@@ -256,14 +272,7 @@
         startActivityForResult(intent, ACCOUNT_EDIT_REQUEST);
     }
 
-    private void deleteSelectedAccount(String accountID) {
-        Log.i(TAG, "DeleteSelectedAccount");
-        try {
-            service.removeAccount(accountID);
-        } catch (RemoteException e) {
-            Log.e(TAG, "Cannot call service method", e);
-        }
-    };
+    
 
     private ArrayList<String> getAccountList() {
         ArrayList<String> accountList = null;
@@ -290,13 +299,7 @@
         return accountDetails;
     }
 
-    private void setAccountDetails(String accountID, HashMap<String, String> accountDetails) {
-        try {
-            service.setAccountDetails(accountID, accountDetails);
-        } catch (RemoteException e) {
-            Log.e(TAG, "Cannot call service method", e);
-        }
-    }
+    
 
     public PreferenceScreen getAccountListPreferenceScreen() {
         Activity currentContext = getActivity();
diff --git a/src/com/savoirfairelinux/sflphone/fragments/CallElementListFragment.java b/src/com/savoirfairelinux/sflphone/fragments/CallElementListFragment.java
index 48535cd..fb9f83b 100644
--- a/src/com/savoirfairelinux/sflphone/fragments/CallElementListFragment.java
+++ b/src/com/savoirfairelinux/sflphone/fragments/CallElementListFragment.java
@@ -33,8 +33,6 @@
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
 
 import android.app.Activity;
 import android.app.AlertDialog;
@@ -51,6 +49,7 @@
 import android.graphics.BitmapFactory;
 import android.net.Uri;
 import android.os.Bundle;
+import android.os.RemoteException;
 import android.provider.ContactsContract;
 import android.provider.ContactsContract.CommonDataKinds;
 import android.provider.ContactsContract.CommonDataKinds.Phone;
@@ -62,19 +61,14 @@
 import android.view.ViewGroup;
 import android.widget.AdapterView;
 import android.widget.AdapterView.OnItemLongClickListener;
-import android.widget.ArrayAdapter;
-import android.widget.Button;
-import android.widget.ImageButton;
-import android.widget.ImageView;
 import android.widget.ListView;
-import android.widget.TextView;
 
 import com.savoirfairelinux.sflphone.R;
 import com.savoirfairelinux.sflphone.account.AccountSelectionSpinner;
+import com.savoirfairelinux.sflphone.adapters.CallElementAdapter;
 import com.savoirfairelinux.sflphone.client.SFLPhoneHomeActivity;
 import com.savoirfairelinux.sflphone.client.SFLphoneApplication;
 import com.savoirfairelinux.sflphone.client.receiver.AccountListReceiver;
-import com.savoirfairelinux.sflphone.model.ContactManager;
 import com.savoirfairelinux.sflphone.model.SipCall;
 import com.savoirfairelinux.sflphone.service.ISipService;
 
@@ -83,16 +77,19 @@
  */
 public class CallElementListFragment extends ListFragment implements LoaderManager.LoaderCallbacks<Cursor> {
     private static final String TAG = CallElementListFragment.class.getSimpleName();
-    private static final String CURRENT_STATE_LABEL = "    CURRENT STATE: ";
-    private ContactManager mContactManager;
+
+    // private ContactManager mContactManager;
     private CallElementAdapter mAdapter;
     private String mCurFilter;
     private SFLPhoneHomeActivity sflphoneHome;
-    private SFLphoneApplication sflphoneApplication;
+    // private SFLphoneApplication sflphoneApplication;
     private ISipService service;
-    private AccountSelectionSpinner mAccountSelectionButton;
+    private AccountSelectionSpinner mAccountSelectionSpinner;
+
     private AccountListReceiver mAccountList;
 
+    private boolean isReady = false;
+
     static final String[] CONTACTS_SUMMARY_PROJECTION = new String[] { Contacts._ID, Contacts.DISPLAY_NAME, Contacts.PHOTO_ID, Contacts.LOOKUP_KEY };
     static final String[] CONTACTS_PHONES_PROJECTION = new String[] { Phone.NUMBER, Phone.TYPE };
     static final String[] CONTACTS_SIP_PROJECTION = new String[] { SipAddress.SIP_ADDRESS, SipAddress.TYPE };
@@ -170,69 +167,6 @@
         }
     }
 
-    /**
-     * A CursorAdapter that creates and update call elements using corresponding contact infos. TODO: handle contact list separatly to allow showing
-     * synchronized contacts on Call cards with multiple contacts etc.
-     */
-    public static class CallElementAdapter extends ArrayAdapter {
-        private ExecutorService infos_fetcher = Executors.newCachedThreadPool();
-        private Context mContext;
-        private final List mCallList;
-
-        public CallElementAdapter(Context context, List callList) {
-            super(context, R.layout.item_contact, callList);
-            mContext = context;
-            mCallList = callList;
-        }
-
-        @Override
-        public View getView(int position, View convertView, ViewGroup parent) {
-            View rowView = convertView;
-            CallElementView entryView = null;
-
-            if (rowView == null) {
-                // Get a new instance of the row layout view
-                LayoutInflater inflater = LayoutInflater.from(mContext);
-                rowView = inflater.inflate(R.layout.item_contact, null);
-
-                // Hold the view objects in an object
-                // so they don't need to be re-fetched
-                entryView = new CallElementView();
-                entryView.toggleButton = (ImageButton) rowView.findViewById(R.id.toggleButton1);
-                entryView.button = (Button) rowView.findViewById(R.id.button2);
-                entryView.photo = (ImageView) rowView.findViewById(R.id.photo);
-                entryView.displayName = (TextView) rowView.findViewById(R.id.display_name);
-                entryView.phones = (TextView) rowView.findViewById(R.id.phones);
-                entryView.state = (TextView) rowView.findViewById(R.id.callstate);
-
-                // Cache the view obects in the tag
-                // so they can be re-accessed later
-                rowView.setTag(entryView);
-            } else {
-                entryView = (CallElementView) rowView.getTag();
-            }
-
-            // Transfer the stock data from the data object
-            // to the view objects
-            SipCall call = (SipCall) mCallList.get(position);
-            call.setAssociatedRowView(rowView);
-            entryView.displayName.setText(call.getDisplayName());
-            entryView.phones.setText(call.getPhone());
-            entryView.state.setText(CURRENT_STATE_LABEL + call.getCallStateString());
-
-            return rowView;
-        }
-    };
-
-    public static class CallElementView {
-        protected ImageButton toggleButton;
-        protected Button button;
-        protected ImageView photo;
-        protected TextView displayName;
-        protected TextView phones;
-        public TextView state;
-    }
-
     public CallElementListFragment() {
         super();
     }
@@ -282,8 +216,8 @@
                 Log.i(TAG, "On Long Click");
                 final CharSequence[] items = { "Hang up Call", "Send Message", "Add to Conference" };
                 final SipCall call = (SipCall) mAdapter.getItem(pos);
-                // FIXME
-                service = sflphoneApplication.getSipService();
+                // // FIXME
+                // service = sflphoneApplication.getSipService();
                 AlertDialog.Builder builder = new AlertDialog.Builder(context);
                 builder.setTitle("Action to perform with " + call.mCallInfo.mDisplayName).setCancelable(true)
                         .setItems(items, new DialogInterface.OnClickListener() {
@@ -318,12 +252,17 @@
 
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+        Log.i(TAG, "onCreateView");
         View inflatedView = inflater.inflate(R.layout.frag_call_element, container, false);
 
-        mAccountSelectionButton = (AccountSelectionSpinner) inflatedView.findViewById(R.id.account_selection_button);
-        mAccountList.addManagementUI(mAccountSelectionButton);
-        mAccountSelectionButton.setAccountList(mAccountList);
+        mAccountSelectionSpinner = (AccountSelectionSpinner) inflatedView.findViewById(R.id.account_selection_button);
+        mAccountList.addManagementUI(mAccountSelectionSpinner);
+        mAccountSelectionSpinner.setAccountList(mAccountList);
 
+        isReady = true;
+        if (service != null) {
+            onServiceSipBinded(service);
+        }
         return inflatedView;
     }
 
@@ -340,7 +279,7 @@
     @Override
     public Loader<Cursor> onCreateLoader(int id, Bundle args) {
 
-        Log.i(TAG,"onCreateLoader");
+        Log.i(TAG, "onCreateLoader");
         // return new CursorLoader(getActivity(), CommonDataKinds.Phone.CONTENT_URI, null,null,null, null);
 
         // This is called when a new Loader needs to be created. This
@@ -366,6 +305,7 @@
 
     @Override
     public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
+        Log.i(TAG, "onLoadFinished");
         // Swap the new cursor in. (The framework will take care of closing the
         // old cursor once we return.)
         // mAdapter.swapCursor(data);
@@ -383,4 +323,25 @@
         // longer using it.
         // mAdapter.swapCursor(null);
     }
+
+    /**
+     * Called by activity to pass a reference to sipservice to Fragment.
+     * 
+     * @param isip
+     */
+    public void onServiceSipBinded(ISipService isip) {
+
+        if (isReady) {
+            service = isip;
+            ArrayList<String> accountList;
+            try {
+                accountList = (ArrayList<String>) service.getAccountList();
+                mAccountSelectionSpinner.populate(service, accountList);
+            } catch (RemoteException e) {
+                Log.i(TAG, e.toString());
+            }
+        }
+
+    }
+
 }
diff --git a/src/com/savoirfairelinux/sflphone/model/SipCall.java b/src/com/savoirfairelinux/sflphone/model/SipCall.java
index 0466cdf..679d2df 100644
--- a/src/com/savoirfairelinux/sflphone/model/SipCall.java
+++ b/src/com/savoirfairelinux/sflphone/model/SipCall.java
@@ -30,21 +30,22 @@
  */
 package com.savoirfairelinux.sflphone.model;
 
+import java.util.ArrayList;
+
 import android.content.Context;
 import android.content.Intent;
 import android.os.Bundle;
-import android.os.Parcelable;
 import android.os.Parcel;
+import android.os.Parcelable;
 import android.os.RemoteException;
 import android.util.Log;
 import android.view.View;
-import java.util.ArrayList;
 
-import com.savoirfairelinux.sflphone.service.ISipService;
+import com.savoirfairelinux.sflphone.adapters.CallElementAdapter.CallElementView;
 import com.savoirfairelinux.sflphone.client.CallActivity;
 import com.savoirfairelinux.sflphone.client.SFLPhoneHomeActivity;
 import com.savoirfairelinux.sflphone.fragments.CallElementListFragment;
-import com.savoirfairelinux.sflphone.fragments.CallElementListFragment.CallElementView;
+import com.savoirfairelinux.sflphone.service.ISipService;
 
 public class SipCall
 {
diff --git a/src/com/savoirfairelinux/sflphone/service/ConfigurationManagerCallback.java b/src/com/savoirfairelinux/sflphone/service/ConfigurationManagerCallback.java
index ab9fbbf..e0d4e58 100644
--- a/src/com/savoirfairelinux/sflphone/service/ConfigurationManagerCallback.java
+++ b/src/com/savoirfairelinux/sflphone/service/ConfigurationManagerCallback.java
@@ -32,7 +32,8 @@
     private Context mContext; 
 
     static public final String SIGNAL_NAME = "signal-name";
-    static public final String ACCOUNTS_CHANGED = "accounts-changed"; 
+    static public final String ACCOUNTS_LOADED = "accounts-loaded";
+    static public final String ACCOUNTS_CHANGED = "accounts-changed";
     static public final String ACCOUNT_STATE_CHANGED = "account-state-changed";
 
     public ConfigurationManagerCallback(Context context) {