Added in API level 3

AppWidgetHostView


open class AppWidgetHostView : FrameLayout
kotlin.Any
   ↳ android.view.View
   ↳ android.view.ViewGroup
   ↳ android.widget.FrameLayout
   ↳ android.appwidget.AppWidgetHostView

Provides the glue to show AppWidget views. This class offers automatic animation between updates, and will try recycling old views for each incoming RemoteViews.

Summary

Inherited XML attributes
Inherited constants
Public constructors

Create a host view.

AppWidgetHostView(context: Context!, animationIn: Int, animationOut: Int)

Create a host view.

Public methods
open FrameLayout.LayoutParams!

Returns a new set of layout parameters based on the supplied attributes set.

open Int

open AppWidgetProviderInfo!

open static Rect!
getDefaultPaddingForWidget(context: Context!, component: ComponentName!, padding: Rect!)

As of ICE_CREAM_SANDWICH we are automatically adding padding to widgets targeting ICE_CREAM_SANDWICH and higher.

open Unit

Reset the dynamically overloaded resources, reverting to the default values for all the colors.

open Unit
setAppWidget(appWidgetId: Int, info: AppWidgetProviderInfo!)

Set the AppWidget that will be displayed by this view.

open Unit

Set the dynamically overloaded color resources.

open Unit
setExecutor(executor: Executor!)

Sets an executor which can be used for asynchronously inflating.

open Unit
setOnLightBackground(onLightBackground: Boolean)

Sets whether the widget is being displayed on a light/white background and use an alternate UI if available.

open Unit

Process a set of RemoteViews coming in as an update from the AppWidget provider.

open Unit

Specify some extra information for the widget provider.

open Unit
updateAppWidgetSize(newOptions: Bundle!, minWidth: Int, minHeight: Int, maxWidth: Int, maxHeight: Int)

Provide guidance about the size of this widget to the AppWidgetManager.

open Unit
updateAppWidgetSize(newOptions: Bundle, sizes: MutableList<SizeF!>)

Provide guidance about the size of this widget to the AppWidgetManager.

Protected methods
open Unit

Called by draw to draw the child views.

open Unit

open Unit

open View!

Inflate and return the default layout requested by AppWidget provider.

open View!

Inflate and return a view that represents an error state.

open Unit
onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int)

open Unit
prepareView(view: View!)

Prepare the given view to be shown.

Inherited functions
Inherited properties

Public constructors

AppWidgetHostView

Added in API level 3
AppWidgetHostView(context: Context!)

Create a host view. Uses default fade animations.

AppWidgetHostView

Added in API level 3
AppWidgetHostView(
    context: Context!,
    animationIn: Int,
    animationOut: Int)

Create a host view. Uses specified animations when pushing updateAppWidget(android.widget.RemoteViews).

Parameters
animationIn Int: Resource ID of in animation to use
animationOut Int: Resource ID of out animation to use

Public methods

generateLayoutParams

Added in API level 3
open fun generateLayoutParams(attrs: AttributeSet!): FrameLayout.LayoutParams!

Returns a new set of layout parameters based on the supplied attributes set.

Parameters
attrs AttributeSet!: the attributes to build the layout parameters from
Return
FrameLayout.LayoutParams! an instance of android.view.ViewGroup.LayoutParams or one of its descendants

getAppWidgetId

Added in API level 3
open fun getAppWidgetId(): Int

getAppWidgetInfo

Added in API level 3
open fun getAppWidgetInfo(): AppWidgetProviderInfo!

getDefaultPaddingForWidget

Added in API level 15
open static fun getDefaultPaddingForWidget(
    context: Context!,
    component: ComponentName!,
    padding: Rect!
): Rect!

As of ICE_CREAM_SANDWICH we are automatically adding padding to widgets targeting ICE_CREAM_SANDWICH and higher. The new widget design guidelines strongly recommend that widget developers do not add extra padding to their widgets. This will help achieve consistency among widgets. Note: this method is only needed by developers of AppWidgetHosts. The method is provided in order for the AppWidgetHost to account for the automatic padding when computing the number of cells to allocate to a particular widget.

Parameters
context Context!: the current context
component ComponentName!: the component name of the widget
padding Rect!: Rect in which to place the output, if null, a new Rect will be allocated and returned
Return
Rect! default padding for this widget, in pixels

resetColorResources

Added in API level 31
open fun resetColorResources(): Unit

Reset the dynamically overloaded resources, reverting to the default values for all the colors. If colors were defined before, calling this method will trigger a full re-inflation of the App Widget.

setAppWidget

Added in API level 3
open fun setAppWidget(
    appWidgetId: Int,
    info: AppWidgetProviderInfo!
): Unit

Set the AppWidget that will be displayed by this view. This method also adds default padding to widgets, as described in getDefaultPaddingForWidget(android.content.Context,android.content.ComponentName,android.graphics.Rect) and can be overridden in order to add custom padding.

