Ajout de la possibilite de creer une PrivacyList et de la liste de PrivacyLists. Debug requis.
authorJean-Manuel Da Silva <dasilvj@gmail.com>
Mon, 16 Nov 2009 02:00:06 +0100
changeset 520 88a19fcd70b3
parent 519 ea7009295a84
child 521 0444ac5038a0
child 522 19ced4af7386
Ajout de la possibilite de creer une PrivacyList et de la liste de PrivacyLists. Debug requis.
res/layout/privacy_list_create_dialog.xml
res/menu/privacy_list.xml
res/values-fr/strings.xml
res/values/strings.xml
src/com/beem/project/beem/service/PrivacyListManagerAdapter.java
src/com/beem/project/beem/service/aidl/IPrivacyListManager.aidl
src/com/beem/project/beem/ui/Chat.java
src/com/beem/project/beem/ui/PrivacyList.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/res/layout/privacy_list_create_dialog.xml	Mon Nov 16 02:00:06 2009 +0100
@@ -0,0 +1,14 @@
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+	android:layout_width="fill_parent" android:layout_height="wrap_content"
+	android:orientation="vertical">
+	<TextView android:id="@+id/privacy_list_create_dialog_list_name_label"
+		android:layout_height="wrap_content" android:layout_width="wrap_content"
+		android:layout_marginLeft="20dip" android:layout_marginRight="20dip"
+		android:text="@string/privacy_list_create_dialog_list_name_label" android:gravity="left"
+		style="@style/Label" />
+	<EditText android:id="@+id/privacy_list_create_dialog_list_name"
+		android:layout_height="wrap_content" android:layout_width="fill_parent"
+		android:layout_marginLeft="20dip" android:layout_marginRight="20dip"
+		android:scrollHorizontally="true" android:autoText="false"
+		android:capitalize="none" android:gravity="fill_horizontal" />
+</LinearLayout>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/res/menu/privacy_list.xml	Mon Nov 16 02:00:06 2009 +0100
@@ -0,0 +1,4 @@
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+	<item android:id="@+id/privacy_list_menu_create" android:visible="true"
+		android:title="@string/privacy_list_menu_create" android:icon="@drawable/ic_menu_add" />
+</menu>
--- a/res/values-fr/strings.xml	Sun Nov 15 23:03:54 2009 +0100
+++ b/res/values-fr/strings.xml	Mon Nov 16 02:00:06 2009 +0100
@@ -303,6 +303,10 @@
 
 	<string name="privacy_list_name">Beem - Gérer mes listes privées</string>
 	<string name="privacy_list_no_data">Il n'existe aucune liste privée enregistrée.</string>
+	<string name="privacy_list_menu_create">Créer une liste privée</string>
+	<string name="privacy_list_create_dialog_title">Créer une liste privée</string>
+	<string name="privacy_list_create_dialog_list_name_label">Titre</string>
+	<string name="privacy_list_create_dialog_create_button">Créer</string>
 
 	<string name="UpdateButton">Mettre à jour</string>
 </resources>
--- a/res/values/strings.xml	Sun Nov 15 23:03:54 2009 +0100
+++ b/res/values/strings.xml	Mon Nov 16 02:00:06 2009 +0100
@@ -267,16 +267,20 @@
 	<string name="chat_dialog_change_chat_title">Opened chats</string>
 	<string name="chat_menu_close_chat">Close this chat</string>
 	<string name="chat_no_more_chats">No more active chats</string>
-	
+
 	<string name="contact_status_msg_available">Available</string>
 	<string name="contact_status_msg_available_chat">Available to chat</string>
 	<string name="contact_status_msg_dnd">Do not disturb</string>
 	<string name="contact_status_msg_away">Away</string>
 	<string name="contact_status_msg_xa">Unavailable</string>
 	<string name="contact_status_msg_offline">Disconnected</string>
-	
+
 	<string name="privacy_list_name">Beem - Manage my privacy lists</string>
 	<string name="privacy_list_no_data">There aren't any privacy list registered.</string>
+	<string name="privacy_list_menu_create">Create a privacy list</string>
+	<string name="privacy_list_create_dialog_title">Create a privacy list</string>
+	<string name="privacy_list_create_dialog_list_name_label">Title</string>
+	<string name="privacy_list_create_dialog_create_button">Create</string>
 
 	<string name="UpdateButton">Update</string>
 </resources>
