Wear OS: Glance framework allows developing tiles with Compose


With Glance, Google is developing a framework for creating remote surfaces for Android apps. With the now released first alpha release, Glance, which translates to both look and shine, gets a connection to tiles on Wear OS. It complements the Tiles library for the smartwatch operating system. The basis for the UIs created with Glance is Jetpack Compose.

The tiles introduced for Wear OS in 2019 are used to display a view with the central information of an app such as weather data, pedometer, song titles or calendar reminders. With the Tiles Library, released in March 2021, developers can create their own tiles for their apps. The library provides a Java API that can be used with both Java and Kotlin.

The Glance framework relies on Jetpack Compose to create tiles. The toolkit, which has been available in a stable variant since July 2021, offers a declarative approach to creating interfaces. Compose offers a reactive programming model and uses Kotlin as the programming language. So-called composable functions define the individual control elements – or parts of them. Over @Composable Decorated functions can be nested in each other to ultimately create the interface.

A simple “Hello World” tile with Glance looks like this:

class HelloTileService : GlanceTileService() 
   @Composable
   override fun Content() 
       Text(text = "Hello World")
   

Although Glance is built on top of Compose, it does not offer interoperability with other components of the Jetpack Compose UI. Direct interaction with other Compose applications on Wear OS is therefore not possible.

Glance not only serves to create tiles, but also has an interface to app widgets. The respective Maven dependencies can be found in the description of the framework.

Glance’s architecture can incorporate both Wear Tiles and app widgets.

(Image: Google)

More details can be found in the Android developer blog. Glance is currently in alpha status. It requires at least SDK version 26, which is Android 8. In addition to the freshly released, current Android Studio, the Compose Runtime is required. See the Jetpack Compose documentation for installation details. Sample applications in the AndroidX repository are intended to make it easier to get started developing with Glance.


(rm)

To home page



Source link -64