Gestion alias dans la user info.
authorVincent Veronis <veroni_v@epitech.net>
Thu, 01 Oct 2009 15:48:06 +0200
changeset 422 1385ea631852
parent 420 ecddfb6c0e2a
child 423 32d2c5840a8c
Gestion alias dans la user info. Modification dans la contact liste pour creer la view avec les infos du roster
res/layout/contactdialog.xml
res/layout/userinfo_alias.xml
res/values-en/strings.xml
res/values-fr/strings.xml
src/com/beem/project/beem/ui/ContactDialog.java
src/com/beem/project/beem/ui/ContactDialogAliasDialog.java
src/com/beem/project/beem/ui/ContactList.java
src/com/beem/project/beem/ui/UserInfo.java
--- a/res/layout/contactdialog.xml	Wed Sep 30 00:19:49 2009 +0200
+++ b/res/layout/contactdialog.xml	Thu Oct 01 15:48:06 2009 +0200
@@ -9,19 +9,7 @@
 	<Button android:id="@+id/CDCall" android:layout_width="fill_parent"
 		android:layout_height="wrap_content" android:text="@string/CDCall" />
 
-	<Button android:id="@+id/CDAlias" android:layout_width="fill_parent"
-		android:layout_height="wrap_content" android:text="@string/CDAlias" />
-
-	<Button android:id="@+id/CDDelete" android:layout_width="fill_parent"
-		android:layout_height="wrap_content" android:text="@string/CDDelete" />
-
-	<Button android:id="@+id/CDResend" android:layout_width="fill_parent"
-		android:layout_height="wrap_content" android:text="@string/CDResend" />
-
 	<Button android:id="@+id/CDInfos" android:layout_width="fill_parent"
 		android:layout_height="wrap_content" android:text="@string/CDInfos" />
 
-	<Button android:id="@+id/CDBlock" android:layout_width="fill_parent"
-		android:layout_height="wrap_content" android:text="@string/CDBlock" />
-
 </LinearLayout>
\ No newline at end of file
--- a/res/layout/userinfo_alias.xml	Wed Sep 30 00:19:49 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,13 +0,0 @@
-<?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="wrap_content">
-	<TextView android:id="@+id/userinfo_alias_label"
-		android:layout_width="fill_parent" android:layout_height="wrap_content"
-		android:paddingLeft="20sp" android:singleLine="true" android:maxLines="1"
-		android:textSize="30px" android:text="Alias" />
-	<TextView android:id="@+id/userinfo_alias_def"
-		android:layout_width="fill_parent" android:layout_height="wrap_content"
-		android:paddingLeft="20sp" android:singleLine="true"
-		android:text="Modifier le nom affiche de votre contact" />
-</LinearLayout>
\ No newline at end of file
--- a/res/values-en/strings.xml	Wed Sep 30 00:19:49 2009 +0200
+++ b/res/values-en/strings.xml	Thu Oct 01 15:48:06 2009 +0200
@@ -214,5 +214,15 @@
 	 <string name="contact_list_menu_settings">Settings</string>
 	 <string name="contact_list_all_contact">All contacts</string>
 	 <string name="contact_list_no_group">No group</string>
+	 
+	 <!-- 
+		UserInfo Activity
+	 -->
+	 <string name="userinfo_label_alias">Alias</string>
+	 <string name="userinfo_label_vcard">VCard</string>
+	 <string name="userinfo_label_chg_group">Modifier groupe</string>
+	 <string name="userinfo_label_re_suscription">Renvoyer souscription</string>
+	 <string name="userinfo_label_block">Bloquer</string>
+	 <string name="userinfo_label_delete">Supprimer</string>
 
 </resources>
--- a/res/values-fr/strings.xml	Wed Sep 30 00:19:49 2009 +0200
+++ b/res/values-fr/strings.xml	Thu Oct 01 15:48:06 2009 +0200
@@ -34,12 +34,8 @@
 
 	<!--  ContactDialog class -->
 	<string name="CDChat">Chat</string>
