FileDocCategorySizeDatePackage
AccountShortcutPicker.javaAPI DocAndroid 1.5 API7815Wed May 06 22:42:46 BST 2009com.android.email.activity

AccountShortcutPicker

public class AccountShortcutPicker extends android.app.ListActivity implements android.widget.AdapterView.OnItemClickListener
This class implements a launcher shortcut for directly accessing a single account. This is simply a lightweight version of Accounts, and should almost certainly be merged with it (or, one could be a base class of the other).

Fields Summary
com.android.email.Account[]
mAccounts
Constructors Summary
Methods Summary
public voidonCreate(android.os.Bundle icicle)

        super.onCreate(icicle);
        
        // finish() immediately if we aren't supposed to be here
        if (!Intent.ACTION_CREATE_SHORTCUT.equals(getIntent().getAction())) {
            finish();
            return;
        }

        // finish() immediately if no accounts are configured
        mAccounts = Preferences.getPreferences(this).getAccounts();
        if (mAccounts.length == 0) {
            finish();
            return;
        }
        
        setContentView(R.layout.accounts);
        ListView listView = getListView();
        listView.setOnItemClickListener(this);
        listView.setItemsCanFocus(false);
        listView.setEmptyView(findViewById(R.id.empty));
    
public voidonItemClick(android.widget.AdapterView parent, android.view.View view, int position, long id)

        Account account = (Account)parent.getItemAtPosition(position);
        onOpenAccount(account);
    
private voidonOpenAccount(com.android.email.Account account)

        // generate & return intents
        setupShortcut(account);
        finish();
    
public voidonResume()

        super.onResume();
        refresh();
    
private voidrefresh()

        getListView().setAdapter(new AccountsAdapter(mAccounts));
    
private voidsetupShortcut(com.android.email.Account account)
This function creates a shortcut and returns it to the caller. There are actually two intents that you will send back. The first intent serves as a container for the shortcut and is returned to the launcher by setResult(). This intent must contain three fields:
  • {@link android.content.Intent#EXTRA_SHORTCUT_INTENT} The shortcut intent.
  • {@link android.content.Intent#EXTRA_SHORTCUT_NAME} The text that will be displayed with the shortcut.
  • {@link android.content.Intent#EXTRA_SHORTCUT_ICON} The shortcut's icon, if provided as a bitmap, or {@link android.content.Intent#EXTRA_SHORTCUT_ICON_RESOURCE} if provided as a drawable resource.
If you use a simple drawable resource, note that you must wrapper it using {@link android.content.Intent.ShortcutIconResource}, as shown below. This is required so that the launcher can access resources that are stored in your application's .apk file. If you return a bitmap, such as a thumbnail, you can simply put the bitmap into the extras bundle using {@link android.content.Intent#EXTRA_SHORTCUT_ICON}. The shortcut intent can be any intent that you wish the launcher to send, when the user clicks on the shortcut. Typically this will be {@link android.content.Intent#ACTION_VIEW} with an appropriate Uri for your content, but any Intent will work here as long as it triggers the desired action within your Activity.

        // First, set up the shortcut intent.

        Intent shortcutIntent = FolderMessageList.actionHandleAccountUriIntent(this, 
                account, Email.INBOX);

        // Then, set up the container intent (the response to the caller)

        Intent intent = new Intent();
        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, account.getDescription());
        Parcelable iconResource = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);
        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);

        // Now, return the result to the launcher

        setResult(RESULT_OK, intent);