#15723: Add contact fragment to main application
diff --git a/src/com/savoirfairelinux/sflphone/client/CallElementList.java b/src/com/savoirfairelinux/sflphone/client/CallElementList.java
index 255666a..a78c1ec 100644
--- a/src/com/savoirfairelinux/sflphone/client/CallElementList.java
+++ b/src/com/savoirfairelinux/sflphone/client/CallElementList.java
@@ -161,15 +161,17 @@
 	 * 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.
 	 */
-	class CallElementAdapter extends ArrayAdapter
+	public static class CallElementAdapter extends ArrayAdapter
 	{
 		private ExecutorService infos_fetcher = Executors.newCachedThreadPool();
                 private ContactManager mContactManager;
+                private Context mContext;
 
 		public CallElementAdapter(Context context, ContactManager manager)
 		{
 			super(context, R.layout.call_element, manager.getContactList());
                         mContactManager = manager;
+                        mContext = context;
 		}
 
                 @Override
@@ -179,10 +181,10 @@
                     CallElementView callElementView = null;
 
                     if(rowView == null) {
-                        LayoutInflater inflater = LayoutInflater.from(getActivity());
+                        LayoutInflater inflater = LayoutInflater.from(mContext);
                         final long contact_id = 0;
                         rowView = inflater.inflate(R.layout.call_element, parent, false);
-                        infos_fetcher.execute(new InfosLoader(getActivity(), rowView, contact_id));
+                        infos_fetcher.execute(new InfosLoader(mContext, rowView, contact_id));
 
                         callElementView = new CallElementView();
                         // callElementView.toggleButton = (ImageButton) rowView.findViewById(R.id.toggleButton1);
@@ -233,7 +235,7 @@
 
 	};
 
-        public class CallElementView
+        public static class CallElementView
         {
             protected ImageButton toggleButton;
             protected Button button;
diff --git a/src/com/savoirfairelinux/sflphone/client/ContactListFragment.java b/src/com/savoirfairelinux/sflphone/client/ContactListFragment.java
new file mode 100644
index 0000000..136095c
--- /dev/null
+++ b/src/com/savoirfairelinux/sflphone/client/ContactListFragment.java
@@ -0,0 +1,73 @@
+/*
+ *  Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
+ *
+ *  Author: Adrien Beraud <adrien.beraud@gmail.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *  Additional permission under GNU GPL version 3 section 7:
+ *
+ *  If you modify this program, or any covered work, by linking or
+ *  combining it with the OpenSSL project's OpenSSL library (or a
+ *  modified version of that library), containing parts covered by the
+ *  terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
+ *  grants you additional permission to convey the resulting work.
+ *  Corresponding Source for a non-source form of such a combination
+ *  shall include the source code for the parts of OpenSSL used as well
+ *  as that of the covered work.
+ */
+package com.savoirfairelinux.sflphone.client;
+
+import android.app.ListFragment;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ListView;
+import android.util.Log;
+
+import com.savoirfairelinux.sflphone.R;
+
+public class ContactListFragment extends ListFragment
+{
+    ContactManager mContactManager;
+    CallElementList.CallElementAdapter mAdapter;
+
+    @Override
+    public void onActivityCreated(Bundle savedInstanceState)
+    {
+        super.onActivityCreated(savedInstanceState);
+
+        setHasOptionsMenu(true);
+
+        mContactManager = new ContactManager(getActivity());
+
+        mAdapter = new CallElementList.CallElementAdapter(getActivity(), mContactManager);
+        setListAdapter(mAdapter);
+    }
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
+    {
+        return inflater.inflate(R.layout.call_element_list, container, false);
+    }
+
+    @Override
+    public void onListItemClick(ListView l, View v, int position, long id)
+    {
+        // Insert desired behavior here.
+        Log.i("FragmentConplexList", "Item clicked: " + id);
+    }
+}
diff --git a/src/com/savoirfairelinux/sflphone/client/SFLPhoneHome.java b/src/com/savoirfairelinux/sflphone/client/SFLPhoneHome.java
index d3f000e..900dfde 100644
--- a/src/com/savoirfairelinux/sflphone/client/SFLPhoneHome.java
+++ b/src/com/savoirfairelinux/sflphone/client/SFLPhoneHome.java
@@ -82,7 +82,7 @@
 	 */
 	ViewPager mViewPager;
 	
-	final private int[] icon_res_id = {R.drawable.ic_tab_call, R.drawable.ic_tab_history, R.drawable.ic_tab_play_selected};
+	final private int[] icon_res_id = {R.drawable.ic_tab_call, R.drawable.ic_tab_call, R.drawable.ic_tab_history, R.drawable.ic_tab_play_selected};
 
 	@Override
 	public void onCreate(Bundle savedInstanceState)
@@ -117,6 +117,7 @@
 			// Create a tab with text corresponding to the page title defined by the adapter.
 			// Also specify this Activity object, which implements the TabListener interface, as the
 			// listener for when this tab is selected.
+                        Log.i(TAG, "adding tab: " + i);
 			actionBar.addTab(actionBar.newTab().setIcon(icon_res_id[i]).setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
 		}
 
@@ -229,13 +230,16 @@
 			Fragment fragment;
 			
 			switch (i) {
-			case 0:
+                        case 0:
+                                fragment = new ContactListFragment();
+                                break;
+			case 1:
 				fragment = new CallElementList();
 				break;
-			case 1:
+			case 2:
 				fragment = new DummySectionFragment();
 				break;
-			case 2:
+			case 3:
 				fragment = new ButtonSectionFragment();
 				Log.i(TAG, "getItem: fragment is " + fragment);
 				break;
@@ -253,18 +257,20 @@
 		@Override
 		public int getCount()
 		{
-			return 3;
+			return 4;
 		}
 
 		@Override
 		public CharSequence getPageTitle(int position)
 		{
 			switch (position) {
-			case 0:
-				return getString(R.string.title_section1).toUpperCase();
+                        case 0:
+                                return getString(R.string.title_section0).toUpperCase();
 			case 1:
-				return getString(R.string.title_section2).toUpperCase();
+				return getString(R.string.title_section1).toUpperCase();
 			case 2:
+				return getString(R.string.title_section2).toUpperCase();
+			case 3:
 				return getString(R.string.title_section3).toUpperCase();
 			default:
 				Log.e(TAG, "getPageTitle: unknown tab position " + position);