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());
}
}
}
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);
}
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;
}
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);
}
});
}
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();
}
Aggregations