Event Listener

The Android SDK provides interfaces to listen to various events on the client app. Through these interfaces, TapTalk.io notifies the client app of events that happen on your app. You will need to register the listener objects to receive event callbacks from TapTalk.io.

Event Listener

Description

Listens to general event changes in the application

Listens to UI-related events in Room List View when UI implementation type is used

Listens to UI-related events in Chat Room View when UI implementation type is used

Listens to UI-related events in Chat Profile View when UI implementation type is used

Listens to UI-related events in My Account View when UI implementation type is used

Listens to custom keyboard-related events when UI implementation type is used

Listens to events when a new/updated message is received by the application

Listens to changes to chat room's state in the room list

Listens to room status events such as typing events and online status

Listens to contact related events such as block or unblock contact

TapListener

General events such as notifications will be notified through TapListener. A TapListener instance is required when initializing TapTalk.

We strongly suggest to override onTapTalkRefreshTokenExpired to handle authentication when the user's session has expired.

TapListener tapListener = new TapListener() {
    @Override
    public void onInitializationCompleted(String instanceKey) {
        // Initialization process has finished
    }
    
    @Override
    public void onTapTalkRefreshTokenExpired() {
        // Authentication is needed
    }

    @Override
    public void onTapTalkUnreadChatRoomBadgeCountUpdated(int unreadCount) {
        // Returns number of unread messages from the application
    }

    @Override
    public void onNotificationReceived(TAPMessageModel message) {
        // A new message from TapTalk.io is received
    }

    @Override
    public void onUserLogout() {
        // User has finished logging out from TapUI or TapTalk.logoutAndClearAllTapTalkData() process has completed
    }
  
    @Override
    public void onTaskRootChatRoomClosed(Activity activity) {
        // A chat room activity was closed by user when no other activity in the application is present
        // You may start another activity to keep the app open, otherwise the app will stay closed
    }
};

TapTalk.init(
  CONTEXT, 
  APP_KEY_ID, 
  APP_KEY_SECRET,            
  APP_ICON, 
  APP_NAME, 
  APP_BASE_URL,            
  IMPLEMENTATION_TYPE, 
  tapListener);

TapListener listens to changes in the following methods:

Method Name

Invoked When

onInitializationCompleted()

TapTalk instance has finished initialization process.

onTapTalkRefreshTokenExpired()

User's refresh token has expired. An authentication with a new auth ticket is required.

onTapTalkUnreadChatRoomBadgeCountUpdated()

The number of unread messages in the application is updated. Returns the number of unread messages from the application.

onNotificationReceived()

User receives new message from TapTalk.io through notification. Returns the newly received message.

onUserLogout()

User has finished logging out from TapUI or TapTalk.logoutAndClearAllTapTalkData() process has completed

onTaskRootChatRoomClosed()

A chat room activity was closed by user when no other activity in the application is present (application will close).

TapUIRoomListListener

TapUIRoomListListener listens to UI-related events in Room List View when UI implementation type is used. You can register a TapUIRoomListListener instance in your application through the TapUI class as follows:

TapUI.getInstance().addRoomListListener(new TapUIRoomListListener() {
    @Override
    public void onSearchChatBarTapped(Activity activity, TapUIMainRoomListFragment mainRoomListFragment) {
        // Calling super will open search chat page by default
        super.onSearchChatBarTapped(activity, mainRoomListFragment);
    }
    
    @Override
    public void onCloseRoomListTapped(Activity activity) {
        // Calling super will close TapTalk's room list activity by default
        super.onCloseRoomListTapped(activity);
    }
    
    @Override
    public void onTapTalkAccountButtonTapped(Activity activity) {
        // Calling super will open TapTalk user account page by default
        super.onTapTalkAccountButtonTapped(activity);
    }
    
    @Override
    public void onNewChatButtonTapped(Activity activity) {
        // Calling super will open TapTalk start new chat page by default
        super.onNewChatButtonTapped(activity);
    }
});

Method Name

Invoked When

onSearchBarTapped()

Search bar in room list is tapped by active user. Returns the room list activity instance and TapUIMainRoomListFragment instance.

onCloseRoomListTapped()

TapTalk's room list activity is closed by active user. Returns the room list activity instance.

