Search in sources :

Example 86 with Account

use of android.accounts.Account in project philm by chrisbanes.

the class AndroidAccountManager method getAccounts.

@Override
public List<PhilmAccount> getAccounts() {
    final Account[] accounts = mAccountManager.getAccountsByType(Constants.TRAKT_ACCOUNT_TYPE);
    ArrayList<PhilmAccount> philmAccounts = new ArrayList<>(accounts.length);
    for (int i = 0; i < accounts.length; i++) {
        final Account account = accounts[i];
        String password = mAccountManager.getPassword(account);
        philmAccounts.add(new PhilmAccount(account.name, password));
    }
    return philmAccounts;
}
Also used : Account(android.accounts.Account) PhilmAccount(app.philm.in.model.PhilmAccount) ArrayList(java.util.ArrayList) PhilmAccount(app.philm.in.model.PhilmAccount)

Example 87 with Account

use of android.accounts.Account in project materialistic by hidroh.

the class DrawerActivityLoginTest method testRemoveAccount.

@Config(sdk = 21)
@Test
public void testRemoveAccount() {
    ShadowAccountManager.get(activity).addAccountExplicitly(new Account("existing", BuildConfig.APPLICATION_ID), "password", null);
    Preferences.setUsername(activity, "existing");
    drawerAccount.performClick();
    AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
    assertNotNull(alertDialog);
    assertThat(alertDialog.getListView().getAdapter()).hasCount(1);
    alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL).performClick();
    assertThat(alertDialog).isNotShowing();
    assertThat(ShadowAccountManager.get(activity).getAccounts()).isEmpty();
}
Also used : AlertDialog(android.app.AlertDialog) ShadowAlertDialog(org.robolectric.shadows.ShadowAlertDialog) Account(android.accounts.Account) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 88 with Account

use of android.accounts.Account in project materialistic by hidroh.

the class DrawerActivityLoginTest method testExistingAccount.

@Test
public void testExistingAccount() {
    ShadowAccountManager.get(activity).addAccountExplicitly(new Account("existing", BuildConfig.APPLICATION_ID), "password", null);
    drawerAccount.performClick();
    AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
    assertNotNull(alertDialog);
    assertThat(alertDialog.getListView().getAdapter()).hasCount(1);
    shadowOf(alertDialog).clickOnItem(0);
    alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
    assertThat(alertDialog).isNotShowing();
    assertThat(drawerAccount).hasText("existing");
    assertThat(drawerLogout).isVisible();
    drawerAccount.performClick();
    alertDialog = ShadowAlertDialog.getLatestAlertDialog();
    assertThat(alertDialog.getListView().getAdapter()).hasCount(1);
}
Also used : AlertDialog(android.app.AlertDialog) ShadowAlertDialog(org.robolectric.shadows.ShadowAlertDialog) Account(android.accounts.Account) Test(org.junit.Test)

Example 89 with Account

use of android.accounts.Account in project materialistic by hidroh.

the class DrawerActivityLoginTest method testAddAccount.

@Test
public void testAddAccount() {
    ShadowAccountManager.get(activity).addAccountExplicitly(new Account("existing", BuildConfig.APPLICATION_ID), "password", null);
    drawerAccount.performClick();
    AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
    assertNotNull(alertDialog);
    assertThat(alertDialog.getListView().getAdapter()).hasCount(1);
    alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).performClick();
    assertThat(alertDialog).isNotShowing();
    ((ShadowSupportDrawerLayout) ShadowExtractor.extract(activity.findViewById(R.id.drawer_layout))).getDrawerListeners().get(0).onDrawerClosed(activity.findViewById(R.id.drawer));
    assertThat(shadowOf(activity).getNextStartedActivity()).hasComponent(activity, LoginActivity.class);
}
Also used : AlertDialog(android.app.AlertDialog) ShadowAlertDialog(org.robolectric.shadows.ShadowAlertDialog) ShadowSupportDrawerLayout(io.github.hidroh.materialistic.test.shadow.ShadowSupportDrawerLayout) Account(android.accounts.Account) Test(org.junit.Test)

Example 90 with Account

use of android.accounts.Account in project QuantumFlux by himanshu-soni.

the class SyncUtils method createSyncAccount.

/**
     * Create a new dummy account for the sync adapter
     *
     * @param context The application context
     */
public static Account createSyncAccount(Context context, String name) {
    // Create the account type and default account
    Account newAccount = new Account(name, ACCOUNT_TYPE);
    // Get an instance of the Android account manager
    AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
    /*
         * Add the account and account type, no password or user data
         * If successful, return the Account object, otherwise report an error.
         */
    if (accountManager.addAccountExplicitly(newAccount, null, null)) {
    /*
             * If you don't set android:syncable="true" in
             * in your <provider> element in the manifest,
             * then call context.setIsSyncable(account, CONTENT_AUTHORITY, 1)
             * here.
             */
    // Turn on automatic syncing for the default account and authority
    //            mResolver.setSyncAutomatically(newAccount, SyncConstants.AUTHORITY, true);
    } else {
    /*
             * The account exists or some other error occurred. Log this, report it,
             * or handle it internally.
             */
    }
    return newAccount;
}
Also used : Account(android.accounts.Account) AccountManager(android.accounts.AccountManager)

Aggregations

Account (android.accounts.Account)550 Bundle (android.os.Bundle)108 AccountManager (android.accounts.AccountManager)79 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