-	<string name="CDAlias">Alias</string>
 	<string name="CDCall">Appeller</string>
-	<string name="CDResend">Réenvoyer la demande</string>
 	<string name="CDInfos">Informations utilisateur</string>
-	<string name="CDBlock">Bloquer l\'utilisateur</string>
-	<string name="CDDelete">Supprimer l\'utilisateur</string>
 	<string name="CDSure2Delete">Êtes-vous sûr de vouloir supprimer ce contact ?</string>
 	<string name="CDSure2DeleteYes">Oui</string>
 	<string name="CDSure2DeleteNo">Non</string>
@@ -211,4 +207,13 @@
 	 <string name="contact_list_all_contact">Tous les contacts</string>
 	 <string name="contact_list_no_group">Aucun groupe</string>
 
+	<!-- 
+		UserInfo Activity
+	 -->
+	 <string name="userinfo_label_alias">Alias</string>
+	 <string name="userinfo_label_vcard">VCard</string>
+	 <string name="userinfo_label_chg_group">Modifier groupe</string>
+	 <string name="userinfo_label_re_suscription">Renvoyer souscription</string>
+	 <string name="userinfo_label_block">Bloquer</string>
+	 <string name="userinfo_label_delete">Supprimer</string>
 </resources>
--- a/src/com/beem/project/beem/ui/ContactDialog.java	Wed Sep 30 00:19:49 2009 +0200
+++ b/src/com/beem/project/beem/ui/ContactDialog.java	Thu Oct 01 15:48:06 2009 +0200
@@ -43,14 +43,6 @@
 
 	Button button = (Button) findViewById(R.id.CDChat);
 	button.setOnClickListener(new chatListener());
-	button = (Button) findViewById(R.id.CDAlias);
-	button.setOnClickListener(new aliasListener());
-	button = (Button) findViewById(R.id.CDDelete);
-	button.setOnClickListener(new deleteListener());
-	button = (Button) findViewById(R.id.CDResend);
-	button.setOnClickListener(new resendListener());
-	button = (Button) findViewById(R.id.CDBlock);
-	button.setOnClickListener(new blockListener());
 	button = (Button) findViewById(R.id.CDInfos);
 	button.setOnClickListener(new infosListener());
 	button = (Button) findViewById(R.id.CDCall);
@@ -85,11 +77,12 @@
 
 	@Override
 	public void onClick(View v) {
-
+/*
 	    ContactDialogAliasDialog dialog = new ContactDialogAliasDialog(mContext, mContact);
 	    dialog.setOwnerActivity(ContactDialog.this.getOwnerActivity());
 	    dialog.initService(mXmppFacade);
 	    dialog.show();
+	    */
 	}
 
     }
--- a/src/com/beem/project/beem/ui/ContactDialogAliasDialog.java	Wed Sep 30 00:19:49 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,56 +0,0 @@
-/**
- * 
- */
-package com.beem.project.beem.ui;
-
-import android.app.Dialog;
-import android.content.Context;
-import android.os.RemoteException;
-import android.util.Log;
-import android.view.View;
-import android.widget.Button;
-import android.widget.EditText;
-
-import com.beem.project.beem.R;
-import com.beem.project.beem.service.Contact;
-import com.beem.project.beem.service.aidl.IXmppFacade;
-
-/**
- * @author marseille
- */
-public class ContactDialogAliasDialog extends Dialog {
-
-    protected static final String TAG = "CAlias";
-    private Contact     mContact;
-    private IXmppFacade mService;
-
-    public ContactDialogAliasDialog(Context context, Contact contact) {
-	super(context);
-	setContentView(R.layout.contactdialogaliasdialog);
-	setTitle("Alias");
-	mContact = contact;
-	EditText nameText = (EditText) findViewById(R.id.CDAliasDialogName);
-	nameText.setText(mContact.getName());
-
-	Button ok = (Button) findViewById(R.id.CDAliasDialogOk);
-	ok.setOnClickListener(new View.OnClickListener() {
-
-	    @Override
-	    public void onClick(View v) {
-		EditText nameText = (EditText) findViewById(R.id.CDAliasDialogName);
-		try {
-		    Log.d(TAG, mContact.getJID() + nameText.getText().toString());
-		    mService.getRoster().setContactName(mContact.getJID(), nameText.getText().toString());
-		} catch (RemoteException e) {
-		    e.printStackTrace();
-		}
-		dismiss();
-	    }
-
-	});
-    }
-
-    public void initService(IXmppFacade service) {
-	mService = service;
-    }
-}
--- a/src/com/beem/project/beem/ui/ContactList.java	Wed Sep 30 00:19:49 2009 +0200
+++ b/src/com/beem/project/beem/ui/ContactList.java	Thu Oct 01 15:48:06 2009 +0200
@@ -484,6 +484,13 @@
 	    }
 
 	    Contact c = mListContact.get(position);