--- a/src/com/beem/project/beem/service/PrivacyListManagerAdapter.java	Sun Nov 15 23:03:54 2009 +0100
+++ b/src/com/beem/project/beem/service/PrivacyListManagerAdapter.java	Mon Nov 16 02:00:06 2009 +0100
@@ -240,4 +240,19 @@
 	if (listener != null)
 	    mPrivacyListListeners.unregister(listener);
     }
+
+    @Override
+    public List<String> getPrivacyLists() throws RemoteException {
+	List<String> res = new ArrayList<String>();
+	try {
+	    PrivacyList[] serverPrivacyLists = mPrivacyListManager.getPrivacyLists();
+	    if (serverPrivacyLists.length > 0) {
+		for (int i = 0; i < serverPrivacyLists.length; i++)
+		    res.add(serverPrivacyLists[i].toString());
+	    }
+	} catch (XMPPException e) {
+	    Log.e(TAG, e.getMessage());
+	}
+	return res;
+    }
 }
--- a/src/com/beem/project/beem/service/aidl/IPrivacyListManager.aidl	Sun Nov 15 23:03:54 2009 +0100
+++ b/src/com/beem/project/beem/service/aidl/IPrivacyListManager.aidl	Mon Nov 16 02:00:06 2009 +0100
@@ -13,6 +13,7 @@
 	void setDefaultPrivacyList(in String listName);
 	void declineActivePrivacyList();
 	void declineDefaultPrivacyList();
+	List<String> getPrivacyLists();
 	void blockUser(in String listName, in String jid);
 	List<String> getBlockedUsersByList(in String listName);
 	List<String> getBlockedGroupsByList(in String listName);
--- a/src/com/beem/project/beem/ui/Chat.java	Sun Nov 15 23:03:54 2009 +0100
+++ b/src/com/beem/project/beem/ui/Chat.java	Mon Nov 16 02:00:06 2009 +0100
@@ -67,7 +67,7 @@
     static {
 	SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
     }
-    private Handler mHandler = new Handler();
+    private Handler mHandler;
 
     private IRoster mRoster;
     private Contact mContact;
--- a/src/com/beem/project/beem/ui/PrivacyList.java	Sun Nov 15 23:03:54 2009 +0100
+++ b/src/com/beem/project/beem/ui/PrivacyList.java	Mon Nov 16 02:00:06 2009 +0100
@@ -3,19 +3,30 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import android.app.AlertDialog;
 import android.app.ListActivity;
 import android.content.ComponentName;
+import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.ServiceConnection;
 import android.os.Bundle;
+import android.os.Handler;
 import android.os.IBinder;
 import android.os.RemoteException;
 import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.View;
 import android.widget.ArrayAdapter;
+import android.widget.EditText;
 
 import com.beem.project.beem.BeemService;
 import com.beem.project.beem.R;
+import com.beem.project.beem.service.PrivacyListItem;
+import com.beem.project.beem.service.aidl.IPrivacyListListener;
 import com.beem.project.beem.service.aidl.IPrivacyListManager;
 import com.beem.project.beem.service.aidl.IXmppFacade;
 import com.beem.project.beem.utils.BeemBroadcastReceiver;
@@ -31,13 +42,16 @@
     static {
 	SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
     }
+    private Handler mHandler = new Handler();
 
     private ArrayAdapter<String> mAdapter;
     private final List<String> mPrivacyListNames = new ArrayList<String>();
 
     private final ServiceConnection mConn = new BeemServiceConnection();
     private BeemBroadcastReceiver mBroadcastReceiver;
+
     private IPrivacyListManager mPrivacyListManager;