setColorResources

Added in API level 31
open fun setColorResources(colorMapping: SparseIntArray): Unit

Set the dynamically overloaded color resources. colorMapping maps a predefined set of color resources to their ARGB representation. Any entry not in the predefined set of colors will be ignored. Calling this method will trigger a full re-inflation of the App Widget. The color resources that can be overloaded are the ones whose name is prefixed with system_neutral or system_accent, for example android.R.color#system_neutral1_500.

Parameters
colorMapping SparseIntArray: This value cannot be null.

setExecutor

Added in API level 26
open fun setExecutor(executor: Executor!): Unit

Sets an executor which can be used for asynchronously inflating. CPU intensive tasks like view inflation or loading images will be performed on the executor. The updates will still be applied on the UI thread.

Parameters
executor Executor!: the executor to use or null.

setOnLightBackground

Added in API level 29
open fun setOnLightBackground(onLightBackground: Boolean): Unit

Sets whether the widget is being displayed on a light/white background and use an alternate UI if available.

updateAppWidget

Added in API level 3
open fun updateAppWidget(remoteViews: RemoteViews!): Unit

Process a set of RemoteViews coming in as an update from the AppWidget provider. Will animate into these new views as needed

updateAppWidgetOptions

Added in API level 16
open fun updateAppWidgetOptions(options: Bundle!): Unit

Specify some extra information for the widget provider. Causes a callback to the AppWidgetProvider.

Parameters
options Bundle!: The bundle of options information.

updateAppWidgetSize

Added in API level 16
Deprecated in API level 31
open fun updateAppWidgetSize(
    newOptions: Bundle!,
    minWidth: Int,
    minHeight: Int,
    maxWidth: Int,
    maxHeight: Int
): Unit

Deprecated: use AppWidgetHostView#updateAppWidgetSize(Bundle, List) instead.

Provide guidance about the size of this widget to the AppWidgetManager. The widths and heights should correspond to the full area the AppWidgetHostView is given. Padding added by the framework will be accounted for automatically. This information gets embedded into the AppWidget options and causes a callback to the AppWidgetProvider. In addition, the list of sizes is explicitly set to an empty list.

Parameters
newOptions Bundle!: The bundle of options, in addition to the size information, can be null.
minWidth Int: The minimum width in dips that the widget will be displayed at.
minHeight Int: The maximum height in dips that the widget will be displayed at.
maxWidth Int: The maximum width in dips that the widget will be displayed at.
maxHeight Int: The maximum height in dips that the widget will be displayed at.

updateAppWidgetSize

Added in API level 31
open fun updateAppWidgetSize(
    newOptions: Bundle,
    sizes: MutableList<SizeF!>
): Unit

Provide guidance about the size of this widget to the AppWidgetManager. The sizes should correspond to the full area the AppWidgetHostView is given. Padding added by the framework will be accounted for automatically. This method will update the option bundle with the list of sizes and the min/max bounds for width and height.

Parameters
newOptions Bundle: The bundle of options, in addition to the size information. This value cannot be null.
sizes MutableList<SizeF!>: Sizes, in dips, the widget may be displayed at without calling the provider again. Typically, this will be size of the widget in landscape and portrait. On some foldables, this might include the size on the outer and inner screens. This value cannot be null.

Protected methods

dispatchDraw

Added in API level 3
protected open fun dispatchDraw(canvas: Canvas): Unit

Called by draw to draw the child views. This may be overridden by derived classes to gain control just before its children are drawn (but after its own view has been drawn).

Parameters
canvas Canvas: This value cannot be null.

dispatchRestoreInstanceState

Added in API level 3
protected open fun dispatchRestoreInstanceState(container: SparseArray<Parcelable!>!): Unit
Parameters
container SparseArray<Parcelable!>!: The SparseArray which holds previously saved state.

dispatchSaveInstanceState

Added in API level 3
protected open fun dispatchSaveInstanceState(container: SparseArray<Parcelable!>!): Unit
Parameters
container SparseArray<Parcelable!>!: The SparseArray in which to save the view's state.

getDefaultView

Added in API level 3
protected open fun getDefaultView(): View!

Inflate and return the default layout requested by AppWidget provider.

getErrorView

Added in API level 3
protected open fun getErrorView(): View!

Inflate and return a view that represents an error state.

onLayout

Added in API level 3
protected open fun onLayout(
    changed: Boolean,
    left: Int,
    top: Int,
    right: Int,
    bottom: Int
): Unit
Parameters
changed Boolean: This is a new size or position for this view
left Int: Left position, relative to parent
top Int: Top position, relative to parent
right Int: Right position, relative to parent
bottom Int: Bottom position, relative to parent

prepareView

Added in API level 3
protected open fun prepareView(view: View!): Unit

Prepare the given view to be shown. This might include adjusting FrameLayout.LayoutParams before inserting.