onTapTalkAccountButtonTapped()

My account button in top right room list view is tapped by active user. Returns the room list activity instance.

onNewChatButtonTapped()

Floating New Chat button on the bottom right of the room list view is tapped by active user. Returns the room list activity instance.

TapUIChatRoomListener

TapUIChatRoomListener listens to UI-related events in Chat Room View when UI implementation type is used.

Your are also able to customize existing long press menus through this listener.

You can register a TapUIChatRoomListener instance in your application through the TapUI class as follows:

TapUI.getInstance().addChatRoomListener(new TapUIChatRoomListener() {
    @Override
    public void onTapTalkChatRoomOpened(Activity activity, TAPRoomModel room, @Nullable TAPUserModel otherUser) {
        // Returns activity instance and opened room model
    }

    @Override
    public void onTapTalkChatRoomClosed(Activity activity, TAPRoomModel room, @Nullable TAPUserModel otherUser) {
        // Returns activity instance and closed room model
    }
    @Override
    public void onTapTalkActiveUserSendMessage(Activity activity, TAPMessageModel messageModel, TAPRoomModel room) {
        // Returns activity instance, temporary message model to be sent, and the room where the message is being sent
    }
    
    @Override
    public void onTapTalkUserProfileButtonTapped(Activity activity, TAPRoomModel room, TAPUserModel user) {
        // Using super will open TapTalk user profile by default
        super.onTapTalkUserProfileButtonTapped(activity, room, user);
    }
  
    @Override
    public void onTapTalkGroupChatProfileButtonTapped(Activity activity, TAPRoomModel room) {
        // Using super will open TapTalk group chat profile by default
        super.onTapTalkGroupChatProfileButtonTapped(activity, room);
    }
  
    @Override
    public void onTapTalkGroupMemberAvatarTapped(Activity activity, TAPRoomModel room, TAPUserModel user) {
        // Using super will open TapTalk user profile by default
        super.onTapTalkGroupMemberAvatarTapped(activity, room, user);
    }

    @Override
    public void onTapTalkUserMentionTapped(Activity activity, TAPMessageModel messageModel, TAPUserModel user, boolean isRoomParticipant) {
        // Using super will open TapTalk user profile by default 
        super.onTapTalkUserMentionTapped(activity, messageModel, user, isRoomParticipant);
    }

    @Override
    public void onTapTalkMessageQuoteTapped(Activity activity, TAPMessageModel message, HashMap<String, Object> userInfo) {
        // Returns activity instance, tapped message, and userInfo
    }
    
    @Override
    public List<TapLongPressMenuItem> setMessageLongPressMenuItems(Context context, TAPMessageModel messageModel) {
        // Return your customized list of TapLongPressMenuItem here if you wish to change the message's long press menu options
        return super.setMessageLongPressMenuItems(context, messageModel);
    }

    @Override
    public List<TapLongPressMenuItem> setScheduledMessageLongPressMenuItems(Context context, TAPMessageModel messageModel) {
        // Return your customized list of TapLongPressMenuItem here if you wish to change the scheduled message's long press menu options
        return super.setScheduledMessageLongPressMenuItems(context, messageModel);
    }

    @Override
    public List<TapLongPressMenuItem> setLinkLongPressMenuItems(Context context, @Nullable TAPMessageModel messageModel, String url) {
        // Return your customized list of TapLongPressMenuItem here if you wish to change the url's long press menu options
        return super.setLinkLongPressMenuItems(context, messageModel, url);
    }

    @Override
    public List<TapLongPressMenuItem> setEmailLongPressMenuItems(Context context, @Nullable TAPMessageModel messageModel, String emailAddress) {
        // Return your customized list of TapLongPressMenuItem here if you wish to change the email address's long press menu options
        return super.setEmailLongPressMenuItems(context, messageModel, emailAddress);
    }

    @Override
    public List<TapLongPressMenuItem> setPhoneLongPressMenuItems(Context context, @Nullable TAPMessageModel messageModel, String phoneNumber) {
        // Return your customized list of TapLongPressMenuItem here if you wish to change the phone number's long press menu options
        return super.setPhoneLongPressMenuItems(context, messageModel, phoneNumber);
    }

    @Override
    public List<TapLongPressMenuItem> setMentionLongPressMenuItems(Context context, @Nullable TAPMessageModel messageModel, String mentionSpan) {
        // Return your customized list of TapLongPressMenuItem here if you wish to change the mention's long press menu options
        return super.setMentionLongPressMenuItems(context, messageModel, mentionSpan);
    }

    @Override
    public void onLongPressMenuItemSelected(Activity activity, TapLongPressMenuItem longPressMenuItem, TAPMessageModel messageModel) {
        // A long press menu item was selected by user
        // You may add your own response and delete the super below
        super.onLongPressMenuItemSelected(activity, longPressMenuItem, messageModel);
    }
});

