FileDocCategorySizeDatePackage
AccountSettings.javaAPI DocAndroid 1.5 API8531Wed May 06 22:42:46 BST 2009com.android.email.activity.setup

AccountSettings

public class AccountSettings extends android.preference.PreferenceActivity

Fields Summary
private static final String
EXTRA_ACCOUNT
private static final String
PREFERENCE_TOP_CATERGORY
private static final String
PREFERENCE_DESCRIPTION
private static final String
PREFERENCE_NAME
private static final String
PREFERENCE_FREQUENCY
private static final String
PREFERENCE_DEFAULT
private static final String
PREFERENCE_NOTIFY
private static final String
PREFERENCE_VIBRATE
private static final String
PREFERENCE_RINGTONE
private static final String
PREFERENCE_INCOMING
private static final String
PREFERENCE_OUTGOING
private static final String
PREFERENCE_ADD_ACCOUNT
private com.android.email.Account
mAccount
private android.preference.EditTextPreference
mAccountDescription
private android.preference.EditTextPreference
mAccountName
private android.preference.ListPreference
mCheckFrequency
private android.preference.CheckBoxPreference
mAccountDefault
private android.preference.CheckBoxPreference
mAccountNotify
private android.preference.CheckBoxPreference
mAccountVibrate
private android.preference.RingtonePreference
mAccountRingtone
Constructors Summary
Methods Summary
public static voidactionSettings(android.content.Context context, com.android.email.Account account)


           
        Intent i = new Intent(context, AccountSettings.class);
        i.putExtra(EXTRA_ACCOUNT, account);
        context.startActivity(i);
    
private voidonAddNewAccount()

        AccountSetupBasics.actionNewAccount(this);
        finish();
    
public voidonCreate(android.os.Bundle savedInstanceState)

        super.onCreate(savedInstanceState);

        mAccount = (Account)getIntent().getSerializableExtra(EXTRA_ACCOUNT);

        addPreferencesFromResource(R.xml.account_settings_preferences);

        Preference category = findPreference(PREFERENCE_TOP_CATERGORY);
        category.setTitle(getString(R.string.account_settings_title_fmt));

        mAccountDescription = (EditTextPreference) findPreference(PREFERENCE_DESCRIPTION);
        mAccountDescription.setSummary(mAccount.getDescription());
        mAccountDescription.setText(mAccount.getDescription());
        mAccountDescription.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                final String summary = newValue.toString();
                mAccountDescription.setSummary(summary);
                mAccountDescription.setText(summary);
                return false;
            }
        });

        mAccountName = (EditTextPreference) findPreference(PREFERENCE_NAME);
        mAccountName.setSummary(mAccount.getName());
        mAccountName.setText(mAccount.getName());
        mAccountName.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                final String summary = newValue.toString();
                mAccountName.setSummary(summary);
                mAccountName.setText(summary);
                return false;
            }
        });

        mCheckFrequency = (ListPreference) findPreference(PREFERENCE_FREQUENCY);
        mCheckFrequency.setValue(String.valueOf(mAccount.getAutomaticCheckIntervalMinutes()));
        mCheckFrequency.setSummary(mCheckFrequency.getEntry());
        mCheckFrequency.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                final String summary = newValue.toString();
                int index = mCheckFrequency.findIndexOfValue(summary);
                mCheckFrequency.setSummary(mCheckFrequency.getEntries()[index]);
                mCheckFrequency.setValue(summary);
                return false;
            }
        });

        mAccountDefault = (CheckBoxPreference) findPreference(PREFERENCE_DEFAULT);
        mAccountDefault.setChecked(
                mAccount.equals(Preferences.getPreferences(this).getDefaultAccount()));

        mAccountNotify = (CheckBoxPreference) findPreference(PREFERENCE_NOTIFY);
        mAccountNotify.setChecked(mAccount.isNotifyNewMail());

        mAccountRingtone = (RingtonePreference) findPreference(PREFERENCE_RINGTONE);

        // XXX: The following two lines act as a workaround for the RingtonePreference
        //      which does not let us set/get the value programmatically
        SharedPreferences prefs = mAccountRingtone.getPreferenceManager().getSharedPreferences();
        prefs.edit().putString(PREFERENCE_RINGTONE, mAccount.getRingtone()).commit();

        mAccountVibrate = (CheckBoxPreference) findPreference(PREFERENCE_VIBRATE);
        mAccountVibrate.setChecked(mAccount.isVibrate());

        findPreference(PREFERENCE_INCOMING).setOnPreferenceClickListener(
                new Preference.OnPreferenceClickListener() {
                    public boolean onPreferenceClick(Preference preference) {
                        onIncomingSettings();
                        return true;
                    }
                });

        findPreference(PREFERENCE_OUTGOING).setOnPreferenceClickListener(
                new Preference.OnPreferenceClickListener() {
                    public boolean onPreferenceClick(Preference preference) {
                        onOutgoingSettings();
                        return true;
                    }
                });
        findPreference(PREFERENCE_ADD_ACCOUNT).setOnPreferenceClickListener(
                new Preference.OnPreferenceClickListener() {
                    public boolean onPreferenceClick(Preference preference) {
                        onAddNewAccount();
                        return true;
                    }
                });
    
private voidonIncomingSettings()

        AccountSetupIncoming.actionEditIncomingSettings(this, mAccount);
    
public booleanonKeyDown(int keyCode, android.view.KeyEvent event)

        if (keyCode == KeyEvent.KEYCODE_BACK) {
            saveSettings();
        }
        return super.onKeyDown(keyCode, event);
    
private voidonOutgoingSettings()

        AccountSetupOutgoing.actionEditOutgoingSettings(this, mAccount);
    
public voidonResume()

        super.onResume();
        mAccount.refresh(Preferences.getPreferences(this));
    
private voidsaveSettings()

        if (mAccountDefault.isChecked()) {
            Preferences.getPreferences(this).setDefaultAccount(mAccount);
        }
        mAccount.setDescription(mAccountDescription.getText());
        mAccount.setName(mAccountName.getText());
        mAccount.setNotifyNewMail(mAccountNotify.isChecked());
        mAccount.setAutomaticCheckIntervalMinutes(Integer.parseInt(mCheckFrequency.getValue()));
        mAccount.setVibrate(mAccountVibrate.isChecked());
        SharedPreferences prefs = mAccountRingtone.getPreferenceManager().getSharedPreferences();
        mAccount.setRingtone(prefs.getString(PREFERENCE_RINGTONE, null));
        mAccount.save(Preferences.getPreferences(this));
        Email.setServicesEnabled(this);