+	    if (mRoster != null) {
+		try {
+		    c = mRoster.getContact(c.getJID());
+		} catch (RemoteException e) {
+		    e.printStackTrace();
+		}
+	    }
 	    bindView(v, c);
 	    return v;
 	}
--- a/src/com/beem/project/beem/ui/UserInfo.java	Wed Sep 30 00:19:49 2009 +0200
+++ b/src/com/beem/project/beem/ui/UserInfo.java	Thu Oct 01 15:48:06 2009 +0200
@@ -1,22 +1,26 @@
 package com.beem.project.beem.ui;
 
-import java.util.ArrayList;
-import java.util.List;
-
 import android.app.Activity;
-import android.content.Context;
+import android.app.Dialog;
+import android.content.ComponentName;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.ServiceConnection;
+import android.net.Uri;
 import android.os.Bundle;
-import android.util.Log;
-import android.view.LayoutInflater;
+import android.os.IBinder;
+import android.os.RemoteException;
 import android.view.View;
-import android.view.ViewGroup;
-import android.widget.AdapterView;
-import android.widget.BaseAdapter;
-import android.widget.ListView;
-import android.widget.AdapterView.OnItemClickListener;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.TextView;
 
+import com.beem.project.beem.BeemService;
 import com.beem.project.beem.R;
 import com.beem.project.beem.service.Contact;
