Search in sources :

Example 36 with Account

use of android.accounts.Account in project iosched by google.

the class TriggerSyncReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    String accountName = AccountUtils.getActiveAccountName(context);
    if (TextUtils.isEmpty(accountName)) {
        return;
    }
    Account account = AccountUtils.getActiveAccount(context);
    if (account != null) {
        if (intent.getBooleanExtra(EXTRA_USER_DATA_SYNC_ONLY, false)) {
            // this is a request to sync user data only, so do a manual sync right now
            // with the userDataOnly == true.
            SyncHelper.requestManualSync(true);
        } else {
            // this is a request to sync everything
            ContentResolver.requestSync(account, ScheduleContract.CONTENT_AUTHORITY, new Bundle());
        }
    }
}
Also used : Account(android.accounts.Account) Bundle(android.os.Bundle)

Example 37 with Account

use of android.accounts.Account in project robolectric by robolectric.

the class ShadowParcelTest method testReadWriteParcelable.

@Test
public void testReadWriteParcelable() {
    Account a1 = new Account("name", "type");
    parcel.writeParcelable(a1, 0);
    parcel.setDataPosition(0);
    Account a2 = parcel.readParcelable(Account.class.getClassLoader());
    assertEquals(a1, a2);
}
Also used : Account(android.accounts.Account) Test(org.junit.Test)

Example 38 with Account

use of android.accounts.Account in project android-delicious by lexs.

the class DeliciousAccount method create.

public static DeliciousAccount create(Context context, String username, String password) {
    AccountManager accountManager = AccountManager.get(context.getApplicationContext());
    Account account = new Account(username, Constants.ACCOUNT_TYPE);
    DeliciousAccount deliciousAccount = new DeliciousAccount(context, accountManager, account);
    accountManager.addAccountExplicitly(account, deliciousAccount.encryptPassword(password), null);
    return deliciousAccount;
}
Also used : Account(android.accounts.Account) AccountManager(android.accounts.AccountManager)

Example 39 with Account

use of android.accounts.Account in project Android-AccountChooser by frakbot.

the class ChooseAccountActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mAccounts = getIntent().getParcelableArrayExtra(AccountManager.KEY_ACCOUNTS);
    mAccountManagerResponse = getIntent().getParcelableExtra(AccountManager.KEY_ACCOUNT_MANAGER_RESPONSE);
    // KEY_ACCOUNTS is a required parameter
    if (mAccounts == null) {
        setResult(RESULT_CANCELED);
        finish();
        return;
    }
    getAuthDescriptions();
    AccountInfo[] mAccountInfos = new AccountInfo[mAccounts.length];
    for (int i = 0; i < mAccounts.length; i++) {
        mAccountInfos[i] = new AccountInfo(((Account) mAccounts[i]).name, getDrawableForType(((Account) mAccounts[i]).type));
    }
    setContentView(R.layout.choose_account);
    // Setup the list
    ListView list = (ListView) findViewById(android.R.id.list);
    // Use an existing ListAdapter that will map an array of strings to TextViews
    list.setAdapter(new AccountArrayAdapter(this, android.R.layout.simple_list_item_1, mAccountInfos));
    list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    list.setTextFilterEnabled(true);
    list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            onListItemClick((ListView) parent, v, position, id);
        }
    });
}
Also used : Account(android.accounts.Account) ListView(android.widget.ListView) AdapterView(android.widget.AdapterView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView)

Example 40 with Account

use of android.accounts.Account in project Android-AccountChooser by frakbot.

the class ChooseTypeAndAccountActivity method onActivityResult.

// Called when the choose account type activity (for adding an account) returns.
// If it was a success read the account and set it in the result. In all cases
// return the result and finish this activity.
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    if (Log.isLoggable(TAG, Log.VERBOSE)) {
        if (data != null && data.getExtras() != null)
            data.getExtras().keySet();
        Bundle extras = data != null ? data.getExtras() : null;
        Log.v(TAG, "ChooseTypeAndAccountActivity.onActivityResult(reqCode=" + requestCode + ", resCode=" + resultCode + ", extras=" + extras + ")");
    }
    // we got our result, so clear the fact that we had a pending request
    mPendingRequest = REQUEST_NULL;
    if (resultCode == RESULT_CANCELED) {
        // finish this activity
        if (mAccounts.isEmpty()) {
            setResult(Activity.RESULT_CANCELED);
            finish();
        }
        return;
    }
    if (resultCode == RESULT_OK) {
        if (requestCode == REQUEST_CHOOSE_TYPE) {
            if (data != null) {
                String accountType = data.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE);
                if (accountType != null) {
                    runAddAccountForAuthenticator(accountType);
                    return;
                }
            }
            Log.d(TAG, "ChooseTypeAndAccountActivity.onActivityResult: unable to find account " + "type, pretending the request was canceled");
        } else if (requestCode == REQUEST_ADD_ACCOUNT) {
            String accountName = null;
            String accountType = null;
            if (data != null) {
                accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
                accountType = data.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE);
            }
            if (accountName == null || accountType == null) {
                Account[] currentAccounts = AccountManager.get(this).getAccounts();
                Set<Account> preExistingAccounts = new HashSet<Account>();
                for (Parcelable accountParcel : mExistingAccounts) {
                    preExistingAccounts.add((Account) accountParcel);
                }
                for (Account account : currentAccounts) {
                    if (!preExistingAccounts.contains(account)) {
                        accountName = account.name;
                        accountType = account.type;
                        break;
                    }
                }
            }
            if (accountName != null || accountType != null) {
                setResultAndFinish(accountName, accountType);
                return;
            }
        }
        Log.d(TAG, "ChooseTypeAndAccountActivity.onActivityResult: unable to find added " + "account, pretending the request was canceled");
    }
    if (Log.isLoggable(TAG, Log.VERBOSE)) {
        Log.v(TAG, "ChooseTypeAndAccountActivity.onActivityResult: canceled");
    }
    setResult(Activity.RESULT_CANCELED);
    finish();
}
Also used : Account(android.accounts.Account) Set(java.util.Set) HashSet(java.util.HashSet) Bundle(android.os.Bundle) Parcelable(android.os.Parcelable)

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