A ScrollableMessage
creates an overlay containing a large block of formatted text that can be scrolled. It contains a body of text, a message timeout, and up to eight soft buttons. To display a scrollable message in your SDL app, you simply send a ScrollableMessage
RPC request.
The message will persist on the screen until the timeout has elapsed or the user dismisses the message by selecting a soft button or cancelling (if the head unit provides cancel UI).
Currently, you can only create a scrollable message view to display on the screen using RPCs.
The ScreenManager
uses soft button ids 0 – 10000. Ensure that if you use custom RPCs—such as this one—that the soft button ids you use are outside of this range (i.e. > 10000).
// Create Message To Display String scrollableMessageText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.Vestibulum mattis ullamcorper velit sed ullamcorper morbi tincidunt ornare. Purus in massa tempor nec feugiat nisl pretium fusce id. Pharetra convallis posuere morbi leo urna molestie at elementum eu. Dictum sit amet justo donec enim diam."; // Create SoftButtons SoftButton softButton1 = new SoftButton(SoftButtonType.SBT_TEXT, 10001); softButton1.setText("Button 1"); SoftButton softButton2 = new SoftButton(SoftButtonType.SBT_TEXT, 10002); softButton2.setText("Button 2"); // Create SoftButton Array List<SoftButton> softButtonList = Arrays.asList(softButton1, softButton2); // Create ScrollableMessage Object ScrollableMessage scrollableMessage = new ScrollableMessage() .setScrollableMessageBody(scrollableMessageText) .setTimeout(50000) .setSoftButtons(softButtonList); // Set cancelId scrollableMessage.setCancelID(cancelId); // Send the scrollable message sdlManager.sendRPC(scrollableMessage);
To listen for OnButtonPress
events for SoftButton
s, we need to add a listener that listens for their Id's:
sdlManager.addOnRPCNotificationListener(FunctionID.ON_BUTTON_PRESS, new OnRPCNotificationListener() { @Override public void onNotified(RPCNotification notification) { OnButtonPress onButtonPress = (OnButtonPress) notification; switch (onButtonPress.getCustomButtonID()){ case 10001: DebugTool.logInfo(TAG, "Button 1 Pressed"); break; case 10002: DebugTool.logInfo(TAG, "Button 2 Pressed"); break; } } });
You can dismiss a displayed scrollable message before the timeout has elapsed. You can dismiss a specific scrollable message, or you can dismiss the scrollable message that is currently displayed.
If connected to older head units that do not support this feature, the cancel request will be ignored, and the scrollable message will persist on the screen until the timeout has elapsed or the user dismisses the message by selecting a button.
// `cancelID` is the ID that you assigned when creating and sending the alert CancelInteraction cancelInteraction = new CancelInteraction(FunctionID.SCROLLABLE_MESSAGE.getId(), cancelID); cancelInteraction.setOnRPCResponseListener(new OnRPCResponseListener() { @Override public void onResponse(int correlationId, RPCResponse response) { if (response.getSuccess()){ DebugTool.logInfo(TAG, "Scrollable message was dismissed successfully"); } } }); sdlManager.sendRPC(cancelInteraction);
CancelInteraction cancelInteraction = new CancelInteraction(FunctionID.SCROLLABLE_MESSAGE.getId()); cancelInteraction.setOnRPCResponseListener(new OnRPCResponseListener() { @Override public void onResponse(int correlationId, RPCResponse response) { if (response.getSuccess()){ DebugTool.logInfo(TAG, "Scrollable message was dismissed successfully"); } } }); sdlManager.sendRPC(cancelInteraction);