FileDocCategorySizeDatePackage
ChatGroupManager.javaAPI DocAndroid 1.5 API10195Wed May 06 22:42:46 BST 2009com.android.im.engine

ChatGroupManager

public abstract class ChatGroupManager extends Object
ChatGroupManager manages the creating, removing and the member of ChatGroups.

Fields Summary
protected HashMap
mGroups
protected HashMap
mInvitations
protected CopyOnWriteArrayList
mGroupListeners
protected InvitationListener
mInvitationListener
Constructors Summary
protected ChatGroupManager()

        mGroups = new HashMap<Address, ChatGroup>();
        mInvitations = new HashMap<String, Invitation>();
        mGroupListeners = new CopyOnWriteArrayList<GroupListener>();
    
Methods Summary
public abstract voidacceptInvitationAsync(Invitation invitation)
Accepts an invitation. The user will join the group automatically after accept the invitation.

param
invitation the invitation to accept.

public voidacceptInvitationAsync(java.lang.String inviteId)
Accepts an invitation. The user can only accept or reject the same invitation only once.

param
inviteId the id of the invitation to accept.
see
#acceptInvitationAsync(Invitation)

        Invitation invitation = mInvitations.remove(inviteId);
        if (invitation != null) {
            acceptInvitationAsync(invitation);
        }
    
public voidaddGroupListener(GroupListener listener)
Adds a GroupListener to this manager so that it will be notified when a certain group changes.

param
listener the listener to be notified.

        mGroupListeners.add(listener);
    
protected abstract voidaddGroupMemberAsync(ChatGroup group, Contact contact)
Adds a member to a certain ChatGroup. This method returns immediately and the GroupGroupListeners registered on the group will be notified when the member is added or any error occurs. Only the administrator of the ChatGroup can add member to it.

param
group the ChatGroup to which the member will add.
param
contact the member to add.

public abstract voidcreateChatGroupAsync(java.lang.String name)
Creates a new ChatGroup with specified name. This method returns immediately and the registered GroupListeners will be notified when the group is created or any error occurs. The newly created group is a temporary group and will be automatically deleted when all joined users have left.

param
name the name of the ChatGroup to be created.

public abstract voiddeleteChatGroupAsync(ChatGroup group)
Deletes a certain ChatGroup. This method returns immediately and the registered GroupListeners will be notified when the group is deleted or any error occurs. Only the administrator of the ChatGroup can delete it.

param
group the ChatGroup to be deleted.

public ChatGroupgetChatGroup(Address address)
Gets a ChatGroup by address.

param
address the address of the ChatGroup.
return
a ChatGroup.

        return mGroups.get(address);
    
public abstract voidinviteUserAsync(ChatGroup group, Contact invitee)
Invites a user to join a certain ChatGroup. If success, the invitee will receive an invitation with information of the group. Otherwise, the registered GroupListeners will be notified if any error occurs.

param
group the ChatGroup.
param
invitee the invitee.

public abstract voidjoinChatGroupAsync(Address address)
Joins into a certain ChatGroup. This method returns immediately and the registered GroupListeners will be notified when the user joined into the group or any error occurs.

param
address the address of the ChatGroup.

public abstract voidleaveChatGroupAsync(ChatGroup group)
Leaves a certain ChatGroup.This method returns immediately and the registered GroupListeners will be notified when the the user left the group or any error occurs.

param
group the ChatGroup.

protected voidnotifyGroupChanged(Address groupAddress, java.util.ArrayList joined, java.util.ArrayList left)
Notifies the GroupListeners that a ChatGroup has changed.

param
groupAddress the address of group which has changed.
param
joined a list of users that have joined the group.
param
left a list of users that have left the group.

        ChatGroup group = mGroups.get(groupAddress);
        if (group == null) {
            group = new ChatGroup(groupAddress, groupAddress.getScreenName(), this);
            mGroups.put(groupAddress, group);
        }
        if (joined != null) {
            for (Contact contact : joined) {
                notifyMemberJoined(group, contact);
            }
        }
        if (left != null) {
            for (Contact contact : left) {
                notifyMemberLeft(group, contact);
            }
        }
    
protected synchronized voidnotifyGroupCreated(ChatGroup group)

        mGroups.put(group.getAddress(), group);
        for (GroupListener listener : mGroupListeners) {
            listener.onGroupCreated(group);
        }
    
protected synchronized voidnotifyGroupDeleted(ChatGroup group)

        mGroups.remove(group.getAddress());
        for (GroupListener listener : mGroupListeners) {
            listener.onGroupDeleted(group);
        }
    
protected synchronized voidnotifyGroupError(int errorType, java.lang.String groupName, ImErrorInfo error)

        for (GroupListener listener : mGroupListeners) {
            listener.onGroupError(errorType, groupName, error);
        }
    
protected synchronized voidnotifyGroupInvitation(Invitation invitation)
Notifies the InvitationListener that another user invited the current logged user to join a group chat.

        mInvitations.put(invitation.getInviteID(), invitation);
        if (mInvitationListener != null) {
            mInvitationListener.onGroupInvitation(invitation);
        }
    
protected voidnotifyGroupMemberError(ChatGroup group, ImErrorInfo error)
Notifies that previous operation on this group has failed.

param
error the error information.

        group.notifyGroupMemberError(error);
    
protected synchronized voidnotifyJoinedGroup(ChatGroup group)

        mGroups.put(group.getAddress(), group);
        for (GroupListener listener : mGroupListeners) {
            listener.onJoinedGroup(group);
        }
    
protected synchronized voidnotifyLeftGroup(ChatGroup group)
Notifies the GroupListeners that the user has left a certain group.

param
groupAddress the address of the group.

        mGroups.remove(group.getAddress());
        for (GroupListener listener : mGroupListeners) {
            listener.onLeftGroup(group);
        }
    
protected voidnotifyMemberJoined(ChatGroup group, Contact contact)
Notifies that a contact has joined into this group.

param
group the group into which the contact has joined.
param
contact the contact who has joined into the group.

        group.notifyMemberJoined(contact);
    
protected voidnotifyMemberLeft(ChatGroup group, Contact contact)
Notifies that a contact has left this group.

param
group the group which the contact has left.
param
contact the contact who has left this group.

        group.notifyMemberLeft(contact);
    
public voidrejectInvitationAsync(java.lang.String inviteId)
Rejects an invitation.

param
inviteId the id of the invitation to reject.
see
#rejectInvitationAsync(Invitation)

        Invitation invitation = mInvitations.remove(inviteId);
        if (invitation != null) {
            rejectInvitationAsync(invitation);
        }
    
public abstract voidrejectInvitationAsync(Invitation invitation)
Rejects an invitation.

param
invitation the invitation to reject.

public voidremoveGroupListener(GroupListener listener)
Removes a GroupListener from this manager so that it won't be notified any more.

param
listener the listener to remove.

        mGroupListeners.remove(listener);
    
protected abstract voidremoveGroupMemberAsync(ChatGroup group, Contact contact)
Removes a member from certain ChatGroup. This method returns immediately and the GroupGroupListeners registered on the group will be notified when the member is added or any error occurs. Only the administrator of the ChatGroup can remove its members.

param
group the ChatGroup whose member will be removed.
param
contact the member to be removed.

public synchronized voidsetInvitationListener(InvitationListener listener)
Sets the InvitationListener to the manager so that it will be notified when an invitation from another users received.

param
listener the InvitationListener.

        mInvitationListener = listener;