AI Agent Component Spec
AI Agent Component Spec
Where It Fits
CometChatCallButtons is a utility component. It renders voice and video call buttons and initiates calls for the bound User or Group. Wire it into a CometChatMessageHeader or place it anywhere a call action is needed.
- Kotlin
- Java
ChatActivity.kt
Quick Start
Add the component to your layout XML:layout_activity.xml
CometChatUIKit.init(), a user logged in, and the cometchat-chat-uikit-android dependency added.
To add programmatically in an Activity:
- Kotlin
- Java
YourActivity.kt
- Kotlin
- Java
YourFragment.kt
You must callsetUser(User)orsetGroup(Group)before the buttons can initiate a call. Without a target, button clicks have no effect.
Actions and Events
Callback Methods
setOnVoiceCallClick
Fires when the voice call button is tapped. Replaces the default behavior of initiating an audio call.
- Kotlin
- Java
YourActivity.kt
What this does: Replaces the default voice call initiation. When a user taps the voice call button, your custom lambda executes instead of the built-in call flow. TheOnClickinterface providesvoid onClick(User user, Group group).
setOnVideoCallClick
Fires when the video call button is tapped. Replaces the default behavior of initiating a video call.
- Kotlin
- Java
YourActivity.kt
- Verify: After setting a callback, tap the corresponding button and confirm your custom logic executes instead of the default call initiation.
Global UI Events (CometChatCallEvents)
CometChatCallEvents emits events subscribable from anywhere in the application. Add a listener and remove it when no longer needed.
| Event | Fires when | Payload |
|---|---|---|
ccOutgoingCall | An outgoing call is initiated | Call |
ccCallAccepted | A call is accepted by the recipient | Call |
ccCallRejected | A call is rejected by the recipient | Call |
ccCallEnded | A call is ended | Call |
- Kotlin
- Java
Add Listener
SDK Events
The component uses an internalCallButtonsViewModel that observes call initiation and direct call events. No manual SDK listener attachment is needed — the component handles call lifecycle internally.
Functionality
Small functional customizations such as toggling visibility of UI elements and configuring button spacing.| Method | Description | Code |
|---|---|---|
setVoiceCallButtonVisibility | Toggles visibility of the voice call button | .setVoiceCallButtonVisibility(View.GONE); |
setVideoCallButtonVisibility | Toggles visibility of the video call button | .setVideoCallButtonVisibility(View.GONE); |
setButtonTextVisibility | Toggles visibility of text labels on both buttons | .setButtonTextVisibility(View.GONE); |
setButtonIconVisibility | Toggles visibility of icons on both buttons | .setButtonIconVisibility(View.GONE); |
setMarginBetweenButtons | Sets the spacing between voice and video buttons | .setMarginBetweenButtons(24); |
- Verify: After calling a visibility method, confirm the corresponding UI element is shown or hidden.
Custom View Slots
CometChatCallButtons exposes direct access to its two internal CometChatButton instances. Use these to customize icons, text, colors, and other properties on each button individually.
| Slot | Method | Returns |
|---|---|---|
| Voice call button | getVoiceCallButton() | CometChatButton |
| Video call button | getVideoCallButton() | CometChatButton |
- Kotlin
- Java
- Verify: After accessing a button via
getVoiceCallButton()orgetVideoCallButton(), confirm your customizations render correctly on the corresponding button.
Common Patterns
Video-only buttons
- Kotlin
- Java
Voice-only buttons
- Kotlin
- Java
Custom button text
- Kotlin
- Java
Icon-only buttons
- Kotlin
- Java
Advanced Methods
setUser / setGroup
Binds the component to a specific user or group. Required before calls can be initiated.
- Kotlin
- Java
setOutgoingCallConfiguration
Configures the outgoing call screen that appears after a call is initiated.
- Kotlin
- Java
setCallSettingsBuilder
Provides a callback to customize call settings per call. The callback receives the User, Group, and a Boolean indicating whether the call is audio (true) or video (false), and returns a CometChatCalls.CallSettingsBuilder.
- Kotlin
- Java
getVoiceCallButton / getVideoCallButton
Returns the internal CometChatButton instances for direct customization.
| Method | Returns | Description |
|---|---|---|
getVoiceCallButton() | CometChatButton | The voice call button instance |
getVideoCallButton() | CometChatButton | The video call button instance |
disposeObservers
Removes lifecycle observers manually. Normally handled automatically when the view detaches from the window.
- Kotlin
- Java
Style
The component uses XML theme styles. Define a custom style with parentCometChatCallButtonsStyle in themes.xml, then apply with setStyle().
themes.xml
- Kotlin
- Java
Programmatic Style Properties
In addition to XML theme styles, the component exposes programmatic setters for fine-grained control:| Method | Type | Description |
|---|---|---|
setVoiceCallIcon | Drawable | Icon drawable for the voice call button |
setVideoCallIcon | Drawable | Icon drawable for the video call button |
setVoiceCallIconTint | @ColorInt int | Tint color for the voice call icon |
setVideoCallIconTint | @ColorInt int | Tint color for the video call icon |
setVoiceCallTextColor | @ColorInt int | Text color for the voice call button |
setVideoCallTextColor | @ColorInt int | Text color for the video call button |
setVoiceCallTextAppearance | @StyleRes int | Text appearance for the voice call button |
setVideoCallTextAppearance | @StyleRes int | Text appearance for the video call button |
setVoiceCallBackgroundColor | @ColorInt int | Background color for the voice call button |
setVideoCallBackgroundColor | @ColorInt int | Background color for the video call button |
setVoiceCallCornerRadius | @Dimension int | Corner radius for the voice call button |
setVideoCallCornerRadius | @Dimension int | Corner radius for the video call button |
setVoiceCallIconSize | @Dimension int | Icon size for the voice call button |
setVideoCallIconSize | @Dimension int | Icon size for the video call button |
setVoiceCallStrokeWidth | @Dimension int | Stroke width for the voice call button |
setVideoCallStrokeWidth | @Dimension int | Stroke width for the video call button |
setVoiceCallStrokeColor | @ColorInt int | Stroke color for the voice call button |
setVideoCallStrokeColor | @ColorInt int | Stroke color for the video call button |
setVoiceCallButtonPadding | @Dimension int | Padding for the voice call button |
setVideoCallButtonPadding | @Dimension int | Padding for the video call button |
Customization Matrix
| What to change | Where | Property/API | Example |
|---|---|---|---|
| Override voice call tap behavior | Activity/Fragment | setOnVoiceCallClick | setOnVoiceCallClick((u, g) -> { ... }) |
| Override video call tap behavior | Activity/Fragment | setOnVideoCallClick | setOnVideoCallClick((u, g) -> { ... }) |
| Hide voice call button | Activity/Fragment | setVoiceCallButtonVisibility(int) | setVoiceCallButtonVisibility(View.GONE) |
| Hide video call button | Activity/Fragment | setVideoCallButtonVisibility(int) | setVideoCallButtonVisibility(View.GONE) |
| Hide button text labels | Activity/Fragment | setButtonTextVisibility(int) | setButtonTextVisibility(View.GONE) |
| Hide button icons | Activity/Fragment | setButtonIconVisibility(int) | setButtonIconVisibility(View.GONE) |
| Change button spacing | Activity/Fragment | setMarginBetweenButtons(int) | setMarginBetweenButtons(24) |
| Set custom button text | Activity/Fragment | setVoiceButtonText / setVideoButtonText | setVoiceButtonText("Audio Call") |
| Change voice call icon | Activity/Fragment | setVoiceCallIcon(Drawable) | setVoiceCallIcon(drawable) |
| Change video call icon | Activity/Fragment | setVideoCallIcon(Drawable) | setVideoCallIcon(drawable) |
| Change icon tint colors | Activity/Fragment | setVoiceCallIconTint / setVideoCallIconTint | setVoiceCallIconTint(Color.GREEN) |
| Change text colors | Activity/Fragment | setVoiceCallTextColor / setVideoCallTextColor | setVoiceCallTextColor(Color.BLACK) |
| Change background colors | Activity/Fragment | setVoiceCallBackgroundColor / setVideoCallBackgroundColor | setVoiceCallBackgroundColor(Color.WHITE) |
| Change corner radius | Activity/Fragment | setVoiceCallCornerRadius / setVideoCallCornerRadius | setVoiceCallCornerRadius(16) |
| Change icon size | Activity/Fragment | setVoiceCallIconSize / setVideoCallIconSize | setVoiceCallIconSize(48) |
| Change stroke width | Activity/Fragment | setVoiceCallStrokeWidth / setVideoCallStrokeWidth | setVoiceCallStrokeWidth(2) |
| Change stroke color | Activity/Fragment | setVoiceCallStrokeColor / setVideoCallStrokeColor | setVoiceCallStrokeColor(Color.GRAY) |
| Change button padding | Activity/Fragment | setVoiceCallButtonPadding / setVideoCallButtonPadding | setVoiceCallButtonPadding(12) |
| Apply XML theme style | themes.xml | CometChatCallButtonsStyle | <item name="cometchatCallButtonsVoiceCallIconTint">#4CAF50</item> |
| Apply style programmatically | Activity/Fragment | setStyle(int styleRes) | callButtons.setStyle(R.style.CustomCallButtonsStyle) |
| Configure outgoing call screen | Activity/Fragment | setOutgoingCallConfiguration | setOutgoingCallConfiguration(config) |
| Custom call settings per call | Activity/Fragment | setCallSettingsBuilder | See setCallSettingsBuilder code above |
| Access internal buttons | Activity/Fragment | getVoiceCallButton() / getVideoCallButton() | callButtons.getVoiceCallButton() |
Accessibility
The component renders twoCometChatButton instances inside a MaterialCardView. Each button responds to tap gestures. The voice and video call icons include default content descriptions for screen readers.
For custom icons set via setVoiceCallIcon or setVideoCallIcon, ensure you set android:contentDescription on the drawable or on the button view so TalkBack can announce the action. The default icons handle this automatically.
Button text labels (when visible) provide additional context for assistive technologies. If you hide text with setButtonTextVisibility(View.GONE), consider adding explicit content descriptions to the buttons via getVoiceCallButton().setContentDescription(...).