FileDocCategorySizeDatePackage
Preferences.javaAPI DocAndroid 1.5 API5224Wed May 06 22:42:46 BST 2009com.android.email

Preferences

public class Preferences extends Object

Fields Summary
private static Preferences
preferences
android.content.SharedPreferences
mSharedPreferences
Constructors Summary
private Preferences(android.content.Context context)

        mSharedPreferences = context.getSharedPreferences("AndroidMail.Main", Context.MODE_PRIVATE);
    
Methods Summary
public voidclear()

        mSharedPreferences.edit().clear().commit();
    
public voiddump()

        if (Config.LOGV) {
            for (String key : mSharedPreferences.getAll().keySet()) {
                Log.v(Email.LOG_TAG, key + " = " + mSharedPreferences.getAll().get(key));
            }
        }
    
public AccountgetAccountByContentUri(android.net.Uri uri)
Get an account object by Uri, or return null if no account exists TODO: Merge hardcoded strings with the same strings in Account.java

        if (!"content".equals(uri.getScheme()) || !"accounts".equals(uri.getAuthority())) {
            return null;
        }
        String uuid = uri.getPath().substring(1);
        if (uuid == null) {
            return null;
        }
        String accountUuids = mSharedPreferences.getString("accountUuids", null);
        if (accountUuids == null || accountUuids.length() == 0) {
            return null;
        }
        String[] uuids = accountUuids.split(",");
        for (int i = 0, length = uuids.length; i < length; i++) {
            if (uuid.equals(uuids[i])) {
                return new Account(this, uuid);
            }
        }
        return null;
    
public Account[]getAccounts()
Returns an array of the accounts on the system. If no accounts are registered the method returns an empty array.

return

        String accountUuids = mSharedPreferences.getString("accountUuids", null);
        if (accountUuids == null || accountUuids.length() == 0) {
            return new Account[] {};
        }
        String[] uuids = accountUuids.split(",");
        Account[] accounts = new Account[uuids.length];
        for (int i = 0, length = uuids.length; i < length; i++) {
            accounts[i] = new Account(this, uuids[i]);
        }
        return accounts;
    
public AccountgetDefaultAccount()
Returns the Account marked as default. If no account is marked as default the first account in the list is marked as default and then returned. If there are no accounts on the system the method returns null.

return

        String defaultAccountUuid = mSharedPreferences.getString("defaultAccountUuid", null);
        Account defaultAccount = null;
        Account[] accounts = getAccounts();
        if (defaultAccountUuid != null) {
            for (Account account : accounts) {
                if (account.getUuid().equals(defaultAccountUuid)) {
                    defaultAccount = account;
                    break;
                }
            }
        }

        if (defaultAccount == null) {
            if (accounts.length > 0) {
                defaultAccount = accounts[0];
                setDefaultAccount(defaultAccount);
            }
        }

        return defaultAccount;
    
public booleangetEnableSensitiveLogging()

        return mSharedPreferences.getBoolean("enableSensitiveLogging", false);
    
public static synchronized com.android.email.PreferencesgetPreferences(android.content.Context context)
TODO need to think about what happens if this gets GCed along with the Activity that initialized it. Do we lose ability to read Preferences in further Activities? Maybe this should be stored in the Application context.

return

        if (preferences == null) {
            preferences = new Preferences(context);
        }
        return preferences;
    
public booleangeteEnableDebugLogging()

        return mSharedPreferences.getBoolean("enableDebugLogging", false);
    
public voidsave()

    
public voidsetDefaultAccount(Account account)

        mSharedPreferences.edit().putString("defaultAccountUuid", account.getUuid()).commit();
    
public voidsetEnableDebugLogging(boolean value)

        mSharedPreferences.edit().putBoolean("enableDebugLogging", value).commit();
    
public voidsetEnableSensitiveLogging(boolean value)

        mSharedPreferences.edit().putBoolean("enableSensitiveLogging", value).commit();