Method Name

Invoked When

onTapTalkChatRoomOpened()

A chat room is opened. Returns the opened activity instance and room model.

onTapTalkChatRoomClosed()

A chat room is closed. Returns the closed activity instance and room model.

onTapTalkActiveUserSendMessage()

Active user sends any message to a chat room. Message may not yet be delivered to the room when this happens. Returns the activity instance, message to be sent, and the destination room. Returned message is temporary and the values will be updated through socket once the message is delivered.

onTapTalkUserProfileButtonTapped()

Profile button in a personal chat room is tapped by active user. Returns the activity instance, room, and recipient user.

onTapTalkGroupChatProfileButtonTapped()

Profile button in a group chat room is tapped by active user. Returns the activity instance and room.

onTapTalkGroupMemberAvatarTapped()

A group member's profile picture on a message bubble in group chat room is tapped by active user. Returns the activity instance, room, and recipient user.

onTapTalkUserMentionTapped()

A user mention span in a chat bubble is tapped by active user. Returns activity instance, message model, mentioned user model, and isRoomParticipant

onTapTalkMessageQuoteTapped()

A quote inside a message bubble in a chat room is tapped by active user. Returns activity instance, tapped message, and userInfo. UserInfo is a HashMap object embedded inside a message containing data specified by client, and is generally null when not specified.

setMessageLongPressMenuItems()

A message bubble in chat room is long pressed by user. TapTalk.io will request custom long press items from the client app to be displayed. Returns context and the long pressed message.

setScheduledMessageLongPressMenuItems()

A message bubble in scheduled messages chat room is long pressed by user. TapTalk.io will request custom long press items from the client app to be displayed. Returns context and the long pressed message.

setLinkLongPressMenuItems()

A URL inside a message bubble is long pressed by user. TapTalk.io will request custom long press items from the client app to be displayed. Returns context, the long pressed message, and the URL.

setEmailLongPressMenuItems()

An email address inside a message bubble is long pressed by user. TapTalk.io will request custom long press items from the client app to be displayed. Returns context, the long pressed message, and the email address.

setPhoneLongPressMenuItems()

A phone number inside a message bubble is long pressed by user. TapTalk.io will request custom long press items from the client app to be displayed. Returns context, the long pressed message, and the phone number.

setMentionLongPressMenuItems()

A mention span inside a message bubble is long pressed by user. TapTalk.io will request custom long press items from the client app to be displayed. Returns context, the long pressed message, and the mention span.

onLongPressMenuItemSelected()

A long press menu is selected by the active user. Returns the current activity, long pressed menu item, and the message model.

TapUIChatProfileListener

TapUIChatProfileListener listens to UI-related events in Chat Profile View when UI implementation type is used. You can register a TapUIChatProfileListener instance in your application through the TapUI class as follows:

TapUI.getInstance().addChatProfileListener(new TapUIChatProfileListener() {
    @Override
    public void onReportUserButtonTapped(Activity activity, TAPRoomModel room, TAPUserModel reportedUser) {
        // Returns activity instance, room model, and user model
    }
    
    @Override
    public void onReportGroupButtonTapped(Activity activity, TAPRoomModel room) {
        // Returns activity instance and room model
    }

    @Override
    public void onGroupInCommonItemTapped(Activity activity, TAPRoomModel room) {
        // Returns activity instance and room model
    }
});

Method Name

Invoked When

onReportUserButtonTapped()

Active user taps the Report User button in chat profile view. Returns activity instance, room model, and the reported user model.

