Книга: Beginning Android
Sprucing Up Your Home
Sprucing Up Your Home
Android 1.5 lets you do more with the built-in home screen application, notably by adding “app widgets” and “live folders”. As an application developer, you can choose to offer app widgets and/or live folders from your own applications for users to add to their home screens.
App widgets are simply user interface elements added to the home screen. Previous Android editions had some of these (the analog clock, the Google search bar), but they were fixed in type and number. Now, not only does Android add in a couple of more app widgets (e.g., media player, picture frame), but users can add and remove app widgets, and developers can create their own (see Figure A-2).
Figure A-2. Some stock Android 1.5 app widgets
App widgets are built not using ordinary layouts, but rather with a layout subset known as
RemoteViews. You cannot use arbitrary widgets with
RemoteViews, though it supports many common ones. The term “remote views” comes from the fact that while the UI is defined by your application, the UI (in the form of the “app widget”) runs in the context of another application, in this case the home screen.
Implementing an app widget involves creating some XML metadata, associating that metadata with a
<receiver> element in your manifest, and implementing that receiver as an
AppWidgetProvider. Most likely in conjunction with a service that will handle any time-consuming work (e.g., network lookups), your provider will create and push out
RemoteViews when requested by the home screen. Note that app widgets are designed for infrequent update, since frequent polling for new widget contents can rapidly drain the device battery.
Live folders are, in essence, a simplified home-screen-launched look into the contents published by a
ContentProvider. In the screenshot shown previously, you see a “Phones” icon. Tapping that brings up a dialog over the home screen containing a list of all contacts containing phone numbers as you can see in Figure A-3.
Figure A-3. A Live Folder in Android 1.5
Tapping an individual contact, of course, brings up the detail screen for that contact.
To create your own live folders for your users to offer, you can add an intent filter watching for a
CREATE_LIVE_FOLDER Intent on an activity in your application. That activity, in turn, simply calls
setResult() with another
Intent object, this one describing the live folder, such as its icon, name, and display mode (e.g.,
Intent also contains the
Uri pointing to the
ContentProvider whose information you are trying to display. That
ContentProvider should be updated to recognize the live folder
Uri and, on
query(), return an ID, title, and description of each piece of content in the provider (or a subset if appropriate). Android will take care of the rest, in terms of formatting the data in the live folder convention (large font title, small font description), pouring the query results into a list, etc.
- Chapter 12. Debugging your scripts
- Listing your active rule-set
- Updating and flushing your tables
- How to use this License for your documents
- 2. How to Apply These Terms to Your New Programs
- Scaling makes your object darker?
- Partitioning Your Hard Drive
- The Home Icon
- Keeping Your Software Up-to-Date
- Assessing Your Backup Needs and Resources
- Building the Source Yourself
- Your Own Domain Name and Third-Party DNS