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

Accounts

public class Accounts extends android.app.ListActivity implements android.widget.AdapterView.OnItemClickListener, android.view.View.OnClickListener

Fields Summary
private static final int
DIALOG_REMOVE_ACCOUNT
private static int[]
secretKeyCodes
Key codes used to open a debug settings screen.
private int
mSecretKeyCodeIndex
private com.android.email.Account
mSelectedContextAccount
Constructors Summary
Methods Summary
public static voidactionShowAccounts(android.content.Context context)
Start the Accounts list activity. Uses the CLEAR_TOP flag which means that other stacked activities may be killed in order to get back to Accounts.

    
                                   
         
        Intent i = new Intent(context, Accounts.class);
        i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        context.startActivity(i);
    
private android.app.DialogcreateRemoveAccountDialog()

        return new AlertDialog.Builder(this)
            .setIcon(android.R.drawable.ic_dialog_alert)
            .setTitle(R.string.account_delete_dlg_title)
            .setMessage(getString(R.string.account_delete_dlg_instructions_fmt,
                    mSelectedContextAccount.getDescription()))
            .setPositiveButton(R.string.okay_action, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    dismissDialog(DIALOG_REMOVE_ACCOUNT);
                    try {
                        ((LocalStore)Store.getInstance(
                                mSelectedContextAccount.getLocalStoreUri(),
                                getApplication())).delete();
                    } catch (Exception e) {
                            // Ignore
                    }
                    mSelectedContextAccount.delete(Preferences.getPreferences(Accounts.this));
                    Email.setServicesEnabled(Accounts.this);
                    refresh();
                }
            })
            .setNegativeButton(R.string.cancel_action, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    dismissDialog(DIALOG_REMOVE_ACCOUNT);
                }
            })
            .create();
    
private voidonAddNewAccount()

        AccountSetupBasics.actionNewAccount(this);
    
public voidonClick(android.view.View view)

        if (view.getId() == R.id.add_new_account) {
            onAddNewAccount();
        }
    
private voidonCompose()

        Account defaultAccount =
                Preferences.getPreferences(this).getDefaultAccount();
        if (defaultAccount != null) {
            MessageCompose.actionCompose(this, defaultAccount);
        }
        else {
            onAddNewAccount();
        }
    
public booleanonContextItemSelected(android.view.MenuItem item)

        AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo)item.getMenuInfo();
        Account account = (Account)getListView().getItemAtPosition(menuInfo.position);
        switch (item.getItemId()) {
            case R.id.delete_account:
                onDeleteAccount(account);
                break;
            case R.id.edit_account:
                onEditAccount(account);
                break;
            case R.id.open:
                onOpenAccount(account);
                break;
        }
        return true;
    
public voidonCreate(android.os.Bundle icicle)

        super.onCreate(icicle);
        setContentView(R.layout.accounts);
        ListView listView = getListView();
        listView.setOnItemClickListener(this);
        listView.setItemsCanFocus(false);
        listView.setEmptyView(findViewById(R.id.empty));
        findViewById(R.id.add_new_account).setOnClickListener(this);
        registerForContextMenu(listView);

        if (icicle != null && icicle.containsKey("selectedContextAccount")) {
            mSelectedContextAccount = (Account) icicle.getSerializable("selectedContextAccount");
        }
    
public voidonCreateContextMenu(android.view.ContextMenu menu, android.view.View v, android.view.ContextMenu.ContextMenuInfo menuInfo)

        super.onCreateContextMenu(menu, v, menuInfo);
        menu.setHeaderTitle(R.string.accounts_context_menu_title);
        getMenuInflater().inflate(R.menu.accounts_context, menu);
    
public android.app.DialogonCreateDialog(int id)

        switch (id) {
            case DIALOG_REMOVE_ACCOUNT:
                return createRemoveAccountDialog();
        }
        return super.onCreateDialog(id);
    
public booleanonCreateOptionsMenu(android.view.Menu menu)

        super.onCreateOptionsMenu(menu);
        getMenuInflater().inflate(R.menu.accounts_option, menu);
        return true;
    
private voidonDeleteAccount(com.android.email.Account account)

        mSelectedContextAccount = account;
        showDialog(DIALOG_REMOVE_ACCOUNT);
    
private voidonEditAccount(com.android.email.Account account)

        AccountSettings.actionSettings(this, account);
    
public voidonItemClick(android.widget.AdapterView parent, android.view.View view, int position, long id)

        Account account = (Account)parent.getItemAtPosition(position);
        onOpenAccount(account);
    
public booleanonItemLongClick(android.widget.AdapterView parent, android.view.View view, int position, long id)

        return true;
    
public booleanonKeyDown(int keyCode, android.view.KeyEvent event)

        if (event.getKeyCode() == secretKeyCodes[mSecretKeyCodeIndex]) {
            mSecretKeyCodeIndex++;
            if (mSecretKeyCodeIndex == secretKeyCodes.length) {
                mSecretKeyCodeIndex = 0;
                startActivity(new Intent(this, Debug.class));
            }
        } else {
            mSecretKeyCodeIndex = 0;
        }
        return super.onKeyDown(keyCode, event);
    
private voidonOpenAccount(com.android.email.Account account)

        FolderMessageList.actionHandleAccount(this, account);
    
public booleanonOptionsItemSelected(android.view.MenuItem item)

        switch (item.getItemId()) {
            case R.id.add_new_account:
                onAddNewAccount();
                break;
            case R.id.check_mail:
                onRefresh();
                break;
            case R.id.compose:
                onCompose();
                break;
            default:
                return super.onOptionsItemSelected(item);
        }
        return true;
    
private voidonRefresh()

        MessagingController.getInstance(getApplication()).checkMail(this, null, null);
    
public voidonResume()

        super.onResume();

        NotificationManager notifMgr = (NotificationManager)
                getSystemService(Context.NOTIFICATION_SERVICE);
        notifMgr.cancel(1);

        refresh();
    
public voidonSaveInstanceState(android.os.Bundle outState)

        super.onSaveInstanceState(outState);
        if (mSelectedContextAccount != null) {
            outState.putSerializable("selectedContextAccount", mSelectedContextAccount);
        }
    
private voidrefresh()

        Account[] accounts = Preferences.getPreferences(this).getAccounts();
        getListView().setAdapter(new AccountsAdapter(accounts));