Creating Tiles for Wear OS

Jun 8 2021 · Kotlin 1.5, Android 8, Android Studio 4.2

Part 1: Creating Tiles for Wear OS

03. Create a Basic Tile

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 02. Set Up the Project Next episode: 04. Add Images to the Tile

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Intro $[==]

Every Tile is backed by a Timeline. A Timeline contains one or more TimelineEntry instances. Each TimelineEntry is backed by a Layout and is available for a specified time interval. The system takes care of rendering different TimelineEntry instances at different time intervals

Demo $[==]

Open WaterService.kt and go to the onTileRequest method. Add a Timeline by adding the following method call to TileBuilders.Tile.builder():

.setTimeline(
  TimelineBuilders.Timeline.builder()
    
  )
)
.addTimelineEntry(
  TimelineBuilders.TimelineEntry.builder().setLayout(
    LayoutElementBuilders.Layout.builder()

    )
  )
)
.setRoot(
  LayoutElementBuilders.Box.builder()
    .setWidth(DimensionBuilders.expand())
    .setHeight(DimensionBuilders.expand())
)
private fun currentGlassText(current: String, deviceParameters: DeviceParametersReaders.DeviceParameters) = 
  LayoutElementBuilders.Text.builder()
    .setText(current)
    .setFontStyle(LayoutElementBuilders.FontStyles.display2(deviceParameters))
    .build()
val deviceParams = requestParams.deviceParameters

val glassCount = waterRepository.getGlassCount()
.addContent(
  currentGlassText(glassCount.toString(), deviceParams)
)