merge avec marseille
authorDa Risk <darisk972@gmail.com>
Wed, 01 Apr 2009 19:24:05 +0200
changeset 48 e7a787b81100
parent 47 743ccc7961dc (current diff)
parent 43 4e7c6918b092 (diff)
child 49 b6d4f4af9e4c
merge avec marseille
res/layout/contactlist.xml
src/com/beem/project/beem/ui/ContactList.java
--- a/AndroidManifest.xml	Tue Mar 31 20:46:06 2009 +0200
+++ b/AndroidManifest.xml	Wed Apr 01 19:24:05 2009 +0200
@@ -10,6 +10,7 @@
 			</intent-filter>
 		</activity>
 		<activity android:name=".ui.ContactList" android:label="@string/app_name" />
+		<activity android:name=".ui.SendIM" 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>
@@ -23,4 +24,5 @@
 	<uses-permission android:name="android.permission.INTERNET"></uses-permission>
 	<uses-permission android:name="android.permission.VIBRATE"></uses-permission>
 	<uses-permission android:name="com.beem.project.beem.BEEM_SERVICE"></uses-permission>
+<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"></uses-permission>
 </manifest> 
--- a/res/layout/contactlist.xml	Tue Mar 31 20:46:06 2009 +0200
+++ b/res/layout/contactlist.xml	Wed Apr 01 19:24:05 2009 +0200
@@ -13,4 +13,4 @@
 			android:layout_width="fill_parent"
             android:layout_height="fill_parent" android:text="Non connecte" />
 
-</LinearLayout> 
\ No newline at end of file
+</LinearLayout>
--- a/res/layout/messagelist.xml	Tue Mar 31 20:46:06 2009 +0200
+++ b/res/layout/messagelist.xml	Wed Apr 01 19:24:05 2009 +0200
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <TextView xmlns:android="http://schemas.android.com/apk/res/android" id="text1"
-          android:textStyle="bold"
+          android:textSize="2mm"
+          android:textColor="@color/black"
           android:singleLine="false"
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"/>
\ No newline at end of file
--- a/res/layout/sendim.xml	Tue Mar 31 20:46:06 2009 +0200
+++ b/res/layout/sendim.xml	Wed Apr 01 19:24:05 2009 +0200
@@ -1,26 +1,20 @@
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-              android:orientation="vertical"
-              android:layout_width="fill_parent"
-              android:layout_height="fill_parent"
-        >
-    <ListView android:id="@+id/listMessages"
-              android:layout_width="wrap_content"
-              android:layout_height="wrap_content"
-              android:layout_weight="1"
-              android:scrollbars="horizontal"
-            />
-    <EditText android:id="@+id/sendText"
-              android:layout_width="fill_parent"
-              android:layout_height="wrap_content"
-              android:singleLine="true"
-              android:textSize="16sp"
-              android:autoText="false"
-              android:capitalize="none"
-              android:scrollHorizontally="true"/>
-    <Button android:id="@+id/send"
-            android:layout_width="fill_parent"
-            android:layout_height="wrap_content"
-            android:text="Send">
-    </Button>
-</LinearLayout>
+    android:orientation="vertical"
+    android:layout_width="fill_parent" 
+    android:layout_height="fill_parent"
+    android:background="@color/blue_sky">
+
+    <ListView android:id="@android:id/list"
+        android:layout_width="fill_parent" 
+        android:layout_height="fill_parent"
+        android:layout_weight="1"
+        android:transcriptMode="alwaysScroll"/>
+        
+    <EditText android:id="@+id/userText"
+        android:layout_width="fill_parent"
+        android:cursorVisible="false"
+        android:hint="@string/SendIMHint"
+        android:layout_height="wrap_content" />
+        
+</LinearLayout>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/res/layout/sendimdialogsmiley.xml	Wed Apr 01 19:24:05 2009 +0200
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+              android:orientation="vertical"
+              android:layout_width="fill_parent"
+              android:layout_height="fill_parent"/>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/res/menu/sendimmenu.xml	Wed Apr 01 19:24:05 2009 +0200
@@ -0,0 +1,3 @@
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+	<item android:title="Insert a smiley" android:id="@+id/sendim_smiley"/>
+</menu>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/res/values/colors.xml	Wed Apr 01 19:24:05 2009 +0200
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+	<color name="blue_sky">#A0C8FF</color>
+	<color name="black">#000000</color>
+</resources>
\ No newline at end of file
--- a/res/values/strings.xml	Tue Mar 31 20:46:06 2009 +0200
+++ b/res/values/strings.xml	Wed Apr 01 19:24:05 2009 +0200
@@ -2,19 +2,26 @@
 <resources>
 	<string name="app_name">Beem</string>
 
