GlanceWearWidget

abstract class GlanceWearWidget


Object that handles providing the contents of a Wear Widget.

The widget UI is defined by an instance of WearWidgetData such as WearWidgetDocument, provided in the implementation of provideWidgetData.

An implementation of this class can be associated with a GlanceWearWidgetService for receiving content requests and events from the Host.

Summary

Public constructors

Public functions

open suspend Unit
@MainThread
onAdded(context: Context, widgetHandle: ActiveWearWidgetHandle)

Called when a widget provider linked to this widget class is added to the host.

open suspend Unit

Called when a widget provider linked to this widget class is removed from the host.

abstract suspend WearWidgetData

Override this method to provide data for this Widget.

Unit
triggerUpdate(context: Context, provider: ComponentName)

Trigger a content update for all widgets associated with the provider service component.

Public constructors

GlanceWearWidget

Added in 1.0.0-alpha01
GlanceWearWidget()

Public functions

onAdded

Added in 1.0.0-alpha01
@MainThread
open suspend fun onAdded(context: Context, widgetHandle: ActiveWearWidgetHandle): Unit

Called when a widget provider linked to this widget class is added to the host.

This occurs when a widget is added to the carousel.

This method is called from the main thread.

Parameters
context: Context

the context from which this method is called

widgetHandle: ActiveWearWidgetHandle

the handle of the active widget.

onRemoved

Added in 1.0.0-alpha01
@MainThread
open suspend fun onRemoved(context: Context, widgetHandle: ActiveWearWidgetHandle): Unit

Called when a widget provider linked to this widget class is removed from the host.

This occurs when a widget is removed from the carousel.

This method is called from the main thread.

Parameters
context: Context

the context from which this method is called

widgetHandle: ActiveWearWidgetHandle

the handle of the widget.

provideWidgetData

@MainThread
abstract suspend fun provideWidgetData(context: Context, params: WearWidgetParams): WearWidgetData

Override this method to provide data for this Widget.

This method is called from the main thread.

Parameters
context: Context

the context from which this method is called

params: WearWidgetParams

the parameters that describe the widget for which the data is being provided.

triggerUpdate

Added in 1.0.0-alpha01
fun triggerUpdate(context: Context, provider: ComponentName): Unit

Trigger a content update for all widgets associated with the provider service component.

Parameters
context: Context

the context from which this method is called.

provider: ComponentName

the component name of the widget provider service to request an update for.

TODO: Add push update flow for newer SDK version. TODO: Provide a default mechanism for storing instanceId