Google releases Jetpack Glance Alpha

According to Google Developers, Android 12 has improved a feature that many Android users regard as key-App Widgets. The improved Widgets are more practical, beautiful, and easier to be discovered by users ( 84% of users use at least one Widget). Now, we have released the first Alpha version of Jetpack Glance to make the building process of Widgets easier. This version is a new framework built on the Jetpack Compose runtime (Runtime), designed to achieve faster and easier Build App Widgets for the main screen or other interfaces.

Android 12 Widgets improvements: Click here

App Widgets: Click here

Jetpack Glance: Click here

Jetpack Compose runtime (Runtime): Click here

You are welcome to start experimenting and share feedback: Click here

Glance provides a new declarative Kotlin API, which is similar to the API you use in Jetpack Compose, which can help you build more beautiful and adaptive App Widgets with less code: Click here

Glance "Hello World" Widgets example

class GreetingsWidget ( private  val name : String ): GlanceAppWidget () { @Composable override  fun  Content () {

working principle

Glance provides a set of basic components that can be combined to help you create a "clear" experience. Now, we will provide more App Widgets. Glance uses Jetpack Compose runtime (Runtime) to convert composable items into actual RemoteViews and display them in App Widgets.

Combinable items: Click here

RemoteViews: Click here

This means that Glance needs to enable Compose and relies on the runtime, graphics and unit interface Compose layers, but it does not have direct interoperability with other existing Jetpack Compose interface elements. However, you can share the state or any other logic in the app to create a clear interface.

Enable Compose: Click here
Compose layer: Click here

Alpha-version introduction

This initial version introduces the main API, which not only enables interoperability with existing RemoteViews, but also helps you build App Widgets. The following is an overview of the content provided by the development library. Declare your App Widgets through GlanceAppWidget and GlanceAppWidgetReceiver.

GlanceAppWidget: Click here
GlanceAppWidgetReceiver: Click here

Combine your interface with the initial set of combinable items in Glance: Box, Row, Column, Text, Button, LazyColumn, Image, Spacer.

Box, Row, Column, Spacer: Click here 
Button: Click here
LazyColumn: Click here
Image: Click here
Use the GlanceModifier method to apply modifiers to combinable items: Click here
Use predefined Actions to handle user interactions: Click here
actionStartActivity: Click here
actionRunCallback: Click here
actionStartService: Click here
actionStartBroadcastReceiver: Click here
Provide parameters for Action through ActionParameters: Click here

Handle different Widgets layouts by defining SizeMode.Single, SizeMode.Exact or SizeMode.Responsive.

SizeMode.Single: Click here
SizeMode.Exact: Click here
SizeMode.Responsive: Click here
Different Widgets layout: Click here

Provide GlanceStateDefinition to preserve GlanceAppWidget state.

GlanceStateDefinition: Click here

GlanceAppWidget: Click here

Provide local combinations, such as LocalContext, LocalState, LocalGlanceId, LocalSize: Click here

Interoperate with your existing RemoteViews through the composable items of AndroidRemoteViews.

AndroidRemoteViews: Click here

RemoteViews: Click here

We will also introduce more features, such as default themes, better Android Studio support, and more. Stay tuned for the new version: Click here

Note: Although the minimum SDK version is 21, the minimum compatible version currently supported by the Alpha version is SDK v23.

Build new Android App Widgets in Android 12

Getting started with Glance

You can view the examples on GitHub to get started quickly. You can also use Glance in the latest stable version of Android Studio, but first, you need to follow the steps in the Jetpack Compose document to set it up because Glance relies on the Compose runtime (Runtime).

Example: Click here

Stable version of Android Studio: Click here

Jetpack Compose documentation: Click here

In addition, you can also view advanced examples in the AndroidX code base: Click here

Write your own plugin, you can extend Android Gradle Plugin and customize your build according to your project needs!

ResponsiveAppWidget.kt: Click here

Post a Comment