-	<!--  Class Beem -->
+	<!--  Beem class -->
 	<string name="BeemCreateAccount">Creer un compte</string>
 	<string name="BeemJabberID">Jabber ID</string>
 	
-	<!--  Class BeemService -->
+	<!--  BeemService class -->
 	<string name="BeemServiceDescription">Use the Beem Service</string>
 	<string name="BeemServiceCreated">BeemService Created</string>
 	<string name="BeemServiceDestroyed">BeemService destroyed</string>
 
-	<!--  Preferences information -->
+	<!--  Preferences informations -->
 	<string name="PreferenceFileName">Beem</string>
 	<string name="PreferenceLoginKey">login</string>
 	<string name="PreferenceHostKey">host</string>
 	<string name="PreferencePasswordKey">password</string>
 	<string name="PreferencePortKey">port</string>
+
+	<!--  SendIM class -->
+	<string name="SendIMSays">says :\n</string>
+	<string name="SendIMHint">Tip text here</string>
+	<string name="SendIMState">Is : </string>
+	<string name="SendIMFrom">and is speaking from : </string>
+	<string name="SendIMSmiley">Insert a smiley</string>
 </resources>
--- a/src/com/beem/project/beem/BeemService.java	Tue Mar 31 20:46:06 2009 +0200
+++ b/src/com/beem/project/beem/BeemService.java	Wed Apr 01 19:24:05 2009 +0200
@@ -1,3 +1,4 @@
+
 /**
  * 
  */
--- a/src/com/beem/project/beem/ui/ContactList.java	Tue Mar 31 20:46:06 2009 +0200
+++ b/src/com/beem/project/beem/ui/ContactList.java	Wed Apr 01 19:24:05 2009 +0200
@@ -4,10 +4,9 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-
 import android.app.ExpandableListActivity;
-import android.app.ProgressDialog;
 import android.content.Context;
+import android.content.Intent;
 import android.graphics.drawable.Drawable;
 import android.os.Bundle;
 import android.os.Handler;
@@ -16,10 +15,10 @@
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.ExpandableListAdapter;
+import android.widget.ExpandableListView;
 import android.widget.ImageView;
 import android.widget.SimpleExpandableListAdapter;
 import android.widget.TextView;
-
 import com.beem.project.beem.BeemApplication;
 import com.beem.project.beem.R;
 import com.beem.project.beem.service.Contact;
@@ -27,140 +26,132 @@
 
 public class ContactList extends ExpandableListActivity {
 
-	private static final String TAG = "CONTACTLIST_ACT";
-	private IXMPPFacade mService = null;
-	private Handler mHandler;
-	private BeemApplication mBeemApplication;
+    private static final String TAG = "CONTACTLIST_ACT";
+    private IXMPPFacade mService = null;
+    private Handler mHandler;
+    private BeemApplication mBeemApplication;
 
-	@Override
-	public void onCreate(Bundle saveBundle) {
-		super.onCreate(saveBundle);		
-		mHandler = new Handler();
-		mBeemApplication = BeemApplication.getApplication(this);
-	
+    @Override
+    public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
+	startActivity(new Intent(this, SendIM.class));
+	return true;
+
+    };
 
-	}
-	
-	@Override
-	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 onCreate(Bundle saveBundle) {
+	super.onCreate(saveBundle);
+	mHandler = new Handler();
+	mBeemApplication = BeemApplication.getApplication(this);
+
+    }
 
