Utilisation de vrai menu pour le longclick sur la contactlist
authorDa Risk <darisk972@gmail.com>
Sat, 28 Nov 2009 01:55:26 +0100
changeset 547 f25639696d5c
parent 546 97ae7bcc219a
child 548 9b0d1638a6e6
Utilisation de vrai menu pour le longclick sur la contactlist
.classpath
src/com/beem/project/beem/ui/ContactList.java
src/com/beem/project/beem/ui/UserInfo.java
--- a/.classpath	Fri Nov 27 22:21:27 2009 +0100
+++ b/.classpath	Sat Nov 28 01:55:26 2009 +0100
@@ -1,24 +1,24 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
-	<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
-	<classpathentry kind="lib" path="libs/smackx-debug.jar"/>
-	<classpathentry kind="lib" path="libs/smackx-jingle.jar" sourcepath="/home/nikita/devel/smack">
+	<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+	<classpathentry exported="true" kind="lib" path="libs/smackx-debug.jar"/>
+	<classpathentry exported="true" kind="lib" path="libs/smackx-jingle.jar" sourcepath="/home/nikita/devel/smack">
 		<attributes>
 			<attribute name="javadoc_location" value="file:/home/nikita/devel/smack_src_3_1_0/javadoc/"/>
 		</attributes>
 	</classpathentry>
-	<classpathentry kind="lib" path="libs/security.jar"/>
-	<classpathentry kind="lib" path="libs/smack.jar" sourcepath="/home/marseille/smack_src_3_1_0/source">
+	<classpathentry exported="true" kind="lib" path="libs/security.jar"/>
+	<classpathentry exported="true" kind="lib" path="libs/smack.jar" sourcepath="/home/marseille/smack_src_3_1_0/source">
 		<attributes>
 			<attribute name="javadoc_location" value="file:/home/nikita/devel/smack_src_3_1_0/javadoc/org/"/>
 		</attributes>
 	</classpathentry>
-	<classpathentry kind="lib" path="libs/smackx.jar" sourcepath="/home/nikita/devel/smack">
+	<classpathentry exported="true" kind="lib" path="libs/smackx.jar" sourcepath="/home/nikita/devel/smack">
 		<attributes>
 			<attribute name="javadoc_location" value="file:/home/nikita/devel/smack_src_3_1_0/javadoc/"/>
 		</attributes>
 	</classpathentry>
-	<classpathentry kind="lib" path="libs/jlibrtp.jar">
+	<classpathentry exported="true" kind="lib" path="libs/jlibrtp.jar">
 		<attributes>
 			<attribute name="javadoc_location" value="file:/home/nikita/android/docs/reference/"/>
 		</attributes>
--- a/src/com/beem/project/beem/ui/ContactList.java	Fri Nov 27 22:21:27 2009 +0100
+++ b/src/com/beem/project/beem/ui/ContactList.java	Sat Nov 28 01:55:26 2009 +0100
@@ -29,6 +29,7 @@
 import android.view.MenuItem;
 import android.view.View;
 import android.view.ViewGroup;
+import android.view.ContextMenu;
 import android.widget.AdapterView;
 import android.widget.BaseAdapter;
 import android.widget.Gallery;
@@ -131,6 +132,55 @@
 	}
     }
 
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
+	super.onCreateContextMenu(menu, v, menuInfo);
+	// TODO gere les info du context menu pour afficher que pour le bon long click
+	MenuInflater inflater = getMenuInflater();
+	inflater.inflate(R.menu.contactlist_context, menu);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean onContextItemSelected(MenuItem item) {
+	ContextMenu.ContextMenuInfo i = item.getMenuInfo();
+	if (i != null && i instanceof AdapterView.AdapterContextMenuInfo) {
+	    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) i;
+	    Contact c = mListContact.get(info.position);
+	    Intent in;
+	    if (c != null) {
+		switch (item.getItemId()) {
+		    case R.id.contact_list_context_menu_chat_item:
+			in = new Intent(this, Chat.class);
+			in.setData(c.toUri());
+			startActivity(in);
+			return true;
+		    case R.id.contact_list_context_menu_call_item:
+			try {
+			mXmppFacade.call(c.getJID() + "/psi");
+			return true;
+			} catch (RemoteException e) {
+			    e.printStackTrace();
+			}
+		    case R.id.contact_list_context_menu_manage_user_item:
+			in = new Intent(this, UserInfo.class);
+			//TODO use in.setData(c.toUri()); a la place 
+			in.putExtra("contact_contactdialog", c.getJID());
+			startActivity(in);
+			return true;
+		    default:
+			return super.onContextItemSelected(item);
+		}
+	    }
+	}
+	return super.onContextItemSelected(item);
+    }
+
     @Override
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
 	super.onActivityResult(requestCode, resultCode, data);
