oulala le dialog ...
authormarseille@marseille-desktop
Fri, 22 May 2009 14:57:30 +0200
changeset 196 052599f4e646
parent 193 54e1e3f0bd4b
child 197 73b3c7576722
child 200 121fe5a66404
oulala le dialog ...
res/layout/contactdialog.xml
src/com/beem/project/beem/ui/ContactDialog.java
src/com/beem/project/beem/ui/ContactList.java
src/com/beem/project/beem/ui/SendIMDialogSmiley.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/res/layout/contactdialog.xml	Fri May 22 14:57:30 2009 +0200
@@ -0,0 +1,9 @@
+<?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">
+
+	<Button android:id="@+id/chat" android:layout_width="fill_parent"
+		android:layout_height="wrap_content" android:text="Chat" />
+
+</LinearLayout>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/ui/ContactDialog.java	Fri May 22 14:57:30 2009 +0200
@@ -0,0 +1,40 @@
+package com.beem.project.beem.ui;
+
+import android.app.Activity;
+import android.app.Dialog;
+import android.content.Context;
+import android.content.Intent;
+import android.view.View;
+import android.widget.Button;
+
+import com.beem.project.beem.R;
+import com.beem.project.beem.service.Contact;
+
+public class ContactDialog extends Dialog {
+
+   // final private CharSequence[] items = { "Chat", "Resend suscription", "Alias", "Change group", "Infos" };
+    private Contact mContact;
+    private Context mContext;
+
+    public ContactDialog(final Context context, Contact c) {
+	super(context);
+	mContext = context;
+	setContentView(R.layout.contactdialog);
+	mContact = c;
+	setTitle(c.getJID());
+		
+	Button chat = (Button) findViewById(R.id.chat);
+	chat.setOnClickListener(new View.OnClickListener() {
+
+	    @Override
+	    public void onClick(View v) {
+		Activity a = ContactDialog.this.getOwnerActivity();
+		Intent i = new Intent(mContext, SendIM.class);
+		i.putExtra("contact", mContact);
+		a.startActivity(i);
+		dismiss();
+	    }
+	    
+	});
+    }
+}
--- a/src/com/beem/project/beem/ui/ContactList.java	Thu May 21 16:33:11 2009 +0200
+++ b/src/com/beem/project/beem/ui/ContactList.java	Fri May 22 14:57:30 2009 +0200
@@ -7,7 +7,10 @@
 
 import org.jivesoftware.smack.util.StringUtils;
 
+import android.app.AlertDialog;
+import android.app.Dialog;
 import android.app.ExpandableListActivity;
+import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.database.DataSetObserver;
@@ -23,10 +26,12 @@
 import android.view.MenuItem;
 import android.view.View;
 import android.view.ViewGroup;
+import android.view.View.OnClickListener;
+import android.view.View.OnLongClickListener;
 import android.widget.ExpandableListAdapter;
-import android.widget.ExpandableListView;
 import android.widget.ImageView;
 import android.widget.TextView;
+import android.widget.Toast;
 
 import com.beem.project.beem.BeemApplication;
 import com.beem.project.beem.R;