-	private void showContactList(List<Contact> listGroup,
-			List<Contact> listContact) {
-		ExpandableListAdapter Adapter;
-
-		List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
-		List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();
-
-		if (listGroup.size() == 0)
-			listGroup.add(new Contact());
-		for (int i = 0; i < listGroup.size() ; i++) {
-			Map<String, String> curGroupMap = new HashMap<String, String>();
-
-			groupData.add(curGroupMap);
-			curGroupMap.put("NAME", "Default");
-
-			List<Map<String, String>> children = new ArrayList<Map<String, String>>();
-			for (int j = 0; j < listContact.size() ; ++j) {
-				Map<String, String> curChildMap = new HashMap<String, String>();
-				children.add(curChildMap);
-				curChildMap.put("NAME_CHILD", listContact.get(j).getJID());
-				curChildMap.put("MSG", "Taper votre message perso");
-			}
-			childData.add(children);
+    @Override
+    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();
 		}
 
-		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<? extends List<? extends Map<String, ?>>> mChildData;
-		private String[] mChildFrom;
-		private int[] mChildTo;
-
-		public ContactExpandableListAdapter(Context context,
-				List<? extends Map<String, ?>> groupData, int groupLayout,
-				String[] groupFrom, int[] groupTo,
-				List<? extends List<? extends Map<String, ?>>> childData,
-				int childLayout, String[] childFrom, int[] childTo) {
-			super(context, groupData, groupLayout, groupFrom, groupTo,
-					childData, childLayout, childFrom, childTo);
-
-			mChildData = childData;
-			mChildFrom = childFrom;
-			mChildTo = childTo;
-
-		}
+    private void showContactList(List<Contact> listGroup, List<Contact> listContact) {
+	ExpandableListAdapter Adapter;
+	List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
+	List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();
 
-		@Override
-		public View getChildView(int groupPosition, int childPosition,
-				boolean isLastChild, View convertView, ViewGroup parent) {
+	if (listGroup.size() == 0)
+	    listGroup.add(new Contact());
+	for (int i = 0; i < listGroup.size(); i++) {
+	    Map<String, String> curGroupMap = new HashMap<String, String>();
 
-			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;
-		}
+	    groupData.add(curGroupMap);
+	    curGroupMap.put("NAME", "Default");
 
-		// This method binds my data to the Views specified in the child
-		// xmllayout
-		private void bindView(View view, Map<String, ?> 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);
-			}
-		}
+	    List<Map<String, String>> children = new ArrayList<Map<String, String>>();
+	    for (int j = 0; j < listContact.size(); ++j) {
+		Map<String, String> curChildMap = new HashMap<String, String>();
+		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<? extends List<? extends Map<String, ?>>> mChildData;
+	private String[] mChildFrom;
+	private int[] mChildTo;
+
+	public ContactExpandableListAdapter(Context context, List<? extends Map<String, ?>> groupData, int groupLayout,
+	    String[] groupFrom, int[] groupTo, List<? extends List<? extends Map<String, ?>>> 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<String, ?> 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);
+	    }
+	}
+    }
+
 }
--- a/src/com/beem/project/beem/ui/SendIM.java	Tue Mar 31 20:46:06 2009 +0200
+++ b/src/com/beem/project/beem/ui/SendIM.java	Wed Apr 01 19:24:05 2009 +0200
@@ -2,51 +2,121 @@
 
 import java.util.ArrayList;
 
-import org.jivesoftware.smack.packet.Message;
-
-import android.app.Activity;
+import android.app.ListActivity;
+import android.content.SharedPreferences;
 import android.os.Bundle;
+import android.view.KeyEvent;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
 import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.View.OnKeyListener;
 import android.widget.ArrayAdapter;
-import android.widget.Button;
 import android.widget.EditText;
-import android.widget.ListView;
 
 import com.beem.project.beem.R;
 
