Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)
Android APIs
public class

AppWidgetHostView

extends FrameLayout
java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.FrameLayout
         ↳ android.appwidget.AppWidgetHostView

Class Overview

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

[Expand]
Inherited XML Attributes
From class android.widget.FrameLayout
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Constants
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Fields
From class android.view.View
Public Constructors
AppWidgetHostView ( Context context)
Create a host view.
AppWidgetHostView ( Context context, int animationIn, int animationOut)
Create a host view.
Public Methods
FrameLayout.LayoutParams generateLayoutParams ( AttributeSet attrs)
Returns a new set of layout parameters based on the supplied attributes set.
int getAppWidgetId ()
AppWidgetProviderInfo getAppWidgetInfo ()
static Rect getDefaultPaddingForWidget ( Context context, ComponentName component, Rect padding)
As of ICE_CREAM_SANDWICH we are automatically adding padding to widgets targeting ICE_CREAM_SANDWICH and higher.
void onInitializeAccessibilityNodeInfo ( AccessibilityNodeInfo info)
Initializes an AccessibilityNodeInfo with information about this view.
void setAppWidget (int appWidgetId, AppWidgetProviderInfo info)
Set the AppWidget that will be displayed by this view.
void updateAppWidget ( RemoteViews remoteViews)
Process a set of RemoteViews coming in as an update from the AppWidget provider.
void updateAppWidgetOptions ( Bundle options)
Specify some extra information for the widget provider.
void updateAppWidgetSize ( Bundle newOptions, int minWidth, int minHeight, int maxWidth, int maxHeight)
Provide guidance about the size of this widget to the AppWidgetManager.
Protected Methods
void )">dispatchRestoreInstanceState ( SparseArray < Parcelable > container)
Called by )">restoreHierarchyState(android.util.SparseArray) to retrieve the state for this view and its children.
void )">dispatchSaveInstanceState ( SparseArray < Parcelable > container)
Called by )">saveHierarchyState(android.util.SparseArray) to store the state for this view and its children.
boolean drawChild ( Canvas canvas, View child, long drawingTime)
Draw one child of this View Group.
View getDefaultView ()
Inflate and return the default layout requested by AppWidget provider.
View getErrorView ()
Inflate and return a view that represents an error state.
void prepareView ( View view)
Prepare the given view to be shown.
[Expand]
Inherited Methods
From class android.widget.FrameLayout
From class android.view.ViewGroup
From class android.view.View
From class java.lang.Object
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.ViewManager
From interface android.view.ViewParent
From interface android.view.accessibility.AccessibilityEventSource

Public Constructors

public AppWidgetHostView ( Context context)

Added in API level 3

Create a host view. Uses default fade animations.

public AppWidgetHostView ( Context context, int animationIn, int animationOut)

Added in API level 3

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

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

Public Methods

public FrameLayout.LayoutParams generateLayoutParams ( AttributeSet attrs)

Added in API level 3

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

Parameters
attrs the attributes to build the layout parameters from
Returns

public int getAppWidgetId ()

Added in API level 3

public AppWidgetProviderInfo getAppWidgetInfo ()

Added in API level 3

public static Rect getDefaultPaddingForWidget ( Context context, ComponentName component, Rect padding)

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 the current context
component the component name of the widget
padding Rect in which to place the output, if null, a new Rect will be allocated and returned
Returns
  • default padding for this widget, in pixels

public void onInitializeAccessibilityNodeInfo ( AccessibilityNodeInfo info)

Parameters
info The instance to initialize.

public void setAppWidget (int appWidgetId, AppWidgetProviderInfo info)

Added in API level 3

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

public void updateAppWidget ( RemoteViews remoteViews)

Added in API level 3

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

public void updateAppWidgetOptions ( Bundle options)

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

Parameters
options The bundle of options information.

public void updateAppWidgetSize ( Bundle newOptions, int minWidth, int minHeight, int maxWidth, int maxHeight)

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.

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

Protected Methods

)">

protected void dispatchRestoreInstanceState ( SparseArray < Parcelable > container)

Added in API level 3

Called by )">restoreHierarchyState(android.util.SparseArray) to retrieve the state for this view and its children. May be overridden to modify how restoring happens to a view's children; for example, some views may want to not store state for their children.

Parameters
container The SparseArray which holds previously saved state.
)">

protected void dispatchSaveInstanceState ( SparseArray < Parcelable > container)

Added in API level 3

Called by )">saveHierarchyState(android.util.SparseArray) to store the state for this view and its children. May be overridden to modify how freezing happens to a view's children; for example, some views may want to not store state for their children.

Parameters
container The SparseArray in which to save the view's state.

protected boolean drawChild ( Canvas canvas, View child, long drawingTime)

Added in API level 3

Draw one child of this View Group. This method is responsible for getting the canvas in the right state. This includes clipping, translating so that the child's scrolled origin is at 0, 0, and applying any animation transformations.

Parameters
canvas The canvas on which to draw the child
child Who to draw
drawingTime The time at which draw is occurring
Returns
  • True if an invalidate() was issued

protected View getDefaultView ()

Added in API level 3

Inflate and return the default layout requested by AppWidget provider.

protected View getErrorView ()

Added in API level 3

Inflate and return a view that represents an error state.

protected void prepareView ( View view)

Added in API level 3

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