onReportGroupButtonTapped()

Active user taps the Report Group button in chat profile view. Returns activity instance and room model.

onGroupInCommonItemTapped()

Active user taps an item in Groups in Common list. Returns activity instance and room model.

TapUIMyAccountListener

TapUIMyAccountListener listens to UI-related events in My Account View when UI implementation type is used. You can register a TapUIMyAccountListener instance in your application through the TapUI class as follows:

TapUI.getInstance().addMyAccountListener(new TapUIMyAccountListener() {
    @Override
    public void onDeleteButtonInMyAccountPageTapped(@NonNull Activity activity) {
        // Returns My Account activity instance
    }
});

Method Name

Invoked When

onDeleteButtonInMyAccountPageTapped()

Active user taps the Delete Account button in My Account view. Returns the currently active My Account activity instance.

TapCustomKeyboardListener

TapCustomKeyboardListener bridges the custom keyboard-related events between TapTalk.io and the client app when UI implementation type is used. TapTalk.io will request custom keyboard items from the client app through this listener when a chat room is opened by the user. TapCustomKeyboardListener can be implemented using the TapUI class.

TapUI.getInstance().addCustomKeyboardListener(new TapCustomKeyboardListener() {
    @Override
    public List<TAPCustomKeyboardItemModel> setCustomKeyboardItems(TAPRoomModel room, TAPUserModel activeUser, @Nullable TAPUserModel recipientUser) {
        // Return items here if you wish to use custom keyboard in chat room
        return null;
    }

    @Override
    public void onCustomKeyboardItemTapped(Activity activity, TAPCustomKeyboardItemModel customKeyboardItem, TAPRoomModel room, TAPUserModel activeUser, @Nullable TAPUserModel recipientUser) {
        // Do an action when user taps a custom keyboard item
    }
});

To use custom keyboard in the chat room, return a list of TAPCustomKeyboardItemModel on the setCustomKeyboardItems() method in this listener. See the example below:JavaKotlin

TapCustomKeyboardManager.getInstance().addCustomKeyboardListener(new TapCustomKeyboardListener() {
    @Override
    public List<TAPCustomKeyboardItemModel> setCustomKeyboardItems(TAPRoomModel room, TAPUserModel activeUser, @Nullable TAPUserModel recipientUser) {
        List<TAPCustomKeyboardItemModel> customKeyboardItems = new ArrayList<>();
        TAPCustomKeyboardItemModel customKeyboardItem1 = new TAPCustomKeyboardItemModel(
                "customKeyboardItem1",
                getDrawable(R.drawable.keyboard_icon_1),
                "Hello, " + room.getRoomName()
        );
        TAPCustomKeyboardItemModel customKeyboardItem2 = new TAPCustomKeyboardItemModel(
                "customKeyboardItem2",
                "https://www.yoururl.com/image2.png",
                "Hello, my name is " + activeUser.getName()
        );
        customKeyboardItems.add(customKeyboardItem1);
        customKeyboardItems.add(customKeyboardItem2);
        return customKeyboardItems;
    }

    @Override
    public void onCustomKeyboardItemTapped(Activity activity, TAPCustomKeyboardItemModel customKeyboardItem, TAPRoomModel room, TAPUserModel activeUser, @Nullable TAPUserModel recipientUser) {
        if (customKeyboardItem.getItemID().equals("customKeyboardItem1")) {
            // Custom keyboard item 1 was tapped by user
        } else if (customKeyboardItem.getItemID().equals("customKeyboardItem2")) {
            // Custom keyboard item 2 was tapped by user
        }
    }
});

Method Name

Invoked When

setCustomKeyboardItems()

Chat room is opened. TapTalk.io will request custom keyboard items from the client app to be displayed in the chat room. Returns room, active user, and the recipient user (only for personal chat room)

onCustomKeyboardItemTapped()

A custom keyboard item in a chat room is tapped by the user. Returns the activity instance, custom keyboard item, room, active user, and recipient user (only for personal chat room)

TapCoreMessageListener

TapCoreMessageListener listens to message-related events, such as receiving new or updated message. TapCoreMessageListener can be registered through the TapCoreMessageManager class.JavaKotlin

