src/com/beem/project/beem/service/PrivacyListManagerAdapter.java
changeset 502 3091acfe31f4
parent 360 13356aeb873c
child 503 93e5d2d9953f
equal deleted inserted replaced
501:d52918cfaba7 502:3091acfe31f4
    15 
    15 
    16 import com.beem.project.beem.service.aidl.IPrivacyListManager;
    16 import com.beem.project.beem.service.aidl.IPrivacyListManager;
    17 
    17 
    18 /**
    18 /**
    19  * Privacy list manager in beem.
    19  * Privacy list manager in beem.
       
    20  * 
    20  * @author nikita
    21  * @author nikita
    21  */
    22  */
    22 public class PrivacyListManagerAdapter extends IPrivacyListManager.Stub {
    23 public class PrivacyListManagerAdapter extends IPrivacyListManager.Stub {
    23 
    24 
    24     /**
    25 	/**
    25      * Tag.
    26 	 * Tag.
    26      */
    27 	 */
    27     public static final String TAG = "PrivacyListManagerAdapter";
    28 	public static final String TAG = "PrivacyListManagerAdapter";
    28     /**
    29 	/**
    29      * default privacy list name.
    30 	 * default privacy list name.
    30      */
    31 	 */
    31     public static final String DEFAULT_PRIVACYLIST = "default";
    32 	public static final String DEFAULT_PRIVACYLIST = "default";
    32 
    33 
    33     private PrivacyListManager mAdaptee;
    34 	private PrivacyListManager mAdaptee;
    34     private List<String> mBlockedUser = new ArrayList<String>();
    35 	private List<String> mBlockedUser = new ArrayList<String>();
    35     private XMPPConnection mConnection;
    36 	private XMPPConnection mConnection;
    36     private MyPrivacyListListener mPrivacyPacketListener = new MyPrivacyListListener();
    37 	private MyPrivacyListListener mPrivacyPacketListener = new MyPrivacyListListener();
    37 
    38 
    38     /**
    39 	/**
    39      * Privacy list constructor.
    40 	 * Privacy list constructor.
    40      * @param connection xmppconnection used.
    41 	 * 
    41      */
    42 	 * @param connection
    42     public PrivacyListManagerAdapter(final XMPPConnection connection) {
    43 	 *            xmppconnection used.
    43 	mConnection = connection;
    44 	 */
    44 	mAdaptee = PrivacyListManager.getInstanceFor(mConnection);
    45 	public PrivacyListManagerAdapter(final XMPPConnection connection) {
    45 	mAdaptee.addListener(mPrivacyPacketListener);
    46 		mConnection = connection;
    46     }
    47 		mAdaptee = PrivacyListManager.getInstanceFor(mConnection);
    47 
    48 		mAdaptee.addListener(mPrivacyPacketListener);
    48     /**
       
    49      * return the blocked user list.
       
    50      * @return blocked user list
       
    51      */
       
    52     public List<String> getBlockedUsers() {
       
    53 	return mBlockedUser;
       
    54     }
       
    55 
       
    56     /**
       
    57      * add an user to the blocked user list.
       
    58      * @param jid blocked user jid
       
    59      */
       
    60     public synchronized void addBlockedUser(final String jid) {
       
    61 	if (mAdaptee == null) {
       
    62 	    mAdaptee = PrivacyListManager.getInstanceFor(mConnection);
       
    63 	    mAdaptee.addListener(mPrivacyPacketListener);
       
    64 	}
       
    65 	List<PrivacyItem> pItemList = new ArrayList<PrivacyItem>();
       
    66 	PrivacyItem pItem = new PrivacyItem("jid", true, 1);
       
    67 	pItem.setFilterMessage(true);
       
    68 	pItem.setValue(jid);
       
    69 	pItemList.add(pItem);
       
    70 
       
    71 	pItem = new PrivacyItem("subscription", true, 2);
       
    72 	pItem.setValue(PrivacyRule.SUBSCRIPTION_BOTH);
       
    73 	pItemList.add(pItem);
       
    74 
       
    75 	try {
       
    76 	    if (mAdaptee.getPrivacyList(DEFAULT_PRIVACYLIST) == null) {
       
    77 		mAdaptee.createPrivacyList(DEFAULT_PRIVACYLIST, pItemList);
       
    78 	    }
       
    79 
       
    80 	} catch (XMPPException e) {
       
    81 	    // TODO Auto-generated catch block
       
    82 	    e.printStackTrace();
       
    83 	} catch (ClassCastException e) {
       
    84 	    e.printStackTrace();
       
    85 	    try {
       
    86 		mAdaptee.createPrivacyList(DEFAULT_PRIVACYLIST, pItemList);
       
    87 	    } catch (XMPPException e1) {
       
    88 		// TODO Auto-generated catch block
       
    89 		e1.printStackTrace();
       
    90 	    }
       
    91 	}
       
    92 	try {
       
    93 	    mAdaptee.setActiveListName(DEFAULT_PRIVACYLIST);
       
    94 	    mAdaptee.setDefaultListName(DEFAULT_PRIVACYLIST);
       
    95 	} catch (XMPPException e) {
       
    96 	    // TODO Auto-generated catch block
       
    97 	    e.printStackTrace();
       
    98 	}
    49 	}
    99 
    50 
   100 	Log.d(TAG, "addBlockedUser");
    51 	/**
   101     }
    52 	 * return the blocked user list.
       
    53 	 * 
       
    54 	 * @return blocked user list
       
    55 	 */
       
    56 	public List<String> getBlockedUsers() {
       
    57 		return mBlockedUser;
       
    58 	}
   102 
    59 
   103     /**
       
   104      * privacy list listener.
       
   105      * @author nikita
       
   106      */
       
   107     class MyPrivacyListListener implements PrivacyListListener {
       
   108 	/**
    60 	/**
   109 	 * constructor.
    61 	 * add an user to the blocked user list.
       
    62 	 * 
       
    63 	 * @param jid
       
    64 	 *            blocked user jid
   110 	 */
    65 	 */
   111 	public MyPrivacyListListener() {
    66 	public synchronized void addBlockedUser(final String jid) {
       
    67 		if (mAdaptee == null) {
       
    68 			mAdaptee = PrivacyListManager.getInstanceFor(mConnection);
       
    69 			mAdaptee.addListener(mPrivacyPacketListener);
       
    70 		}
       
    71 		List<PrivacyItem> pItemList = new ArrayList<PrivacyItem>();
       
    72 		PrivacyItem pItem = new PrivacyItem("jid", true, 1);
       
    73 		pItem.setFilterMessage(true);
       
    74 		pItem.setValue(jid);
       
    75 		pItemList.add(pItem);
       
    76 
       
    77 		pItem = new PrivacyItem("subscription", true, 2);
       
    78 		pItem.setValue(PrivacyRule.SUBSCRIPTION_BOTH);
       
    79 		pItemList.add(pItem);
       
    80 
       
    81 		try {
       
    82 			if (mAdaptee.getPrivacyList(DEFAULT_PRIVACYLIST) == null) {
       
    83 				mAdaptee.createPrivacyList(DEFAULT_PRIVACYLIST, pItemList);
       
    84 			}
       
    85 
       
    86 		} catch (XMPPException e) {
       
    87 			// TODO Auto-generated catch block
       
    88 			e.printStackTrace();
       
    89 		} catch (ClassCastException e) {
       
    90 			e.printStackTrace();
       
    91 			try {
       
    92 				mAdaptee.createPrivacyList(DEFAULT_PRIVACYLIST, pItemList);
       
    93 			} catch (XMPPException e1) {
       
    94 				// TODO Auto-generated catch block
       
    95 				e1.printStackTrace();
       
    96 			}
       
    97 		}
       
    98 		try {
       
    99 			mAdaptee.setActiveListName(DEFAULT_PRIVACYLIST);
       
   100 			mAdaptee.setDefaultListName(DEFAULT_PRIVACYLIST);
       
   101 		} catch (XMPPException e) {
       
   102 			// TODO Auto-generated catch block
       
   103 			e.printStackTrace();
       
   104 		}
       
   105 
       
   106 		Log.d(TAG, "addBlockedUser");
       
   107 	}
       
   108 
       
   109 	/**
       
   110 	 * privacy list listener.
       
   111 	 * 
       
   112 	 * @author nikita
       
   113 	 */
       
   114 	class MyPrivacyListListener implements PrivacyListListener {
       
   115 		/**
       
   116 		 * constructor.
       
   117 		 */
       
   118 		public MyPrivacyListListener() {
       
   119 		}
       
   120 
       
   121 		@Override
       
   122 		public void setPrivacyList(String listName, List<PrivacyItem> listItem) {
       
   123 			Log.d(TAG, "setPrivacyList");
       
   124 		}
       
   125 
       
   126 		@Override
       
   127 		public void updatedPrivacyList(String listName) {
       
   128 			Log.d(TAG, "updatedPrivacyList");
       
   129 		}
   112 	}
   130 	}
   113 
   131 
   114 	@Override
   132 	@Override
   115 	public void setPrivacyList(String listName, List<PrivacyItem> listItem) {
   133 	public List<String> getBlockedUsersByList(String listName) throws RemoteException {
   116 	    Log.d(TAG, "setPrivacyList");
   134 		// TODO Auto-generated method stub
       
   135 		return null;
   117 	}
   136 	}
   118 
   137 
   119 	@Override
   138 	/**
   120 	public void updatedPrivacyList(String listName) {
   139 	 * adaptee getter.
   121 	    Log.d(TAG, "updatedPrivacyList");
   140 	 * 
       
   141 	 * @return the current PrivacyListManager instance
       
   142 	 */
       
   143 	public PrivacyListManager getManager() {
       
   144 		return mAdaptee;
   122 	}
   145 	}
   123     }
       
   124 
       
   125     @Override
       
   126     public List<String> getBlockedUsersByList(String listName) throws RemoteException {
       
   127 	// TODO Auto-generated method stub
       
   128 	return null;
       
   129     }
       
   130 
       
   131     /**
       
   132      * adaptee getter.
       
   133      * @return the current PrivacyListManager instance
       
   134      */
       
   135     public PrivacyListManager getManager() {
       
   136 	return mAdaptee;
       
   137     }
       
   138 }
   146 }