merge avec nikita
authorPhilippe Lago <lago_p@epitech.net>
Tue, 23 Jun 2009 11:59:21 +0200
changeset 277 48eaf4f08062
parent 276 673ee3896d50 (current diff)
parent 271 e5040078e3bb (diff)
child 278 8bfaad9cfe93
merge avec nikita
src/com/beem/project/beem/service/PrivacyListAdapter.java
--- a/res/layout/contactdialog.xml	Tue Jun 23 11:22:20 2009 +0200
+++ b/res/layout/contactdialog.xml	Tue Jun 23 11:59:21 2009 +0200
@@ -18,4 +18,7 @@
 	<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/values/strings.xml	Tue Jun 23 11:22:20 2009 +0200
+++ b/res/values/strings.xml	Tue Jun 23 11:59:21 2009 +0200
@@ -57,12 +57,12 @@
 	<string name="CDAlias">Alias</string>
 	<string name="CDResend">Resend suscription</string>
 	<string name="CDInfos">User infos</string>
+	<string name="CDBlock">Block user</string>
 	<string name="CDDelete">Delete user</string>
 	<string name="CDSure2Delete">Are you sure you want to delete this contact?
 	</string>
 	<string name="CDSure2DeleteYes">Yes</string>
 	<string name="CDSure2DeleteNo">No</string>
-
 	<!-- AccountCreation class -->
 	<string name="ACLogin">Login:</string>
 	<string name="ACEmail">Email:</string>
--- a/src/com/beem/project/beem/BeemService.java	Tue Jun 23 11:22:20 2009 +0200
+++ b/src/com/beem/project/beem/BeemService.java	Tue Jun 23 11:59:21 2009 +0200
@@ -2,6 +2,7 @@
 
 import org.jivesoftware.smack.ConnectionConfiguration;
 import org.jivesoftware.smack.PacketListener;
+import org.jivesoftware.smack.PrivacyListManager;
 import org.jivesoftware.smack.Roster;
 import org.jivesoftware.smack.XMPPConnection;
 import org.jivesoftware.smack.Roster.SubscriptionMode;
@@ -234,7 +235,7 @@
 	else
 	    mService = null;
 	initConnectionConfig();
-	mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
+	mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);	
 	mConnection = new XmppConnectionAdapter(mConnectionConfiguration, mLogin, mPassword, this);
 	initRosterRequestListener();
 	mBind = new XmppFacade(mConnection, this);