@@ -174,7 +224,7 @@
     /**
      * Comparator Contact by Name.
      */
-    class ComparatorContactListByName<T> implements Comparator<T> {
+    private class ComparatorContactListByName<T> implements Comparator<T> {
 	/**
 	 * Constructor.
 	 */
@@ -194,7 +244,7 @@
     /**
      * Comparator Contact by status and name.
      */
-    class ComparatorContactListByStatusAndName<T> implements Comparator<T> {
+    private class ComparatorContactListByStatusAndName<T> implements Comparator<T> {
 	/**
 	 * Constructor.
 	 */
@@ -226,7 +276,7 @@
 	sortBeemContactList();
 	ListView listView = (ListView) findViewById(R.id.contactlist);
 	listView.setOnItemClickListener(new BeemContactListOnClick());
-	listView.setOnItemLongClickListener(new BeemContactListOnLongClick());
+	registerForContextMenu(listView);
 	listView.setAdapter(mAdapterContactList);
     }
 
@@ -242,7 +292,7 @@
     /**
      * Event simple click on item of the contact list.
      */
-    public class BeemContactListOnClick implements OnItemClickListener {
+    private class BeemContactListOnClick implements OnItemClickListener {
 	/**
 	 * Constructor.
 	 */
@@ -263,30 +313,6 @@
     }
 
     /**
-     * Event long click on item of the contact list.
-     */
-    public class BeemContactListOnLongClick implements OnItemLongClickListener {
-	/**
-	 * Constructor.
-	 */
-	public BeemContactListOnLongClick() {
-
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public boolean onItemLongClick(AdapterView<?> arg0, View v, int pos, long lpos) {
-	    Contact c = mListContact.get(pos);
-	    mContactDialog = new ContactDialog(ContactList.this, c);
-	    mContactDialog.setOwnerActivity(ContactList.this);
-	    mContactDialog.show();
-	    return true;
-	}
-    }
-
-    /**
      * Event simple click on middle groupe name.
      */
     private class OnItemClickGroupName implements OnItemClickListener {
@@ -512,7 +538,20 @@
 	 */
 	@Override
 	public Object getItem(int position) {
-	    return position;
+	    Contact c = null;
+	    if (mSettings.getBoolean("settings_key_hidden_contact", false)) {
+		int res = 0;
+		for (Contact cur : mListContact) {
+		    if (res == position) {
+			c = cur;
+			break;
+		    }
+		    if (Status.statusOnline(cur.getStatus()))
+			res++;
+		}
+	    } else
+		c = mListContact.get(position);
+	    return c;
 	}
 
 	/**
@@ -523,6 +562,7 @@
 	    return position;
 	}
 
+
 	/**
 	 * {@inheritDoc}
 	 */
@@ -581,7 +621,7 @@
     /**
      * Adapter banner list.
      */
-    public class BeemBanner extends BaseAdapter {
+    private class BeemBanner extends BaseAdapter {
 	/**
 	 * Constructor.
 	 * @param c context activity.
--- a/src/com/beem/project/beem/ui/UserInfo.java	Fri Nov 27 22:21:27 2009 +0100
+++ b/src/com/beem/project/beem/ui/UserInfo.java	Sat Nov 28 01:55:26 2009 +0100
@@ -16,6 +16,7 @@
 import android.os.Bundle;
 import android.os.IBinder;
 import android.os.RemoteException;
+import android.util.Log;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.BaseAdapter;
@@ -252,7 +253,7 @@
     /**
      * Event simple click on layout resend suscription.
      */
-    class ResendListener implements View.OnClickListener {
+    private class ResendListener implements View.OnClickListener {
 
 	/**
 	 * Constructor.
@@ -293,12 +294,13 @@
     /**
      * Event simple click on layout delete.
      */
-    class DeleteListener implements View.OnClickListener {
+    private class DeleteListener implements View.OnClickListener {
 
 	/**
 	 * Constructor.
 	 */
 	public DeleteListener() {
+	    
 	}
 
 	@Override