# HG changeset patch # User Jean-Manuel Da Silva # Date 1258322599 -3600 # Node ID 6b8089c9b83428205806691fe89d2c88d3a3605f # Parent fd6c52c23165d9e936988832b900a7f1411e1427 Creation de l'activite PrivacyList et d'une interface PrivacyListListener ainsi que son implementation. diff -r fd6c52c23165 -r 6b8089c9b834 AndroidManifest.xml --- a/AndroidManifest.xml Sun Nov 15 20:40:15 2009 +0100 +++ b/AndroidManifest.xml Sun Nov 15 23:03:19 2009 +0100 @@ -2,10 +2,9 @@ - + @@ -26,8 +25,9 @@ - - + + @@ -74,6 +74,12 @@ android:name="com.beem.project.beem.service.XmppConnectionAdapter.CONNECTION_CLOSED" /> + + + + + diff -r fd6c52c23165 -r 6b8089c9b834 res/menu/edit_settings.xml --- a/res/menu/edit_settings.xml Sun Nov 15 20:40:15 2009 +0100 +++ b/res/menu/edit_settings.xml Sun Nov 15 23:03:19 2009 +0100 @@ -7,4 +7,8 @@ android:visible="true" android:title="@string/settings_menu_login" android:icon="@drawable/ic_menu_login" /> + diff -r fd6c52c23165 -r 6b8089c9b834 res/values-fr/strings.xml --- a/res/values-fr/strings.xml Sun Nov 15 20:40:15 2009 +0100 +++ b/res/values-fr/strings.xml Sun Nov 15 23:03:19 2009 +0100 @@ -180,6 +180,7 @@ --> Créer un compte Se connecter + Gérer mes listes privées Les paramètres ont été enregistrés avec succès. @@ -292,12 +293,16 @@ Conversations en cours Fermer cette conversation Aucune conversation en cours - + Disponible Disponible pour clavarder Occupé(e) Parti(e) Indisponible Hors ligne + + Beem - Gérer mes listes privées + Il n'existe aucune liste privée enregistrée. + Mettre à jour diff -r fd6c52c23165 -r 6b8089c9b834 res/values/strings.xml --- a/res/values/strings.xml Sun Nov 15 20:40:15 2009 +0100 +++ b/res/values/strings.xml Sun Nov 15 23:03:19 2009 +0100 @@ -165,6 +165,7 @@ Create an account Login + Manage my privacy lists The settings have been saved successfully. beem_account_username @@ -273,6 +274,9 @@ Away Unavailable Disconnected + + Beem - Manage my privacy lists + There aren't any privacy list registered. Update diff -r fd6c52c23165 -r 6b8089c9b834 src/com/beem/project/beem/BeemService.java --- a/src/com/beem/project/beem/BeemService.java Sun Nov 15 20:40:15 2009 +0100 +++ b/src/com/beem/project/beem/BeemService.java Sun Nov 15 23:03:19 2009 +0100 @@ -103,9 +103,9 @@ @Override public boolean onUnbind(Intent intent) { - Log.d("BEEMSERVICE", "ONUNBIND()"); + Log.d(TAG, "ONUNBIND()"); if (!mConnection.getAdaptee().isConnected()) { - Log.d("BEEMSERVICE", "DESTROYED"); + Log.d(TAG, "DESTROYED"); this.stopSelf(); } return true; diff -r fd6c52c23165 -r 6b8089c9b834 src/com/beem/project/beem/service/PrivacyListManagerAdapter.java --- a/src/com/beem/project/beem/service/PrivacyListManagerAdapter.java Sun Nov 15 20:40:15 2009 +0100 +++ b/src/com/beem/project/beem/service/PrivacyListManagerAdapter.java Sun Nov 15 23:03:19 2009 +0100 @@ -4,14 +4,17 @@ import java.util.List; import org.jivesoftware.smack.PrivacyList; +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.RemoteCallbackList; import android.os.RemoteException; import android.util.Log; +import com.beem.project.beem.service.aidl.IPrivacyListListener; import com.beem.project.beem.service.aidl.IPrivacyListManager; /** @@ -25,8 +28,11 @@ */ public static final String TAG = "PrivacyListManagerAdapter"; + private final XMPPConnection mXmppConnection; private final PrivacyListManager mPrivacyListManager; - private final XMPPConnection mXmppConnection; + + private final RemoteCallbackList mPrivacyListListeners = new RemoteCallbackList(); + private final PrivacyListListenerAdapter mPrivacyListListener = new PrivacyListListenerAdapter(); /** * Constructor. @@ -35,6 +41,7 @@ public PrivacyListManagerAdapter(final XMPPConnection connection) { mXmppConnection = connection; mPrivacyListManager = PrivacyListManager.getInstanceFor(mXmppConnection); + mPrivacyListManager.addListener(mPrivacyListListener); } @Override @@ -171,4 +178,66 @@ return rItems; } + + /** + * From a List of PrivacyItem get a List of PrivacyListItem. + * @param items The List of PrivacyItem. + * @return A list of PrivacyListItem. + */ + private List tranformPrivacyItemsToPrivacyListItems(List items) { + List rItems = new ArrayList(); + PrivacyItem.Type[] itemTypes = PrivacyItem.Type.values(); + + for (int i = 0; i < items.size(); i++) { + rItems.add(new PrivacyListItem(items.get(i).getType().ordinal(), items.get(i).getValue())); + } + return rItems; + } + + /** + * An adapter for the Smack's PrivacyListListener. + * @author Jean-Manuel Da Silva + */ + private class PrivacyListListenerAdapter implements PrivacyListListener { + + @Override + public void setPrivacyList(String listName, List listItem) { + final int n = mPrivacyListListeners.beginBroadcast(); + for (int i = 0; i < n; i++) { + IPrivacyListListener listener = mPrivacyListListeners.getBroadcastItem(i); + try { + listener.setPrivacyList(listName, tranformPrivacyItemsToPrivacyListItems(listItem)); + } catch (RemoteException e) { + Log.w(TAG, e.getMessage()); + } + } + mPrivacyListListeners.finishBroadcast(); + } + + @Override + public void updatedPrivacyList(String listName) { + final int n = mPrivacyListListeners.beginBroadcast(); + for (int i = 0; i < n; i++) { + IPrivacyListListener listener = mPrivacyListListeners.getBroadcastItem(i); + try { + listener.updatedPrivacyList(listName); + } catch (RemoteException e) { + Log.w(TAG, e.getMessage()); + } + } + mPrivacyListListeners.finishBroadcast(); + } + } + + @Override + public void addPrivacyListListener(IPrivacyListListener listener) throws RemoteException { + if (listener != null) + mPrivacyListListeners.register(listener); + } + + @Override + public void removePrivacyListListener(IPrivacyListListener listener) throws RemoteException { + if (listener != null) + mPrivacyListListeners.unregister(listener); + } } diff -r fd6c52c23165 -r 6b8089c9b834 src/com/beem/project/beem/service/XmppConnectionAdapter.java --- a/src/com/beem/project/beem/service/XmppConnectionAdapter.java Sun Nov 15 20:40:15 2009 +0100 +++ b/src/com/beem/project/beem/service/XmppConnectionAdapter.java Sun Nov 15 23:03:19 2009 +0100 @@ -48,7 +48,7 @@ private final String mLogin; private final String mPassword; private RosterAdapter mRoster; - private PrivacyListManagerAdapter mPrivacyList; + private PrivacyListManagerAdapter mPrivacyListManager; private final BeemService mService; private final RemoteCallbackList mRemoteConnListeners = new RemoteCallbackList(); @@ -133,7 +133,7 @@ mAdaptee.login(mLogin, mPassword, "BEEM"); mChatManager = new BeemChatManager(mAdaptee.getChatManager(), mService); - mPrivacyList = new PrivacyListManagerAdapter(mAdaptee); + mPrivacyListManager = new PrivacyListManagerAdapter(mAdaptee); this.initFeatures(); // pour declarer les features xmpp qu'on // supporte @@ -141,8 +141,8 @@ triggerAsynchronousConnectEvent(); // Priority between -128 and 128 - Presence p = new Presence(Presence.Type.available, "Beem : http://www.beem-project.com", PRESENCE_PRIORITY, - Presence.Mode.available); + Presence p = new Presence(Presence.Type.available, "Beem : http://www.beem-project.com", + PRESENCE_PRIORITY, Presence.Mode.available); mAdaptee.sendPacket(p); return true; } catch (XMPPException e) { @@ -244,19 +244,19 @@ } /** - * Set the privacy list to use. - * @param privacyList the mPrivacyList to set + * PrivacyListManagerAdapter mutator. + * @param privacyList the PrivacyListManager to set */ - public void setPrivacyList(PrivacyListManagerAdapter privacyList) { - this.mPrivacyList = privacyList; + public void setPrivacyListManager(PrivacyListManagerAdapter privacyListManager) { + this.mPrivacyListManager = privacyListManager; } /** - * Get the privacy list in use. + * PrivacyListManagerAdapter accessor. * @return the mPrivacyList */ - public PrivacyListManagerAdapter getPrivacyList() { - return mPrivacyList; + public PrivacyListManagerAdapter getPrivacyListManager() { + return mPrivacyListManager; } /** @@ -343,13 +343,14 @@ @Override public void processPacket(Packet packet) { String from = packet.getFrom(); - Notification notif = new Notification(android.R.drawable.stat_notify_more, mService - .getString(R.string.AcceptContactRequest, from), System.currentTimeMillis()); + Notification notif = new Notification(android.R.drawable.stat_notify_more, mService.getString( + R.string.AcceptContactRequest, from), System.currentTimeMillis()); notif.defaults = Notification.DEFAULT_ALL; notif.flags = Notification.FLAG_AUTO_CANCEL; Intent intent = new Intent(mService, Subscription.class); intent.putExtra("from", from); - notif.setLatestEventInfo(mService, from, mService.getString(R.string.AcceptContactRequestFrom, from), PendingIntent.getActivity(mService, 0, intent, PendingIntent.FLAG_ONE_SHOT)); + notif.setLatestEventInfo(mService, from, mService.getString(R.string.AcceptContactRequestFrom, + from), PendingIntent.getActivity(mService, 0, intent, PendingIntent.FLAG_ONE_SHOT)); int id = packet.hashCode(); mService.sendNotification(id, notif); } @@ -442,13 +443,14 @@ @Override public void processPacket(Packet packet) { String from = packet.getFrom(); - Notification notif = new Notification(android.R.drawable.stat_notify_more, mService - .getString(R.string.AcceptContactRequest, from), System.currentTimeMillis()); + Notification notif = new Notification(android.R.drawable.stat_notify_more, mService.getString( + R.string.AcceptContactRequest, from), System.currentTimeMillis()); notif.defaults = Notification.DEFAULT_ALL; notif.flags = Notification.FLAG_AUTO_CANCEL; Intent intent = new Intent(mService, Subscription.class); intent.putExtra("from", from); - notif.setLatestEventInfo(mService, from, mService.getString(R.string.AcceptContactRequestFrom, from), PendingIntent.getActivity(mService, 0, intent, PendingIntent.FLAG_ONE_SHOT)); + notif.setLatestEventInfo(mService, from, mService.getString(R.string.AcceptContactRequestFrom, + from), PendingIntent.getActivity(mService, 0, intent, PendingIntent.FLAG_ONE_SHOT)); int id = packet.hashCode(); mService.sendNotification(id, notif); } diff -r fd6c52c23165 -r 6b8089c9b834 src/com/beem/project/beem/service/XmppFacade.java --- a/src/com/beem/project/beem/service/XmppFacade.java Sun Nov 15 20:40:15 2009 +0100 +++ b/src/com/beem/project/beem/service/XmppFacade.java Sun Nov 15 23:03:19 2009 +0100 @@ -12,6 +12,7 @@ import com.beem.project.beem.BeemService; import com.beem.project.beem.jingle.JingleService; import com.beem.project.beem.service.aidl.IChatManager; +import com.beem.project.beem.service.aidl.IPrivacyListManager; import com.beem.project.beem.service.aidl.IRoster; import com.beem.project.beem.service.aidl.IXmppConnection; import com.beem.project.beem.service.aidl.IXmppFacade; @@ -116,6 +117,14 @@ return mConnexion.getRoster(); } + /** + * {@inheritDoc} + */ + @Override + public IPrivacyListManager getPrivacyListManager() { + return mConnexion.getPrivacyListManager(); + } + @Override public void sendPresencePacket(PresenceAdapter presence) throws RemoteException { Presence presence2 = new Presence(PresenceType.getPresenceTypeFrom(presence.getType())); diff -r fd6c52c23165 -r 6b8089c9b834 src/com/beem/project/beem/service/aidl/IPrivacyListListener.aidl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/aidl/IPrivacyListListener.aidl Sun Nov 15 23:03:19 2009 +0100 @@ -0,0 +1,8 @@ +package com.beem.project.beem.service.aidl; + +import com.beem.project.beem.service.PrivacyListItem; + +interface IPrivacyListListener { + void updatedPrivacyList(in String listName); + void setPrivacyList(in String listName, in List listItem); +} diff -r fd6c52c23165 -r 6b8089c9b834 src/com/beem/project/beem/service/aidl/IPrivacyListManager.aidl --- a/src/com/beem/project/beem/service/aidl/IPrivacyListManager.aidl Sun Nov 15 20:40:15 2009 +0100 +++ b/src/com/beem/project/beem/service/aidl/IPrivacyListManager.aidl Sun Nov 15 23:03:19 2009 +0100 @@ -1,31 +1,21 @@ package com.beem.project.beem.service.aidl; import com.beem.project.beem.service.PrivacyListItem; +import com.beem.project.beem.service.aidl.IPrivacyListListener; interface IPrivacyListManager { - void createPrivacyList(in String listName, in List items); - void removePrivacyList(in String listName); - void editPrivacyList(in String listName, in List items); - String getActivePrivacyList(); - String getDefaultPrivacyList(); - void setActivePrivacyList(in String listName); - void setDefaultPrivacyList(in String listName); - void declineActivePrivacyList(); - void declineDefaultPrivacyList(); - void blockUser(in String listName, in String jid); - List getBlockedUsersByList(in String listName); - List getBlockedGroupsByList(in String listName); - + void addPrivacyListListener(in IPrivacyListListener listener); + void removePrivacyListListener(in IPrivacyListListener listener); } \ No newline at end of file diff -r fd6c52c23165 -r 6b8089c9b834 src/com/beem/project/beem/service/aidl/IXmppConnection.aidl --- a/src/com/beem/project/beem/service/aidl/IXmppConnection.aidl Sun Nov 15 20:40:15 2009 +0100 +++ b/src/com/beem/project/beem/service/aidl/IXmppConnection.aidl Sun Nov 15 23:03:19 2009 +0100 @@ -3,6 +3,7 @@ import com.beem.project.beem.service.aidl.IRoster; import com.beem.project.beem.service.aidl.IBeemConnectionListener; import com.beem.project.beem.service.aidl.IChatManager; +import com.beem.project.beem.service.aidl.IPrivacyListManager; interface IXmppConnection { @@ -20,4 +21,6 @@ boolean isAuthentificated(); IChatManager getChatManager(); -} \ No newline at end of file + + IPrivacyListManager getPrivacyListManager(); +} diff -r fd6c52c23165 -r 6b8089c9b834 src/com/beem/project/beem/service/aidl/IXmppFacade.aidl --- a/src/com/beem/project/beem/service/aidl/IXmppFacade.aidl Sun Nov 15 20:40:15 2009 +0100 +++ b/src/com/beem/project/beem/service/aidl/IXmppFacade.aidl Sun Nov 15 23:03:19 2009 +0100 @@ -3,6 +3,7 @@ import com.beem.project.beem.service.aidl.IXmppConnection; import com.beem.project.beem.service.aidl.IRoster; import com.beem.project.beem.service.aidl.IChatManager; +import com.beem.project.beem.service.aidl.IPrivacyListManager; import com.beem.project.beem.service.PresenceAdapter; interface IXmppFacade { @@ -52,9 +53,11 @@ */ void call(in String jid); - /** - * get the user vcard avatar - * @param jid the user jid - */ - byte[] getVcardAvatar(in String jid); + /** + * get the user vcard avatar + * @param jid the user jid + */ + byte[] getVcardAvatar(in String jid); + + IPrivacyListManager getPrivacyListManager(); } diff -r fd6c52c23165 -r 6b8089c9b834 src/com/beem/project/beem/ui/Chat.java --- a/src/com/beem/project/beem/ui/Chat.java Sun Nov 15 20:40:15 2009 +0100 +++ b/src/com/beem/project/beem/ui/Chat.java Sun Nov 15 23:03:19 2009 +0100 @@ -705,7 +705,7 @@ private String mMessage; /** - * Construtor. + * Constructor. * @param bareJid A String containing the bare JID of the message's author. * @param name A String containing the name of the message's author. * @param message A String containing the message. @@ -859,12 +859,4 @@ } Log.v(TAG, "END sendMessage."); } - - private final OnClickListener mSendButtonClickListener = new OnClickListener() { - - @Override - public void onClick(View v) { - sendMessage(); - } - }; } diff -r fd6c52c23165 -r 6b8089c9b834 src/com/beem/project/beem/ui/PrivacyList.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/ui/PrivacyList.java Sun Nov 15 23:03:19 2009 +0100 @@ -0,0 +1,128 @@ +package com.beem.project.beem.ui; + +import java.util.ArrayList; +import java.util.List; + +import android.app.ListActivity; +import android.content.ComponentName; +import android.content.Intent; +import android.content.IntentFilter; +import android.content.ServiceConnection; +import android.os.Bundle; +import android.os.IBinder; +import android.os.RemoteException; +import android.util.Log; +import android.widget.ArrayAdapter; + +import com.beem.project.beem.BeemService; +import com.beem.project.beem.R; +import com.beem.project.beem.service.aidl.IPrivacyListManager; +import com.beem.project.beem.service.aidl.IXmppFacade; +import com.beem.project.beem.utils.BeemBroadcastReceiver; + +/** + * This class represents an activity which allows the user to manage his privacy lists. + * @author Jean-Manuel Da Silva + */ +public class PrivacyList extends ListActivity { + + private static final String TAG = "PrivacyList"; + private static final Intent SERVICE_INTENT = new Intent(); + static { + SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService")); + } + + private ArrayAdapter mAdapter; + private final List mPrivacyListNames = new ArrayList(); + + private final ServiceConnection mConn = new BeemServiceConnection(); + private BeemBroadcastReceiver mBroadcastReceiver; + private IPrivacyListManager mPrivacyListManager; + + /** + * Constructor. + */ + public PrivacyList() { + super(); + } + + /** + * {@inheritDoc}. + */ + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + Log.d(TAG, "BEGIN onCreate."); + setContentView(R.layout.privacy_list); + + mAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, mPrivacyListNames); + setListAdapter(mAdapter); + + mBroadcastReceiver = new BeemBroadcastReceiver(mConn); + this.registerReceiver(mBroadcastReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED)); + + Log.d(TAG, "END onCreate."); + } + + /** + * {@inheritDoc}. + */ + @Override + protected void onDestroy() { + super.onDestroy(); + + Log.v(TAG, "BEGIN onDestroy."); + this.unregisterReceiver(mBroadcastReceiver); + Log.v(TAG, "END onDestroy."); + } + + /** + * {@inheritDoc}. + */ + @Override + protected void onStart() { + super.onStart(); + + Log.v(TAG, "BEGIN onStart."); + bindService(new Intent(this, BeemService.class), mConn, BIND_AUTO_CREATE); + Log.v(TAG, "END onStart."); + } + + /** + * {@inheritDoc}. + */ + @Override + protected void onStop() { + super.onStop(); + + Log.v(TAG, "BEGIN onStop."); + if (mBroadcastReceiver.isBinded()) { + unbindService(mConn); + } + Log.v(TAG, "END onStop."); + } + + private final class BeemServiceConnection implements ServiceConnection { + + private IXmppFacade mXmppFacade; + + @Override + public void onServiceConnected(ComponentName name, IBinder service) { + Log.v(TAG, "BEGIN onServiceConnected."); + mXmppFacade = IXmppFacade.Stub.asInterface(service); + try { + mPrivacyListManager = mXmppFacade.getPrivacyListManager(); + } catch (RemoteException e) { + Log.e(TAG, e.getMessage()); + } + Log.v(TAG, "END onServiceConnected."); + } + + @Override + public void onServiceDisconnected(ComponentName name) { + Log.v(TAG, "BEGIN onServiceDisconnected."); + mXmppFacade = null; + Log.v(TAG, "END onServiceDisconnected."); + } + } +} diff -r fd6c52c23165 -r 6b8089c9b834 src/com/beem/project/beem/ui/Settings.java --- a/src/com/beem/project/beem/ui/Settings.java Sun Nov 15 20:40:15 2009 +0100 +++ b/src/com/beem/project/beem/ui/Settings.java Sun Nov 15 23:03:19 2009 +0100 @@ -17,7 +17,6 @@ /** * This class represents an activity which allows the user to change his account or proxy parameters. - * @author nikita */ public class Settings extends PreferenceActivity { @@ -103,6 +102,10 @@ this.stopService(SERVICE_INTENT); finish(); return true; + case R.id.settings_menu_privacy_lists: + i = new Intent(this, PrivacyList.class); + startActivity(i); + return true; default: return false; }