--- a/src/com/beem/project/beem/service/PrivacyListAdapter.java	Tue Jun 23 11:22:20 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,39 +0,0 @@
-/**
- * 
- */
-package com.beem.project.beem.service;
-
-import java.util.List;
-
-import org.jivesoftware.smack.PrivacyListListener;
-import org.jivesoftware.smack.PrivacyListManager;
-import org.jivesoftware.smack.packet.PrivacyItem;
-
-/**
- * @author nikita
- *
- */
-public class PrivacyListAdapter {
-    private PrivacyListManager mAdaptee = null;
-   
-    
-    public PrivacyListAdapter(PrivacyListManager manager) {
-	mAdaptee = manager;
-    }
-    
-    class MyPrivacyListListener implements PrivacyListListener {
-
-	@Override
-	public void setPrivacyList(String listName, List<PrivacyItem> listItem) {
-	    // TODO Auto-generated method stub
-	    
-	}
-
-	@Override
-	public void updatedPrivacyList(String listName) {
-	    // TODO Auto-generated method stub
-	    
-	}
-	
-    }    
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/service/PrivacyListManagerAdapter.java	Tue Jun 23 11:59:21 2009 +0200
@@ -0,0 +1,85 @@
+/**
+ * 
+ */
+package com.beem.project.beem.service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jivesoftware.smack.PrivacyListListener;
+import org.jivesoftware.smack.PrivacyListManager;
+import org.jivesoftware.smack.XMPPConnection;
+import org.jivesoftware.smack.XMPPException;
+import org.jivesoftware.smack.packet.PrivacyItem;
+
+import android.os.RemoteException;
+import android.util.Log;
+
+import com.beem.project.beem.service.aidl.IPrivacyListManager;
+
+/**
+ * @author nikita
+ *
+ */
+public class PrivacyListManagerAdapter extends IPrivacyListManager.Stub {
+    public static final String TAG = "PrivacyListManagerAdapter";
+    private PrivacyListManager mAdaptee = null;
+    private List<String> mBlockedUser = new ArrayList<String>();
+    private XMPPConnection mConnection;
+    
+    public PrivacyListManagerAdapter(XMPPConnection connection) {
+	mConnection = connection;
+    }
+    
+    public List<String> getBlockedUsers() {
+	return mBlockedUser;
+    }
+    
+    public void addBlockedUser(String jid) {
+	if (mAdaptee == null) {
+	    PrivacyListManager.getInstanceFor(mConnection);
+	    if (mAdaptee == null) {
+		Log.e(TAG, "pas bon");
+	    }
+	    mAdaptee.addListener(new MyPrivacyListListener());
+	}
+	    
+	Log.d(TAG, "addBlockedUser");
+	PrivacyItem pItem = new PrivacyItem("jid", false, 0);
+	pItem.setValue(jid);
+	pItem.setFilterPresence_out(false);
+	List<PrivacyItem> pItemList = new ArrayList<PrivacyItem>();
+	pItemList.add(pItem);
+	try {
+	    mAdaptee.createPrivacyList(jid, pItemList);
+	} catch (XMPPException e) {
+	    // TODO Auto-generated catch block
+	    e.printStackTrace();
+	}
+    }
+    
+    class MyPrivacyListListener implements PrivacyListListener {
+
+	@Override
+	public void setPrivacyList(String listName, List<PrivacyItem> listItem) {
+	    Log.d(TAG,"setPrivacyList");
+	    
+	}
+
+	@Override
+	public void updatedPrivacyList(String listName) {
+	    Log.d(TAG,"updatedPrivacyList");
+	    
+	}	
+    }
+
+    @Override
+    public List<String> getBlockedUsersByList(String listName) throws RemoteException {
+	// TODO Auto-generated method stub
+	return null;
+    }
+
+    public PrivacyListManager getManager() {
+	return mAdaptee;
+    }   
+}
--- a/src/com/beem/project/beem/service/RosterAdapter.java	Tue Jun 23 11:22:20 2009 +0200
+++ b/src/com/beem/project/beem/service/RosterAdapter.java	Tue Jun 23 11:59:21 2009 +0200
@@ -5,9 +5,7 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
@@ -186,8 +184,8 @@
     }
 
     /**
-	 * 
-	 */
+     * 
+     */
     @Override
     public void setContactName(String jid, String name) throws RemoteException {
 	mContacts.get(jid).setName(name);
@@ -280,9 +278,7 @@
 	 */
 	@Override
 	public void presenceChanged(Presence presence) {
-	    Log.i(TAG, "Changement de Presence");
 	    String user = StringUtils.parseBareAddress(presence.getFrom());
-	    Log.d(TAG, "User : " + user);
 	    Contact c = mContacts.get(StringUtils.parseBareAddress(user));
 	    if (c == null) {
 		c = new Contact(user);
--- a/src/com/beem/project/beem/service/XmppConnectionAdapter.java	Tue Jun 23 11:22:20 2009 +0200
+++ b/src/com/beem/project/beem/service/XmppConnectionAdapter.java	Tue Jun 23 11:59:21 2009 +0200
@@ -35,7 +35,7 @@
     private String mLogin;
     private String mPassword;
     private RosterAdapter mRoster;
-    private PrivacyListAdapter mPrivacyList;
+    private PrivacyListManagerAdapter mPrivacyList;
     private BeemService mService;
     private RemoteCallbackList<IBeemConnectionListener> mRemoteConnListeners = new RemoteCallbackList<IBeemConnectionListener>();
 
@@ -111,15 +111,21 @@
     @Override
     public boolean connectSync() throws RemoteException {
 	try {
+	    try {
+		PrivacyListManager.getInstanceFor(mAdaptee);
+	    } catch (NullPointerException e){
+		Log.e(TAG, "pas normal", e);
+	    }
 	    mAdaptee.connect();
 	    mAdaptee.addConnectionListener(mConListener);
 	    mAdaptee.login(mLogin, mPassword, "BEEM");
 
 	    mChatManager = new BeemChatManager(mAdaptee.getChatManager(), mService);
-	    // TODO find why this cause a null pointer exception
+	    mPrivacyList = new PrivacyListManagerAdapter(mAdaptee);
+
 	    this.initFeatures(); // pour declarer les features xmpp qu'on supporte
-	    mPrivacyList = new PrivacyListAdapter(PrivacyListManager.getInstanceFor(mAdaptee));
 	    ChatStateManager.getInstance(mAdaptee);
+
 	    triggerAsynchronousConnectEvent();
 	    return true;
 	} catch (XMPPException e) {
@@ -165,7 +171,7 @@
 	Roster adap = mAdaptee.getRoster();
 	if (adap == null)
 	    return null;
-	mRoster = new RosterAdapter(adap);
+	mRoster = new RosterAdapter(adap);	
 	return mRoster;
     }
 
@@ -206,6 +212,19 @@
 	mConListener.onConnect();
     }
     /**
+     * @param mPrivacyList the mPrivacyList to set
+     */
+    public void setPrivacyList(PrivacyListManagerAdapter mPrivacyList) {
+	this.mPrivacyList = mPrivacyList;
+    }
+
+    /**
+     * @return the mPrivacyList
+     */
+    public PrivacyListManagerAdapter getPrivacyList() {
+	return mPrivacyList;
+    }
+    /**
      * Listener for XMPP connection events. It will calls the remote listeners for connexion events.
      * @author darisk
      */
@@ -223,6 +242,7 @@
 	@Override
 	public void connectionClosed() {
 	    mRoster = null;
+
 	    final int n = mRemoteConnListeners.beginBroadcast();
 
 	    for (int i = 0; i < n; i++) {
--- a/src/com/beem/project/beem/service/XmppFacade.java	Tue Jun 23 11:22:20 2009 +0200
+++ b/src/com/beem/project/beem/service/XmppFacade.java	Tue Jun 23 11:59:21 2009 +0200
@@ -117,4 +117,9 @@
 	presence2.setTo(presence.getTo());
 	mConnexion.getAdaptee().sendPacket(presence2);
     }
+
+    @Override
+    public void blockUser(String jid) throws RemoteException {
+	mConnexion.getPrivacyList().addBlockedUser(jid);
+    }
 }
--- a/src/com/beem/project/beem/service/aidl/IXmppFacade.aidl	Tue Jun 23 11:22:20 2009 +0200
+++ b/src/com/beem/project/beem/service/aidl/IXmppFacade.aidl	Tue Jun 23 11:59:21 2009 +0200
@@ -46,4 +46,5 @@
     
     void sendPresencePacket(in PresenceAdapter presence);
     
+    void blockUser(in String jid);
 }
--- a/src/com/beem/project/beem/ui/ContactDialog.java	Tue Jun 23 11:22:20 2009 +0200
+++ b/src/com/beem/project/beem/ui/ContactDialog.java	Tue Jun 23 11:59:21 2009 +0200
@@ -51,6 +51,8 @@
 	button.setOnClickListener(new resendListener());
 	button = (Button) findViewById(R.id.CDInfos);
 	button.setOnClickListener(new infosListener());
+	button = (Button) findViewById(R.id.CDBlock);
+	button.setOnClickListener(new blockListener());
 
 	mContext.bindService(new Intent(mContext, BeemService.class), mServConn, Service.BIND_AUTO_CREATE);
     }
@@ -74,6 +76,19 @@
 
     }
 
+    class blockListener implements View.OnClickListener {
+
+	@Override
+	public void onClick(View v) {
+	    try {
+		xmppFacade.blockUser("beem.test@gmail.com");
+	    } catch (RemoteException e) {
+		// TODO Auto-generated catch block
+		e.printStackTrace();
+	    }	    
+	}	
+    }
+
     class chatListener implements View.OnClickListener {
 
 	@Override
@@ -105,21 +120,19 @@
 			dismiss();
 		    }
 		}).setNegativeButton(a.getString(R.string.CDSure2DeleteNo), new DialogInterface.OnClickListener() {
-		public void onClick(DialogInterface dialog, int id) {
-		    dialog.cancel();
-		}
-	    });
+		    public void onClick(DialogInterface dialog, int id) {
+			dialog.cancel();
+		    }
+		});
 	    AlertDialog alert = builder.create();
 	    alert.show();
 	}
-
     }
 
     class infosListener implements View.OnClickListener {
 
 	@Override
-	public void onClick(View v) {
-	    // TODO Auto-generated method stub
+	public void onClick(View v) {	    
 	    dismiss();
 	}