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 the system sends a batch of interaction events.

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-alpha03
GlanceWearWidget()

Public functions

onAdded

Added in 1.0.0-alpha03
@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.

onEvents

@MainThread
open suspend fun onEvents(context: Context, events: List<WearWidgetEvent>): Unit

Called when the system sends a batch of interaction events. The time between calls to this method may vary, do not depend on it for time-sensitive or critical tasks.

Interaction events represent user direct interaction with a widget, for example when a widget was visible.

This function must complete within 10 seconds of being called. If the timeout is exceeded, the operation will be canceled.

This method is called from the main thread.

Parameters
context: Context

the context from which this method is called

events: List<WearWidgetEvent>

A list WearWidgetEvent representing interactions that occurred.

onRemoved

Added in 1.0.0-alpha03
@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-alpha03
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