@@ -67,7 +72,7 @@
     @Override
     protected void onResume() {
 	super.onResume();
-	
+
 	mBeemApplication.callWhenConnectedToServer(mHandler, new Runnable() {
 	    @Override
 	    public void run() {
@@ -93,7 +98,7 @@
     @Override
     protected void onDestroy() {
 	mBeemApplication.unbindBeemService();
-	super.onDestroy();	
+	super.onDestroy();
     }
 
     private void callbackShowContactList() {
@@ -147,19 +152,10 @@
 	}
     }
 
-    @Override
-    public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
-	Intent i = new Intent(this, SendIM.class);
-	try {
-	    i.putExtra("contact", groupMap.get(groupName.get(groupPosition)).get(childPosition));
-	    startActivity(i);
-	    return true;
-	} catch (NullPointerException e) {
-	    Log.e(TAG, "Child not found", e);
-	    return false;
-	}
-    }
-
+    /*
+     * @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition,
+     * long id) { try { } catch (NullPointerException e) { Log.e(TAG, "Child not found", e); return false; } }
+     */
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
 	if (requestCode == PREFERENCECHANGED) {
 	    if (resultCode == RESULT_OK) {
@@ -175,7 +171,7 @@
 	groupMap = new HashMap<String, List<Contact>>();
 	groupName = new ArrayList<String>();
 	for (Contact contact : listContact) {
-	    for (String group: contact.getGroups()) {
+	    for (String group : contact.getGroups()) {
 		if (!groupMap.containsKey(group)) {
 		    groupMap.put(group, new ArrayList<Contact>());
 		    groupName.add(group);
@@ -200,19 +196,18 @@
 
     private class MyExpandableListAdapter implements ExpandableListAdapter {
 
-	private List<DataSetObserver> observers; 
-	
+	private List<DataSetObserver> observers;
+
 	public MyExpandableListAdapter() {
 	    observers = new ArrayList<DataSetObserver>();
 	}
-	
+
 	public void changed() {
 	    for (DataSetObserver obs : observers) {
 		obs.onChanged();
 	    }
 	}
-	
-	
+
 	@Override
 	public boolean areAllItemsEnabled() {
 	    return true;
@@ -239,17 +234,58 @@
 	    return childPosition;
 	}
 
+	void createDialog(Contact contact) {
+
+	    Dialog dialogContact= new ContactDialog(ContactList.this, contact);
+	    dialogContact.show();
+	}
+
+	class MyOnLongClickListener implements OnLongClickListener {
+	    @Override
+	    public boolean onLongClick(View v) {
+		TextView jidTextView = (TextView) v.findViewById(R.id.contactlistpseudo);
+		String jid = jidTextView.getText().toString();
+		for (Contact curContact : mListContact) {
+		    if (jid.equals(curContact.getJID())) {
+			createDialog(curContact);
+			break;
+		    }
+		}
+		return true;
+	    }
+	}
+
+	class MyOnClickListener implements OnClickListener {
+	    @Override
+	    public void onClick(View v) {
+		TextView jidTextView = (TextView) v.findViewById(R.id.contactlistpseudo);
+		String jid = jidTextView.getText().toString();
+		for (Contact curContact : mListContact) {
+		    if (jid.equals(curContact.getJID())) {
+			Intent i = new Intent(ContactList.this, SendIM.class);
+			i.putExtra("contact", curContact);
+			startActivity(i);
+			break;
+		    }
+		}
+	    }
+
+	}
+
 	@Override
 	public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView,
 	    ViewGroup parent) {
 	    View v;
 	    if (convertView == null) {
-		v  = LayoutInflater.from(ContactList.this).inflate(R.layout.contactlistcontact, null);
+		v = LayoutInflater.from(ContactList.this).inflate(R.layout.contactlistcontact, null);
 		Log.d(TAG, "Convert view est vide sur un getChildView");
 	    } else {
 		v = convertView;
 	    }
 	    bindView(v, groupMap.get(groupName.get(groupPosition)).get(childPosition));
+
+	    v.setOnLongClickListener(new MyOnLongClickListener());
+	    v.setOnClickListener(new MyOnClickListener());
 	    return v;
 	}
 
@@ -321,13 +357,10 @@
 
 	@Override
 	public void onGroupCollapsed(int groupPosition) {
-	    // TODO A voir
 	}
 
 	@Override
 	public void onGroupExpanded(int groupPosition) {
-	    // TODO A voir
-
 	}
 
 	@Override
@@ -368,7 +401,7 @@
 			break;
 		    default:
 			imageDrawable = (Drawable) getResources().getDrawable(R.drawable.error);
-		    break;
+			break;
 		}
 		imgV.setImageDrawable(imageDrawable);
 
@@ -382,7 +415,7 @@
 		    v.setText(curContact.getMsgState());
 		}
 
-		//TODO: Rajouter l'avatar du contact getAvatar() dans la classe
+		// TODO: Rajouter l'avatar du contact getAvatar() dans la classe
 		imgV = (ImageView) view.findViewById(R.id.contactlistavatar);
 		if (imgV != null) {
 		    imageDrawable = (Drawable) getResources().getDrawable(R.drawable.avatar);
@@ -390,7 +423,6 @@
 		}
 	    }
 	}
-
     }
 
     private class BeemRosterListener extends IBeemRosterListener.Stub {
@@ -415,7 +447,7 @@
 
 	@Override
 	public void onPresenceChanged(PresenceAdapter presence) throws RemoteException {
-	    for (Contact curContact :mListContact) {
+	    for (Contact curContact : mListContact) {
 		if (curContact.getJID().equals(StringUtils.parseBareAddress(presence.getFrom()))) {
 		    curContact.setStatus(presence);
 		    mHandler.post(new Runnable() {
@@ -424,7 +456,7 @@
 			    mAdapter.changed();
 			}
 		    });
-		    return ;
+		    return;
 		}
 	    }
 	}
--- a/src/com/beem/project/beem/ui/SendIMDialogSmiley.java	Thu May 21 16:33:11 2009 +0200
+++ b/src/com/beem/project/beem/ui/SendIMDialogSmiley.java	Fri May 22 14:57:30 2009 +0200
@@ -6,19 +6,19 @@
 import android.content.SharedPreferences;
 
 public class SendIMDialogSmiley extends Dialog {
-   private SendIM	mSendIM;
-    private SharedPreferences	mSet;
-    
+    private SendIM mSendIM;
+    private SharedPreferences mSet;
+
     public SendIMDialogSmiley(SendIM sendim, SharedPreferences settings) {
-        super(sendim);
-        this.mSendIM = sendim;
-        this.mSet = settings;
+	super(sendim);
+	this.mSendIM = sendim;
+	this.mSet = settings;
     }
-    
+
     @Override
     protected void onStart() {
-        super.onStart();
-        setContentView(R.layout.sendimdialogsmiley);
-        setTitle("Select a smiley");
+	super.onStart();
+	setContentView(R.layout.sendimdialogsmiley);
+	setTitle("Select a smiley");
     }
 }