Adding the App WidgetProvider Info Metadata

The AppWidgetProviderlnfo defines the essential qualities of an App Widget, such as its minimum layout dimensions, its initial layout resource, how often to update the App Widget, and (optionally) a configuration Activity to launch at create-time. Define the AppWidgetProviderlnfo object in an XML resource using a single <appwidget-provider> element and save it in the project's res/xml/folder.

For example:

<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" android:minWidth="294dp" <!-- density-independent pixels --> android:minHeight="72dp"

android:updatePeriodMillis="86400000" <!— once per day —> android:initialLayout="@layout/example appwidget"

android:configure="com.example.android.ExampleAppWidgetConfigure" > </appwidget-provider>

Here's a summary of the <appwidget-provider> attributes:

• The values for the minWidth and minHeight attributes specify the minimum area required by the App Widget's layout.

The default Home screen positions App Widgets in its window based on a grid of cells that have a defined height and width. If the values for an App Widget's minimum width or height don't match the dimensions of the cells, then the App Widget dimensions round up to the nearest cell size. (See the App Widget Design Guidelines for more information on the Home screen cell sizes.)

Because the Home screen's layout orientation (and thus, the cell sizes) can change, as a rule of thumb, you should assume the worst-case cell size of 74 pixels for the height and width of a cell. However, you must subtract 2 from the final dimension to account for any integer rounding errors that occur in the pixel count. To find your minimum width and height in density-independent pixels (dp), use this formula:

Following this formula, you should use 72 dp for a height of one cell, 294 dp and for a width of four cells.

• The updatePeriodMillis attribute defines how often the App Widget framework should request an update from the AppWidgetProvider by calling the onUpdate() method. The actual update is not guaranteed to occur exactly on time with this value and we

0 0

Post a comment