+import com.beem.project.beem.service.aidl.IRoster;
+import com.beem.project.beem.service.aidl.IXmppFacade;
+import com.beem.project.beem.utils.BeemBroadcastReceiver;
 
 /**
  * This activity class provides the view for user infos after long click on a correspondant.
@@ -24,11 +28,15 @@
  */
 public class UserInfo extends Activity {
 
+    private static final Intent SERVICE_INTENT = new Intent();
+    private final ServiceConnection mServConn = new BeemServiceConnection();
+    private String mJID;
     private Contact mContact;
-    private static final List<String> mInfo = new ArrayList<String>();
+    private IXmppFacade mXmppFacade;
+    private BeemBroadcastReceiver mReceiver;
 
     static {
-	mInfo.add("alias");
+	SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
     }
 
     /**
@@ -44,73 +52,114 @@
     protected void onCreate(Bundle savedInstanceState) {
 	super.onCreate(savedInstanceState);
 	setContentView(R.layout.userinfo);
-	mContact = new Contact(getIntent().getData());
-	setTitle(mContact.getName());
-	ListView listview = (ListView) findViewById(R.id.userinfo);
-	listview.setAdapter(new BeemUserInfo(this));
-	listview.setOnItemClickListener(new BeemUserInfoClick());
+	View v = (View) findViewById(R.id.userinfo_layout_alias);
+	v.setOnClickListener(new AliasListener());
+
+	mReceiver = new BeemBroadcastReceiver(mServConn);
     }
-    
+
     /**
-     * Event simple click on item of the user info.
+     * {@inheritDoc}
      */
-    public class BeemUserInfoClick implements OnItemClickListener {
-	@Override
-	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
-	    Log.i("OOO", mInfo.get(arg2));
-	}
+    @Override
+    protected void onResume() {
+	super.onResume();
+	this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
+	bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
+	mReceiver.setBinded();
     }
 
     /**
-     * Adapter user info list.
+     * {@inheritDoc}
      */
-    public class BeemUserInfo extends BaseAdapter {
-	private LayoutInflater mInflater;
+    @Override
+    protected void onPause() {
+	super.onPause();
+	this.unregisterReceiver(mReceiver);
+	if (mReceiver.isBinded())
+	    unbindService(mServConn);
+    }
+
+    class AliasListener implements View.OnClickListener {
+
+	@Override
+	public void onClick(View v) {
+
+	    Dialog d = new ContactDialogAliasDialog();
+	    d.show();
+	}
+
+    }
+
+    public class ContactDialogAliasDialog extends Dialog {
+
+	public ContactDialogAliasDialog() {
+	    super(UserInfo.this);
+	    setContentView(R.layout.contactdialogaliasdialog);
+	    setTitle(mContact.getJID());
+	    EditText nameText = (EditText) findViewById(R.id.CDAliasDialogName);
+	    if (mContact.getName().length() == 0)
+		nameText.setText(mContact.getJID());
+	    else
+		nameText.setText(mContact.getName());
+
+	    Button ok = (Button) findViewById(R.id.CDAliasDialogOk);
+	    ok.setOnClickListener(new View.OnClickListener() {
+
+		@Override
+		public void onClick(View v) {
+		    IRoster r;
+		    try {
+			r = mXmppFacade.getRoster();
+			if (r != null) {
+			    EditText nameText = (EditText) findViewById(R.id.CDAliasDialogName);
+			    String name = nameText.getText().toString();
+			    if (name.length() == 0)
+				name = mContact.getJID();
+			    r.setContactName(mContact.getJID(), name);
+			    mContact.setName(name);
+
+			}
+		    } catch (RemoteException e) {
+			e.printStackTrace();
+		    }
+		    dismiss();
+		}
+
+	    });
+	}
+
+    }
+
+    /**
+     * The ServiceConnection used to connect to the Beem service.
+     */
+    private class BeemServiceConnection implements ServiceConnection {
 
 	/**
 	 * Constructor.
-	 * @param c context activity.
 	 */
-	public BeemUserInfo(final Context c) {
-	    mInflater = LayoutInflater.from(c);
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public int getCount() {
-	    return mInfo.size();
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public Object getItem(int position) {
-	    return position;
+	public BeemServiceConnection() {
 	}
 
-	/**
-	 * {@inheritDoc}
-	 */
 	@Override
-	public long getItemId(int position) {
-	    return position;
+	public void onServiceConnected(ComponentName name, IBinder service) {
+	    mXmppFacade = IXmppFacade.Stub.asInterface(service);
+	    try {
+		IRoster r = mXmppFacade.getRoster();
+		if (r != null) {
+		    String jidByUri = getIntent().getData().getEncodedSchemeSpecificPart();
+		    mContact = r.getContact(jidByUri);
+		    setTitle(mContact.getJID());
+		}
+	    } catch (RemoteException e) {
+		e.printStackTrace();
+	    }
 	}
 
-	/**
-	 * {@inheritDoc}
-	 */
 	@Override
-	public View getView(int position, View convertView, ViewGroup parent) {
-	    View v = convertView;
-	    if (convertView == null) {
-		if (position == 0)
-		    v = mInflater.inflate(R.layout.userinfo_alias, null);
-	    }
-	    return v;
+	public void onServiceDisconnected(ComponentName name) {
+	    mXmppFacade = null;
 	}
     }
-
 }