TapCoreMessageManager.getInstance().addMessageListener(new TapCoreMessageListener() {
    @Override
    public void onReceiveNewMessage(TAPMessageModel message) {

    }

    @Override
    public void onReceiveUpdatedMessage(TAPMessageModel message) {

    }
    
    @Override
    public void onMessageDeleted(TAPMessageModel message) {
    
    }

    @Override
    public void onRequestMessageFileUpload(TAPMessageModel message, Uri fileUri) {

    }
});

Method Name

Invoked When

onReceiveNewMessage()

A new message is received. Returns the newly received message.

onReceiveUpdatedMessage()

An updated message is received. Returns the updated message.

onMessageDeleted()

A message is deleted. Returns the deleted message.

onRequestMessageFileUpload()

Active user sends a message with file, such as image, video, or document. Returns the message to be sent and the uri of the file to be uploaded by the client.

Note: the callback onRequestMessageFileUpload() will only be invoked when the user calls setUploadMessageFileToExternalServerEnabled(true) in TapCoreMessageManager. Enabling this will prevent the SDK from uploading message files, which are image, video, or document, to TapTalk servers, means the message will not be sent until the client returns the uploaded file's URL to the SDK through the onFileUploadCompleted method in TapCoreMessageManager.

TapCoreRoomListListener

Changes to a chat room's state, such as pin and mute events are notified through TapCoreRoomListListener. An instance of TapCoreRoomListListener can be registered from the TapCoreRoomListManager class.

TapCoreRoomListManager.getInstance().addCoreRoomListListener(new TapCoreRoomListListener() {
    @Override
    public void onChatRoomMuted(@NonNull String roomID, long expiryTime) {
        
    }

    @Override
    public void onChatRoomUnmuted(@NonNull String roomID) {
        
    }

    @Override
    public void onChatRoomPinned(@NonNull String roomID) {
        
    }

    @Override
    public void onChatRoomUnpinned(@NonNull String roomID) {
        
    }
    
    @Override
    public void onChatRoomDeleted(@NonNull String roomID) {

    }
});
Method NameInvoked When

onChatRoomMuted()

The active user muted a chat room. Returns the room ID and mute expiry time of the muted room.

onChatRoomUnmuted()

The active user unmuted a chat room. Returns the room ID of the unmuted room.

onChatRoomPinned()

The active user pinned a chat room. Returns the room ID of the pinned room.

onChatRoomUnpinned()

The active user unpinned a chat room. Returns the room ID of the unpinned room.

onChatRoomDeleted()

The active user deleted a chat room. Returns the room ID of the deleted room.

TapCoreChatRoomListener

Room status events such as typing events and online status are notified through TapCoreChatRoomListener. An instance of TapCoreChatRoomListener can be registered from the TapCoreContactManager class.

TapCoreChatRoomManager.getInstance().addContactListener(new TapCoreChatRoomListener() {
    @Override
    public void onReceiveStartTyping(String roomID, TAPUserModel user) {
    
    }

    @Override
    public void onReceiveStopTyping(String roomID, TAPUserModel user) {
    
    }

    @Override
    public void onReceiveOnlineStatus(TAPUserModel user, Boolean isOnline, Long lastActive) {
    
    }
});

Method Name

Invoked When

onReceiveStartTyping()

Another user starts typing a message in a chat room. Returns the room ID and typing user.

onReceiveStopTyping()

Another user stops typing a message in a chat room. Returns the room ID and typing user.

onReceiveOnlineStatus()

Another user comes online or offline. Returns the updated user, online status, and the updated user's last active time stamp.

TapCoreContactListener

Contact related events such as block/unblock are notified through TapCoreContactListener. An instance of TapCoreContactListener can be registered from the TapCoreContactManager class.

TapCoreContactManager.getInstance().addContactListener(new TapCoreContactListener() {
    @Override
    public void onContactBlocked(TAPUserModel user) {
    
    }

    @Override
    public void onContactUnblocked(TAPUserModel user) {
    
    }
});

Method Name

Invoked When

onContactBlocked()

Active user blocks another user. Returns the blocked user.

onContactUnblocked()

Active user unblocks another user. Returns the unblocked user.

Last updated