+    private IPrivacyListListener mPrivacyListListener;
 
     /**
      * Constructor.
@@ -55,9 +69,12 @@
 	Log.d(TAG, "BEGIN onCreate.");
 	setContentView(R.layout.privacy_list);
 
+	mHandler = new Handler();
+
 	mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mPrivacyListNames);
 	setListAdapter(mAdapter);
 
+	mPrivacyListListener = new PrivacyListListener();
 	mBroadcastReceiver = new BeemBroadcastReceiver(mConn);
 	this.registerReceiver(mBroadcastReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
 
@@ -102,6 +119,32 @@
 	Log.v(TAG, "END onStop.");
     }
 
+    /**
+     * {@inheritDoc}.
+     */
+    @Override
+    public final boolean onCreateOptionsMenu(Menu menu) {
+	super.onCreateOptionsMenu(menu);
+
+	MenuInflater inflater = getMenuInflater();
+	inflater.inflate(R.menu.privacy_list, menu);
+	return true;
+    }
+
+    /**
+     * {@inheritDoc}.
+     */
+    @Override
+    public final boolean onOptionsItemSelected(MenuItem item) {
+	switch (item.getItemId()) {
+	    case R.id.privacy_list_menu_create:
+		createCreatePrivacyListDialog();
+		return true;
+	    default:
+		return false;
+	}
+    }
+
     private final class BeemServiceConnection implements ServiceConnection {
 
 	private IXmppFacade mXmppFacade;
@@ -110,8 +153,18 @@
 	public void onServiceConnected(ComponentName name, IBinder service) {
 	    Log.v(TAG, "BEGIN onServiceConnected.");
 	    mXmppFacade = IXmppFacade.Stub.asInterface(service);
+	    mBroadcastReceiver.setBinded(true);
 	    try {
 		mPrivacyListManager = mXmppFacade.getPrivacyListManager();
+		mPrivacyListManager.addPrivacyListListener(mPrivacyListListener);
+		/**
+		 * FIXME: ERROR /AndroidRuntime(21999): java.lang.ClassCastException:
+		 * org.jivesoftware.smack.PacketReader$4 ERROR/AndroidRuntime(21999): at
+		 * org.jivesoftware.smack.PrivacyListManager.getRequest(PrivacyListManager.java:189) at
+		 * org.jivesoftware.smack.PrivacyListManager.getPrivacyWithListNames(PrivacyListManager.java:254)
+		 */
+		// mPrivacyListNames = mPrivacyListManager.getPrivacyLists();
+		// mAdapter.notifyDataSetChanged();
 	    } catch (RemoteException e) {
 		Log.e(TAG, e.getMessage());
 	    }
@@ -122,7 +175,55 @@
 	public void onServiceDisconnected(ComponentName name) {
 	    Log.v(TAG, "BEGIN onServiceDisconnected.");
 	    mXmppFacade = null;
+	    mBroadcastReceiver.setBinded(false);
 	    Log.v(TAG, "END onServiceDisconnected.");
 	}
     }
+
+    private class PrivacyListListener extends IPrivacyListListener.Stub {
+
+	@Override
+	public void setPrivacyList(String listName, List<PrivacyListItem> listItem) throws RemoteException {
+	    Log.d(TAG, "BEGIN PrivacyListListener >> setPrivacyList.");
+	    Log.d(TAG, listName);
+	    Log.d(TAG, "END PrivacyListListener >> setPrivacyList.");
+	}
+
+	@Override
+	public void updatedPrivacyList(String listName) throws RemoteException {
+	    Log.d(TAG, "BEGIN PrivacyListListener >> updatedPrivacyList.");
+	    Log.d(TAG, listName);
+	    Log.d(TAG, "END PrivacyListListener >> updatedPrivacyList.");
+	}
+    }
+
+    private void createCreatePrivacyListDialog() {
+	LayoutInflater factory = LayoutInflater.from(this);
+	final View textEntryView = factory.inflate(R.layout.privacy_list_create_dialog, null);
+	AlertDialog.Builder builder = new AlertDialog.Builder(this);
+	builder.setTitle(R.string.privacy_list_create_dialog_title);
+	builder.setView(textEntryView);
+
+	builder.setPositiveButton(R.string.privacy_list_create_dialog_create_button,
+	    new DialogInterface.OnClickListener() {
+		public void onClick(DialogInterface dialog, int whichButton) {
+		    EditText listNameField = (EditText) textEntryView
+			.findViewById(R.id.privacy_list_create_dialog_list_name);
+		    try {
+			mPrivacyListManager.createPrivacyList(listNameField.getText().toString(),
+			    new ArrayList<PrivacyListItem>());
+		    } catch (RemoteException e) {
+			Log.e(TAG, e.getMessage());
+		    }
+		}
+	    });
+
+	builder.setNegativeButton(R.string.CancelButton, new DialogInterface.OnClickListener() {
+	    public void onClick(DialogInterface dialog, int whichButton) {
+	    }
+	});
+
+	AlertDialog createPrivacyListDialog = builder.create();
+	createPrivacyListDialog.show();
+    }
 }