All ContactsLive FolderCreator Activityjava

The AllContactsLiveFolderCreatorActivity class has one responsibility: to serve as the generator or creator of a live folder (see Listing 13-13). Think of it as a template for the live folder. Every time this activity is clicked (through the Folders option in the home page's context menu), it will generate a live folder on the home page.

This activity accomplishes its task by telling the invoker—the home page or live-folder framework, in this case—the name of the live folder, the image to use for the live-folder icon, the URI where the data is available, and the display mode (list or grid). The framework, in turn, is responsible for creating the live-folder icon on the home page.

Note For all the contracts needed by a live folder, see the Android 1.5 SDK documentation for the android.provider.LiveFolders class.

Listing 13-13. AllContactsLiveFolderCreatorActivity Source Code public class AllContactsLiveFolderCreatorActivity extends Activity {

^Override protected void onCreate(Bundle savedlnstanceState) {


final Intent intent = getIntent(); final String action = intent.getAction();

if (LiveFolders.ACTION_CREATE_LIVE_FOLDER.equals(action)) {

setResult(RESULT_OK, createLiveFolder(MyContactsProvider.CONTACTS_URI, "Contacts LF", R.drawable.icon)


private Intent createLiveFolder(Uri uri, String name, int icon) {

final Intent intent = new Intent(); intent.setData(uri);

intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME, name); intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON,

Intent.ShortcutIconResource.fromContext(this, icon)); intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE,

LiveFolders.DISPLAY_MODE_LIST); return intent;

The createLiveFolder method essentially sets values on the intent that invoked it. When this intent is returned to the caller, the caller will know the following:

• The live-folder name

• The image to use for the live-folder icon

• The display mode: list or grid

• The data or content URI to invoke for data

This information is sufficient to create the live-folder icon as shown in Figure 13-4. When a user clicks this icon, the system will call the URI to retrieve data. It is up to the content provider identified by this URI to provide the standardized cursor. We'll now show you the code for that content provider: the MyContactsProvider class.

0 0

Post a comment