# HG changeset patch # User Da Risk # Date 1238606645 -7200 # Node ID e7a787b81100aa7c582e8a3de063c9f89b8120e8 # Parent 743ccc7961dca597a291c0ff0ff1bc3475b690eb# Parent 4e7c6918b0928ebad59f598a36b78b59a1f38f80 merge avec marseille diff -r 743ccc7961dc -r e7a787b81100 AndroidManifest.xml --- 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 @@ + @@ -23,4 +24,5 @@ + diff -r 743ccc7961dc -r e7a787b81100 res/layout/contactlist.xml --- 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" /> - \ No newline at end of file + diff -r 743ccc7961dc -r e7a787b81100 res/layout/messagelist.xml --- 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 @@ \ No newline at end of file diff -r 743ccc7961dc -r e7a787b81100 res/layout/sendim.xml --- 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 @@ - - - - + android:orientation="vertical" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:background="@color/blue_sky"> + + + + + + \ No newline at end of file diff -r 743ccc7961dc -r e7a787b81100 res/layout/sendimdialogsmiley.xml --- /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 @@ + + \ No newline at end of file diff -r 743ccc7961dc -r e7a787b81100 res/menu/sendimmenu.xml --- /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 @@ + + + diff -r 743ccc7961dc -r e7a787b81100 res/values/colors.xml --- /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 @@ + + + #A0C8FF + #000000 + \ No newline at end of file diff -r 743ccc7961dc -r e7a787b81100 res/values/strings.xml --- 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 @@ Beem - + Creer un compte Jabber ID - + Use the Beem Service BeemService Created BeemService destroyed - + Beem login host password port + + + says :\n + Tip text here + Is : + and is speaking from : + Insert a smiley diff -r 743ccc7961dc -r e7a787b81100 src/com/beem/project/beem/BeemService.java --- 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 @@ + /** * */ diff -r 743ccc7961dc -r e7a787b81100 src/com/beem/project/beem/ui/ContactList.java --- 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 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); + @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>> 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; - - } + private void showContactList(List listGroup, List listContact) { + ExpandableListAdapter Adapter; + List> groupData = new ArrayList>(); + List>> childData = new ArrayList>>(); - @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 curGroupMap = new HashMap(); - 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 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> 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); + } + } + } + } diff -r 743ccc7961dc -r e7a787b81100 src/com/beem/project/beem/ui/SendIM.java --- 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 mMessages = new ArrayList(); - - @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 mMessages = new ArrayList(); + private ArrayAdapter 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(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 adapter = new ArrayAdapter(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; + } + } } diff -r 743ccc7961dc -r e7a787b81100 src/com/beem/project/beem/ui/SendIMDialogSmiley.java --- /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"); + } +}