public class ThemePreviewTileRenderer(context: Context, private val thisTheme: Colors) : SingleTileLayoutRenderer<Unit, Unit>(context) { override fun createTheme(): Colors = thisTheme override fun renderTile( state: Unit, deviceParameters: DeviceParameters ): LayoutElement { return Box.Builder() .setWidth(ExpandedDimensionProp.Builder().build()) .setHeight(ExpandedDimensionProp.Builder().build()) .setHorizontalAlignment(HORIZONTAL_ALIGN_CENTER) .setVerticalAlignment(VERTICAL_ALIGN_CENTER) .addContent( Column.Builder() .addContent(title()) .addContent(primaryIconButton()) .addContent(primaryChip(deviceParameters)) .addContent(secondaryCompactChip(deviceParameters)) .addContent(secondaryIconButton()) .build() ) .build() } internal fun title() = Text.Builder(context, "Title") .setTypography(Typography.TYPOGRAPHY_CAPTION1) .setColor(ColorBuilders.argb(theme.onSurface)) .build() internal fun primaryChip( deviceParameters: DeviceParameters ) = Chip.Builder(context, NoOpClickable, deviceParameters) .setPrimaryLabelContent("Primary Chip") .setIconContent(Icon) .setChipColors(ChipColors.primaryChipColors(theme)) .build() internal fun secondaryCompactChip( deviceParameters: DeviceParameters ) = CompactChip.Builder(context, "Secondary Chip", NoOpClickable, deviceParameters) .setChipColors(ChipColors.secondaryChipColors(theme)) .build() internal fun primaryIconButton() = Button.Builder(context, NoOpClickable) .setIconContent(Icon) .setButtonColors(ButtonColors.primaryButtonColors(theme)) .build() internal fun secondaryIconButton() = Button.Builder(context, NoOpClickable) .setIconContent(Icon) .setButtonColors(ButtonColors.secondaryButtonColors(theme)) .build() override fun ResourceBuilders.Resources.Builder.produceRequestedResources( resourceResults: Unit, deviceParameters: DeviceParameters, resourceIds: MutableList<String> ) { addIdToImageMapping(Icon, drawableResToImageResource(R.drawable.ic_nordic)) } private companion object { private const val Icon = "icon" } }
Tile that renders components with typical layouts and a theme colour.