-public class SendIM extends Activity {
-	private EditText		mToSend;
-	private ListView		mList;
-	private ArrayList<String>	mMessages = new ArrayList<String>();
-	
-	@Override
+/**
+ * @author barbu
+ * This activity class provide the view for instant messaging
+ * after selecting a correspondant.
+ */
+
+public class SendIM extends ListActivity implements OnClickListener, OnKeyListener {
+    private EditText			mToSend;
+    private ArrayList<String>		mMessages = new ArrayList<String>();
+    private ArrayAdapter<String>	mAdapter;
+    private SendIMDialogSmiley		mSmyDialog;
+    private SharedPreferences mSet;
+
+    /**
+     * Constructor.
+     */
+    public SendIM() {
+	super();
+    }
+
+    /**
+     * Overload of onCreate() Activity inherited function
+     */
+    @Override
     public void onCreate(Bundle saveBundle) {
-        super.onCreate(saveBundle);
-        setContentView(R.layout.sendim);
-        mToSend = (EditText) findViewById(R.id.sendText);
-        mList = (ListView) findViewById(R.id.listMessages);
-        
-        Button send = (Button) this.findViewById(R.id.send);
-        send.setOnClickListener(new View.OnClickListener() {
-            public void onClick(View view) {
-                String text = mToSend.getText().toString();
-                if (text != "")
-                {
-                    /*
-                     * Prepare the message to send 
-                     * */
-                    Message msg = new Message("barbu", Message.Type.chat);
-                    msg.setBody(text);
-                    mMessages.add("Barbu says:\n" + text);
-                    mToSend.setText("");
-                    setListAdapter();
-                }
-            }
-        });
+	super.onCreate(saveBundle);
+	setContentView(R.layout.sendim);
+	mToSend = (EditText) findViewById(R.id.userText);
+	mSet = getSharedPreferences("lol", MODE_PRIVATE);
+	mSmyDialog = new SendIMDialogSmiley(this, mSet);
+
+	mAdapter = new ArrayAdapter<String>(this, R.layout.messagelist, mMessages);
+	setListAdapter(mAdapter);
+
+	mToSend.setOnClickListener(this);
+	mToSend.setOnKeyListener(this);
+    }
+
+    /**
+     * Abstract method inherited from OnClickListener
+     */
+    public void onClick(View view) {
+	sendText();
+    }
+
+    /**
+     * This method send a message to the server over the XMPP
+     * connection and display it on activity view
+     * TODO : Exception si la connexion se coupe pendant la conversation
+     */
+    private void sendText() {
+	String text = mToSend.getText().toString();
+	if (!text.equals("")) {
+	    /*
+	     * Prepare the message to be send 
+	     * */
+	    /*Message msg = new Message("barbu", Message.Type.chat);*/
+	    /*msg.setBody(text);*/
+	    mAdapter.add("Barbu " + getString(R.string.SendIMSays) + text);
+	    mToSend.setText(null);
 	}
-	
-	private void setListAdapter() {
-	    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.messagelist, mMessages);
-	    mList.setAdapter(adapter);
+    }
+
+    /**
+     * Abstract method inherited from OnKeyListener
+     */
+    public boolean onKey(View v, int keyCode, KeyEvent event) {
+	if (event.getAction() == KeyEvent.ACTION_DOWN) {
+	    switch (keyCode) {
+		case KeyEvent.KEYCODE_DPAD_CENTER:
+		case KeyEvent.KEYCODE_ENTER:
+		    sendText();
+		    return true;
+	    }
 	}
+	return false;
+    }
+    
+    /**
+     * Callback for menu creation.
+     * @param menu
+     *            the menu created
+     * @return true on success, false otherwise
+     */
+    @Override
+    public final boolean onCreateOptionsMenu(Menu menu) {
+	super.onCreateOptionsMenu(menu);
+	MenuInflater inflater = getMenuInflater();
+	inflater.inflate(R.menu.sendimmenu, menu);
+	return true;
+    }
+    
+    @Override
+    public final boolean onOptionsItemSelected(MenuItem item) {
+	switch (item.getItemId()) {
+	    case R.id.sendim_smiley:
+		mSmyDialog.show();
+		return true;
+	    default:
+		return false;
+	}
+    }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/ui/SendIMDialogSmiley.java	Wed Apr 01 19:24:05 2009 +0200
@@ -0,0 +1,25 @@
+package com.beem.project.beem.ui;
+
+import com.beem.project.beem.R;
+
+import android.app.Dialog;
+import android.content.SharedPreferences;
+import android.widget.Button;
+
+public class SendIMDialogSmiley extends Dialog {
+    private SendIM	mSendIM;
+    private SharedPreferences	mSet;
+    
+    public SendIMDialogSmiley(SendIM sendim, SharedPreferences settings) {
+        super(sendim);
+        this.mSendIM = sendim;
+        this.mSet = settings;
+    }
+    
+    @Override
+    protected void onStart() {
+        super.onStart();
+        setContentView(R.layout.sendimdialogsmiley);
+        setTitle("Select a smiley");
+    }
+}