This guide covers presenting text and images on the screen as well as creating, showing, and responding to custom buttons you create.
The ScreenManager
is a manager for easily creating text, images and soft buttons for your SDL app. To update the UI, simply give the manager the new UI data and sandwich the update between the manager's beginTransaction()
and commit()
methods.
SDLScreenManager Parameter Name | Description |
---|---|
textField1 | The text displayed in a single-line display, or in the upper display line of a multi-line display |
textField2 | The text displayed on the second display line of a multi-line display |
textField3 | The text displayed on the third display line of a multi-line display |
textField4 | The text displayed on the bottom display line of a multi-line display |
mediaTrackTextField | The text displayed in the in the track field. This field is only valid for media applications |
primaryGraphic | The primary image in a template that supports images |
secondaryGraphic | The second image in a template that supports multiple images |
textAlignment | The text justification for the text fields. The text alignment can be left, center, or right |
softButtonObjects | An array of buttons. Each template supports a different number of soft buttons |
textField1Type | The type of data provided in textField1 |
textField2Type | The type of data provided in textField2 |
textField3Type | The type of data provided in textField3 |
textField4Type | The type of data provided in textField4 |
sdlManager.getScreenManager().beginTransaction(); sdlManager.getScreenManager().setTextField1("Hello, this is MainField1."); sdlManager.getScreenManager().setTextField2("Hello, this is MainField2."); sdlManager.getScreenManager().setTextField3("Hello, this is MainField3."); sdlManager.getScreenManager().setTextField4("Hello, this is MainField4."); sdlManager.getScreenManager().commit(new CompletionListener() { @Override public void onComplete(boolean success) { Log.i(TAG, "ScreenManager update complete: " + success); } });
After you have displayed text and graphics onto the screen, you may want to remove those from being displayed. In order to do so, you only need to set the screen manager property to null
.
sdlManager.getScreenManager().setTextField1(null); sdlManager.getScreenManager().setTextField2(null); sdlManager.getScreenManager().setPrimaryGraphic(null);
To create a soft button using the ScreenManager
, you only need to create a custom name for the button and provide the text for the button's label and/or an image for the button's icon. If your button cycles between different states (e.g. a button used to set the repeat state of a song playlist can have three states: repeat-off, repeat-one, and repeat-all) you can upload all the states on initialization. Soft Buttons can contain images, text or both.
SoftButtonState textState = new SoftButtonState("<#State Name#>", "<#Button Label Text#>", null); SoftButtonObject softButtonObject = new SoftButtonObject("softButtonObject", Collections.singletonList(textState), textState.getName(), new SoftButtonObject.OnEventListener() { @Override public void onPress(SoftButtonObject softButtonObject, OnButtonPress onButtonPress) { } @Override public void onEvent(SoftButtonObject softButtonObject, OnButtonEvent onButtonEvent) { } }); sdlManager.getScreenManager().setSoftButtonObjects(Collections.singletonList(softButtonObject));
To see if soft buttons support images you should check the getGraphicSupported()
method on SdlManager
sSoftButtonCapabilities
using SystemCapabilityManager
.
Object softButtonCapabilities = sdlManager.getSystemCapabilityManager().getCapability(SystemCapabilityType.SOFTBUTTON); List<SoftButtonCapabilities> softButtonCapabilitiesList = SystemCapabilityManager.convertToList(softButtonCapabilities, SoftButtonCapabilities.class); boolean imageSupported = false; if (softButtonCapabilities != null && !softButtonCapabilitiesList.isEmpty() && softButtonCapabilitiesList.get(0).getImageSupported()){ imageSupported = true; } if (imageSupported) { SoftButtonState state = new SoftButtonState("<#State Name#>", null, imageArtwork); SoftButtonObject softButtonObject = new SoftButtonObject("softButtonObject", Collections.singletonList(state), state.getName(), new SoftButtonObject.OnEventListener() { @Override public void onPress(SoftButtonObject softButtonObject, OnButtonPress onButtonPress) { } @Override public void onEvent(SoftButtonObject softButtonObject, OnButtonEvent onButtonEvent) { } }); sdlManager.getScreenManager().setSoftButtonObjects(Collections.singletonList(softButtonObject)); }
SoftButtonState state = new SoftButtonState("<#State Name#>", "<#Button Label Text#>", imageArtwork); SoftButtonObject softButtonObject = new SoftButtonObject("softButtonObject", Collections.singletonList(state), state.getName(), new SoftButtonObject.OnEventListener() { @Override public void onPress(SoftButtonObject softButtonObject, OnButtonPress onButtonPress) { } @Override public void onEvent(SoftButtonObject softButtonObject, OnButtonEvent onButtonEvent) { } }); sdlManager.getScreenManager().setSoftButtonObjects(Collections.singletonList(softButtonObject));
When the soft button state needs to be updated, simply tell the SoftButtonObject
to transition to the next state. If your button states do not cycle in a predictable order, you can also tell the soft button the state to transition to by passing the stateName
of the new soft button state.
SoftButtonState state1 = new SoftButtonState("<#State1 Name#>", "<#Button1 Label Text#>", image1Artwork); SoftButtonState state2 = new SoftButtonState("<#State2 Name#>", "<#Button2 Label Text#>", image2Artwork); SoftButtonObject softButtonObject = new SoftButtonObject("softButtonObject", Arrays.asList(state1, state2), state1.getName(), new SoftButtonObject.OnEventListener() { @Override public void onPress(SoftButtonObject softButtonObject, OnButtonPress onButtonPress) { } @Override public void onEvent(SoftButtonObject softButtonObject, OnButtonEvent onButtonEvent) { } }); sdlManager.getScreenManager().setSoftButtonObjects(Collections.singletonList(softButtonObject)); // Transition to a new state SoftButtonObject retrievedSoftButtonObject = sdlManager.getScreenManager().getSoftButtonObjectByName("softButtonObject"); retrievedSoftButtonObject.transitionToNextState();
To delete soft buttons, simply pass the screen manager a new array of soft buttons. To delete all soft buttons, simply pass the screen manager an empty array.
sdlManager.getScreenManager().setSoftButtonObjects(Collections.EMPTY_LIST);
When connected to a remote system running SDL Core 5.0+, you may be able to use template images. Templated images are tinted by Core so the image is visible regardless of whether your user has set the head unit to day or night mode. For example, if a head unit is in night mode with a dark theme (see Template Coloring in the Integration Basics section for more details on how to customize theme colors), then your templated images will be displayed as white. In the day theme, the image will automatically change to black.
Soft buttons, menu icons, and primary / secondary graphics can all be templated. Images that you wish to template must be PNGs with a transparent background and only one color for the icon. Therefore, templating is only useful for things like icons and not for images that must be rendered in a specific color.
In the screenshots below, the shuffle and repeat icons have been templated. In night mode, the icons are tinted white and in day mode the icons are tinted black.
SdlArtwork image = new SdlArtwork("ArtworkName", FileType.GRAPHIC_PNG, R.drawable.artworkName, true); image.setTemplateImage(true);
Static icons are pre-existing images on the remote system that you may reference and use in your own application. Static icons are fully supported by the screen manager via an SdlArtwork
initializer.
Static icons can be used in primary and secondary graphic fields, soft button image fields, and menu icon fields.
SdlArtwork sdlArtwork = new SdlArtwork(StaticIconName.ALBUM); sdlManager.getScreenManager().setPrimaryGraphic(sdlArtwork);
If you don't want to use the screen manager, you can just send raw Show
RPC requests to Core.