FileDocCategorySizeDatePackage
ChatSessionManagerAdapter.javaAPI DocAndroid 1.5 API8045Wed May 06 22:42:46 BST 2009com.android.im.service

ChatSessionManagerAdapter

public class ChatSessionManagerAdapter extends IChatSessionManager.Stub

Fields Summary
static final String
TAG
ImConnectionAdapter
mConnection
com.android.im.engine.ChatSessionManager
mSessionManager
com.android.im.engine.ChatGroupManager
mGroupManager
HashMap
mActiveSessions
ChatSessionListenerAdapter
mSessionListenerAdapter
final android.os.RemoteCallbackList
mRemoteListeners
Constructors Summary
public ChatSessionManagerAdapter(ImConnectionAdapter connection)


       
        mConnection = connection;
        ImConnection connAdaptee = connection.getAdaptee();
        mSessionManager = connAdaptee.getChatSessionManager();
        mActiveSessions = new HashMap<String, ChatSessionAdapter>();
        mSessionListenerAdapter = new ChatSessionListenerAdapter();
        mSessionManager.addChatSessionListener(mSessionListenerAdapter);

        if((connAdaptee.getCapability() & ImConnection.CAPABILITY_GROUP_CHAT) != 0) {
            mGroupManager = connAdaptee.getChatGroupManager();
            mGroupManager.addGroupListener(new ChatGroupListenerAdpater());
        }
    
Methods Summary
public voidcloseAllChatSessions()

        synchronized (mActiveSessions) {
            ArrayList<ChatSessionAdapter> sessions =
                new ArrayList<ChatSessionAdapter>(mActiveSessions.values());
            for (ChatSessionAdapter ses : sessions) {
                ses.leave();
            }
        }
    
public voidcloseChatSession(ChatSessionAdapter adapter)

        synchronized (mActiveSessions) {
            ChatSession session = adapter.getAdaptee();
            mSessionManager.closeChatSession(session);
            mActiveSessions.remove(adapter.getAddress());
        }
    
public com.android.im.IChatSessioncreateChatSession(java.lang.String contactAddress)

        ContactListManagerAdapter listManager =
            (ContactListManagerAdapter) mConnection.getContactListManager();
        Contact contact = listManager.getContactByAddress(contactAddress);
        if(contact == null) {
            try {
                contact = listManager.createTemporaryContact(contactAddress);
            } catch (IllegalArgumentException e) {
                mSessionListenerAdapter.notifyChatSessionCreateFailed(contactAddress,
                        new ImErrorInfo(ImErrorInfo.ILLEGAL_CONTACT_ADDRESS,
                                "Invalid contact address:" + contactAddress));
                return null;
            }
        }
        ChatSession session = mSessionManager.createChatSession(contact);
        return getChatSessionAdapter(session);
    
public java.util.ListgetActiveChatSessions()

        synchronized (mActiveSessions) {
            return new ArrayList<ChatSessionAdapter>(mActiveSessions.values());
        }
    
public com.android.im.IChatSessiongetChatSession(java.lang.String address)

        synchronized (mActiveSessions) {
            return mActiveSessions.get(address);
        }
    
ChatSessionAdaptergetChatSessionAdapter(com.android.im.engine.ChatSession session)

        synchronized (mActiveSessions) {
            Address participantAddress = session.getParticipant().getAddress();
            String key = participantAddress.getFullName();
            ChatSessionAdapter adapter = mActiveSessions.get(key);
            if (adapter == null) {
                adapter = new ChatSessionAdapter(session, mConnection);
                mActiveSessions.put(key, adapter);
            }
            return adapter;
        }
    
public intgetChatSessionCount()

        synchronized (mActiveSessions) {
            return mActiveSessions.size();
        }
    
public voidregisterChatSessionListener(com.android.im.IChatSessionListener listener)

        if (listener != null) {
            mRemoteListeners.register(listener);
        }
    
public voidunregisterChatSessionListener(com.android.im.IChatSessionListener listener)

        if (listener != null) {
            mRemoteListeners.unregister(listener);
        }
    
public voidupdateChatSession(java.lang.String oldAddress, ChatSessionAdapter adapter)

        synchronized (mActiveSessions) {
            mActiveSessions.remove(oldAddress);
            mActiveSessions.put(adapter.getAddress(), adapter);
        }