Search in sources :

Example 26 with Account

use of android.accounts.Account in project Reader by TheKeeperOfPie.

the class ControllerUser method setAccount.

public void setAccount(Account accountUser) {
    boolean accountFound = false;
    Account[] accounts = accountManager.getAccountsByType(Reddit.ACCOUNT_TYPE);
    for (Account account : accounts) {
        if (account.name.equals(accountUser.name)) {
            this.account = account;
            accountFound = true;
            reloadUser();
            break;
        }
    }
    user = new User();
    if (!accountFound) {
        account = null;
    } else {
        user.setName(account.name);
    }
}
Also used : Account(android.accounts.Account) User(com.winsonchiu.reader.data.reddit.User)

Example 27 with Account

use of android.accounts.Account in project SeriesGuide by UweTrottmann.

the class TraktCredentials method getAccessToken.

/**
     * Get the access token. Avoid keeping this in memory, maybe calling {@link #hasCredentials()}
     * is sufficient.
     */
public String getAccessToken() {
    Account account = AccountUtils.getAccount(mContext);
    if (account == null) {
        return null;
    }
    AccountManager manager = AccountManager.get(mContext);
    return manager.getPassword(account);
}
Also used : Account(android.accounts.Account) AccountManager(android.accounts.AccountManager)

Example 28 with Account

use of android.accounts.Account in project SeriesGuide by UweTrottmann.

the class TraktCredentials method setAccessToken.

private boolean setAccessToken(String accessToken) {
    Account account = AccountUtils.getAccount(mContext);
    if (account == null) {
        // try to create a new account
        AccountUtils.createAccount(mContext);
    }
    account = AccountUtils.getAccount(mContext);
    if (account == null) {
        // give up
        return false;
    }
    AccountManager manager = AccountManager.get(mContext);
    manager.setPassword(account, accessToken);
    return true;
}
Also used : Account(android.accounts.Account) AccountManager(android.accounts.AccountManager)

Example 29 with Account

use of android.accounts.Account in project SeriesGuide by UweTrottmann.

the class AccountUtils method removeAccount.

@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
private static void removeAccount(Context context) {
    Timber.d("Removing existing accounts...");
    AccountManager manager = AccountManager.get(context);
    Account[] accounts = manager.getAccountsByType(ACCOUNT_TYPE);
    for (Account account : accounts) {
        if (AndroidUtils.isLollipopMR1OrHigher()) {
            manager.removeAccount(account, null, null, null);
        } else {
            //noinspection deprecation
            manager.removeAccount(account, null, null);
        }
    }
    Timber.d("Removing existing accounts...DONE");
}
Also used : Account(android.accounts.Account) AccountManager(android.accounts.AccountManager) TargetApi(android.annotation.TargetApi)

Example 30 with Account

use of android.accounts.Account in project SeriesGuide by UweTrottmann.

the class AccountUtils method createAccount.

public static void createAccount(Context context) {
    Timber.d("Setting up account...");
    // remove any existing accounts
    removeAccount(context);
    // try to create a new account
    AccountManager manager = AccountManager.get(context);
    Account account = new Account(ACCOUNT_NAME, ACCOUNT_TYPE);
    boolean isNewAccountAdded;
    try {
        isNewAccountAdded = manager != null && manager.addAccountExplicitly(account, null, null);
    } catch (SecurityException e) {
        Timber.e(e, "Setting up account...FAILED Account could not be added");
        return;
    }
    if (isNewAccountAdded) {
        // Inform the system that this account supports sync
        ContentResolver.setIsSyncable(account, SgApp.CONTENT_AUTHORITY, 1);
        // Inform the system that this account is eligible for auto sync
        // when the network is up
        ContentResolver.setSyncAutomatically(account, SgApp.CONTENT_AUTHORITY, true);
        // Recommend a schedule for automatic synchronization. The system
        // may modify this based
        // on other scheduled syncs and network utilization.
        ContentResolver.addPeriodicSync(account, SgApp.CONTENT_AUTHORITY, new Bundle(), SYNC_FREQUENCY);
    }
    Timber.d("Setting up account...DONE");
}
Also used : Account(android.accounts.Account) Bundle(android.os.Bundle) AccountManager(android.accounts.AccountManager)

Aggregations

Account (android.accounts.Account)548 Bundle (android.os.Bundle)108 AccountManager (android.accounts.AccountManager)78 Test (org.junit.Test)53 ArrayList (java.util.ArrayList)49 Intent (android.content.Intent)40 File (java.io.File)37 Cursor (android.database.Cursor)31 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)29 PersistableBundle (android.os.PersistableBundle)27 UserInfo (android.content.pm.UserInfo)22 MockContentResolver (android.test.mock.MockContentResolver)22 HashMap (java.util.HashMap)20 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)20 RemoteException (android.os.RemoteException)19 FileOutputStream (java.io.FileOutputStream)19 IOException (java.io.IOException)19 SmallTest (android.test.suitebuilder.annotation.SmallTest)18 HashSet (java.util.HashSet)16 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)16