BBM Enterprise SDK is now BlackBerry Spark Communications Platform. Learn more, and download it for free at BlackBerry.com/Spark.
The BlackBerry Spark Communications Platform makes it easy to integrate a messaging experience into your application. Messaging within Spark allows users to share text, files, pictures, or custom data defined by you. Let’s take a look at how the SimpleChat sample displays a conversation style message list.
Displaying a List of Chat Messages
Spark comes with a collection of utility classes (provided as source code for your convenience) that help you accelerate your development.
The ChatMessageList is one of these utilities. It provides an indexed list of chat messages that are lazily loaded, so that you don’t have to worry about your message history’s performance as the chat grows with thousands of messages.
Using the ChatMessageList coupled with Android’s RecyclerView framework to display the messages within a chat, you can achieve smooth and fluid scrolling in your message list, with older messages lazily loading as you scroll back to view them.
To start, instantiate a ChatMessageList with the id of the chat whose messages you want to display, and an IncrementalListObserver to notify your RecyclerView.Adapter whenever a message is added, removed, or changed.
The IncrementalListObserver is added to your ChatMessageList as an observer.
Call start() and stop() on the ChatMessageList to start/stop listening to changes on your messages. This will cause your adapter to only update when the chat is displayed to the user.
Creating Chat Message Views
In this example, we display simple text messages, but Spark also supports files, pictures, contacts, calendar, location, voice notes, or any custom data types you define.
Your RecyclerView.Adapter will create and update the views for the chat messages. Simply update your message view’s text field with the ChatMessage.content. You can also left or right align your outgoing and incoming messages by creating different view types based on the Incoming flag on the ChatMessage object.
Adding a messaging experience to your application is made simple with Spark. You can download this example and follow a step by step walkthrough by visiting the BlackBerry Spark Communications Platform developer portal and downloading Spark today.