AppWidgetManagerCompat

Added in 1.0.0

public final class AppWidgetManagerCompat


Summary

Public methods

static final @NonNull RemoteViews
createExactSizeAppWidget(
    @NonNull AppWidgetManager appWidgetManager,
    int appWidgetId,
    @NonNull Function1<@NonNull SizeFCompat, @NonNull RemoteViews> factory
)

Creates a RemoteViews associated with each size assigned to the app widget by AppWidgetManager, invoking factory to create each alternative view.

static final @NonNull RemoteViews
createResponsiveSizeAppWidget(
    @NonNull AppWidgetManager appWidgetManager,
    int appWidgetId,
    @NonNull Collection<@NonNull SizeFCompat> dpSizes,
    @NonNull Function1<@NonNull SizeFCompat, @NonNull RemoteViews> factory
)

Creating a RemoteViews associated with each size provided in dpSizes.

static final void
updateAppWidget(
    @NonNull AppWidgetManager receiver,
    int appWidgetId,
    @NonNull Function1<@NonNull SizeFCompat, @NonNull RemoteViews> factory
)

Updates the app widget with appWidgetId, creating a RemoteViews for each size assigned to the app widget by AppWidgetManager, invoking factory to create each alternative view.

static final void
updateAppWidget(
    @NonNull AppWidgetManager receiver,
    int appWidgetId,
    @NonNull Collection<@NonNull SizeFCompat> dpSizes,
    @NonNull Function1<@NonNull SizeFCompat, @NonNull RemoteViews> factory
)

Updates the app widget with appWidgetId, creating a RemoteViews for each size provided in dpSizes.

Public methods

createExactSizeAppWidget

public static final @NonNull RemoteViews createExactSizeAppWidget(
    @NonNull AppWidgetManager appWidgetManager,
    int appWidgetId,
    @NonNull Function1<@NonNull SizeFCompat, @NonNull RemoteViews> factory
)

Creates a RemoteViews associated with each size assigned to the app widget by AppWidgetManager, invoking factory to create each alternative view.

This provides "exact" sizing , which allows you to tailor your app widget appearance to the exact size at which it is displayed. If you are only concerned with a small number of size thresholds, it is preferable to use "responsive" sizing by providing a fixed set of sizes that your app widget supports.

As your factory may be invoked multiple times, if there is expensive computation of state that is shared among each size, it is recommended to perform that computation before calling this and cache the results as necessary.

To handle resizing of your app widget, it is necessary to call AppWidgetManager.updateAppWidget during both android.appwidget.AppWidgetProvider.onUpdate and android.appwidget.AppWidgetProvider.onAppWidgetOptionsChanged.

Parameters
@NonNull AppWidgetManager appWidgetManager

the AppWidgetManager to provide information about appWidgetId

int appWidgetId

the id of the app widget

@NonNull Function1<@NonNull SizeFCompat, @NonNull RemoteViews> factory

a function to create a RemoteViews for a given width and height (in dp)

createResponsiveSizeAppWidget

public static final @NonNull RemoteViews createResponsiveSizeAppWidget(
    @NonNull AppWidgetManager appWidgetManager,
    int appWidgetId,
    @NonNull Collection<@NonNull SizeFCompat> dpSizes,
    @NonNull Function1<@NonNull SizeFCompat, @NonNull RemoteViews> factory
)

Creating a RemoteViews associated with each size provided in dpSizes.

This provides "responsive" sizing , which allows for smoother resizing and a more consistent experience across different host configurations.

As your factory may be invoked multiple times, if there is expensive computation of state that is shared among each size, it is recommended to perform that computation before calling this and cache the results as necessary.

To handle resizing of your app widget, it is necessary to call AppWidgetManager.updateAppWidget during both android.appwidget.AppWidgetProvider.onUpdate and android.appwidget.AppWidgetProvider.onAppWidgetOptionsChanged. If your app's minSdk is 31 or higher, it is only necessary to call updateAppWidget during onUpdate.

Parameters
@NonNull AppWidgetManager appWidgetManager

the AppWidgetManager to provide information about appWidgetId

int appWidgetId

the id of the app widget

@NonNull Collection<@NonNull SizeFCompat> dpSizes

a collection of sizes (in dp) that your app widget supports. Must not be empty or contain more than 16 elements.

@NonNull Function1<@NonNull SizeFCompat, @NonNull RemoteViews> factory

a function to create a RemoteViews for a given width and height (in dp). It is guaranteed that factory will only ever be called with the values provided in dpSizes.

updateAppWidget

public static final void updateAppWidget(
    @NonNull AppWidgetManager receiver,
    int appWidgetId,
    @NonNull Function1<@NonNull SizeFCompat, @NonNull RemoteViews> factory
)

Updates the app widget with appWidgetId, creating a RemoteViews for each size assigned to the app widget by AppWidgetManager, invoking factory to create each alternative view.

This provides "exact" sizing , which allows you to tailor your app widget appearance to the exact size at which it is displayed. If you are only concerned with a small number of size thresholds, it is preferable to use "responsive" sizing by providing a fixed set of sizes that your app widget supports.

As your factory may be invoked multiple times, if there is expensive computation of state that is shared among each size, it is recommended to perform that computation before calling this and cache the results as necessary.

To handle resizing of your app widget, it is necessary to call this function during both android.appwidget.AppWidgetProvider.onUpdate and android.appwidget.AppWidgetProvider.onAppWidgetOptionsChanged.

Parameters
int appWidgetId

the id of the app widget

@NonNull Function1<@NonNull SizeFCompat, @NonNull RemoteViews> factory

a function to create a RemoteViews for a given width and height (in dp)

updateAppWidget

public static final void updateAppWidget(
    @NonNull AppWidgetManager receiver,
    int appWidgetId,
    @NonNull Collection<@NonNull SizeFCompat> dpSizes,
    @NonNull Function1<@NonNull SizeFCompat, @NonNull RemoteViews> factory
)

Updates the app widget with appWidgetId, creating a RemoteViews for each size provided in dpSizes.

This provides "responsive" sizing , which allows for smoother resizing and a more consistent experience across different host configurations.

As your factory may be invoked multiple times, if there is expensive computation of state that is shared among each size, it is recommended to perform that computation before calling this and cache the results as necessary.

To handle resizing of your app widget, it is necessary to call this function during both android.appwidget.AppWidgetProvider.onUpdate and android.appwidget.AppWidgetProvider.onAppWidgetOptionsChanged. If your app's minSdk is 31 or higher, it is only necessary to call this function during onUpdate.

Parameters
int appWidgetId

the id of the app widget

@NonNull Collection<@NonNull SizeFCompat> dpSizes

a collection of sizes (in dp) that your app widget supports. Must not be empty or contain more than 16 elements.

@NonNull Function1<@NonNull SizeFCompat, @NonNull RemoteViews> factory

a function to create a RemoteViews for a given width and height (in dp). It is guaranteed that factory will only ever be called with the values provided in dpSizes.