Example usage for android.accounts AccountManagerFuture isDone

List of usage examples for android.accounts AccountManagerFuture isDone

Introduction

In this page you can find the example usage for android.accounts AccountManagerFuture isDone.

Prototype

boolean isDone();

Source Link

Document

Returns true if this task completed.

Usage

From source file:Main.java

private static void waitForAccountToBeRemoved(AccountManagerFuture<Boolean> removeAccount) {
    while (!removeAccount.isDone()) {
    }/*w w w.ja  v  a  2s. co  m*/
}

From source file:saschpe.birthdays.helper.AccountHelper.java

/**
 * Remove account from Android system/*from   ww  w.j  a  v a2s  .  c om*/
 */
public static boolean removeAccount(Context context) {
    Log.d(TAG, "Removing account...");
    AccountManager manager = AccountManager.get(context);
    final Account account = new Account(context.getString(R.string.app_name),
            context.getString(R.string.account_type));
    AccountManagerFuture<Boolean> future = manager.removeAccount(account, null, null);
    if (future.isDone()) {
        try {
            future.getResult();
            return true;
        } catch (Exception e) {
            Log.e(TAG, "Problem while removing account!", e);
            return false;
        }
    } else {
        return false;
    }
}

From source file:org.birthdayadapter.util.AccountHelper.java

/**
 * Remove account from Android system//from   ww  w  . jav  a2s. c o  m
 */
public boolean removeAccount() {
    Log.d(Constants.TAG, "Removing account...");

    AccountManager am = AccountManager.get(mContext);

    // remove account
    AccountManagerFuture<Boolean> future = am.removeAccount(Constants.ACCOUNT, null, null);
    if (future.isDone()) {
        try {
            future.getResult();

            return true;
        } catch (Exception e) {
            Log.e(Constants.TAG, "Problem while removing account!", e);
            return false;
        }
    } else {
        return false;
    }
}

From source file:com.owncloud.android.ui.activity.ManageAccountsActivity.java

/**
 * Callback executed after the {@link AccountManager} removed an account
 *
 * @param future    Result of the removal; future.getResult() is true if account was removed correctly.
 *///w  ww  .ja  v  a 2 s . com
@Override
public void run(AccountManagerFuture<Boolean> future) {
    if (future != null && future.isDone()) {
        Account account = new Account(mAccountBeingRemoved, MainApp.getAccountType());
        if (!AccountUtils.exists(account.name, MainApp.getAppContext())) {
            // Cancel transfers of the removed account
            if (mUploaderBinder != null) {
                mUploaderBinder.cancel(account);
            }
            if (mDownloaderBinder != null) {
                mDownloaderBinder.cancel(account);
            }
        }

        mAccountListAdapter = new AccountListAdapter(this, getAccountListItems(), mTintedCheck);
        mListView.setAdapter(mAccountListAdapter);

        AccountManager am = AccountManager.get(this);
        if (am.getAccountsByType(MainApp.getAccountType()).length == 0) {
            // Show create account screen if there isn't any account
            am.addAccount(MainApp.getAccountType(), null, null, null, this, null, null);
        } else { // at least one account left
            if (AccountUtils.getCurrentOwnCloudAccount(this) == null) {
                // current account was removed - set another as current
                String accountName = "";
                Account[] accounts = AccountManager.get(this).getAccountsByType(MainApp.getAccountType());
                if (accounts.length != 0) {
                    accountName = accounts[0].name;
                }
                AccountUtils.setCurrentOwnCloudAccount(this, accountName);
            }
        }
    }
}

From source file:eu.trentorise.smartcampus.ac.authenticator.AMSCAccessProvider.java

@Override
public String getAuthToken(Context ctx, String inAuthority)
        throws OperationCanceledException, AuthenticatorException, IOException {
    final String authority = inAuthority == null ? Constants.AUTHORITY_DEFAULT : inAuthority;
    AccountManager am = AccountManager.get(ctx);
    AccountManagerFuture<Bundle> future = am.getAuthToken(
            new Account(Constants.getAccountName(ctx), Constants.getAccountType(ctx)), authority, true, null,
            null);//from w  ww  .  java 2s.  co m
    String token = null;
    if (future.isDone()) {
        token = future.getResult().getString(AccountManager.KEY_AUTHTOKEN);
    }
    return token;
}

From source file:com.android.volley.toolbox.AndroidAuthenticator.java

@SuppressWarnings("deprecation")
@Override//from  w w  w . j av a  2 s  .c o m
public String getAuthToken() throws AuthFailureError {
    AccountManagerFuture<Bundle> future = mAccountManager.getAuthToken(mAccount, mAuthTokenType,
            mNotifyAuthFailure, null, null);
    Bundle result;
    try {
        result = future.getResult();
    } catch (Exception e) {
        throw new AuthFailureError("Error while retrieving auth token", e);
    }
    String authToken = null;
    if (future.isDone() && !future.isCancelled()) {
        if (result.containsKey(AccountManager.KEY_INTENT)) {
            Intent intent = result.getParcelable(AccountManager.KEY_INTENT);
            throw new AuthFailureError(intent);
        }
        authToken = result.getString(AccountManager.KEY_AUTHTOKEN);
    }
    if (authToken == null) {
        throw new AuthFailureError("Got null auth token for type: " + mAuthTokenType);
    }

    return authToken;
}

From source file:eu.trentorise.smartcampus.ac.authenticator.AMSCAccessProvider.java

@Override
public String getAuthToken(Context ctx, String inAuthority, IntentSender intentSender)
        throws OperationCanceledException, AuthenticatorException, IOException {
    final String authority = inAuthority == null ? Constants.AUTHORITY_DEFAULT : inAuthority;
    AccountManager am = AccountManager.get(ctx);
    AccountManagerFuture<Bundle> future = am.getAuthToken(
            new Account(Constants.getAccountName(ctx), Constants.getAccountType(ctx)), authority, false,
            new OnTokenAcquired(ctx, authority, intentSender), null);
    String token = null;/*w w  w  .j a v a2 s .c  om*/
    if (future.isDone()) {
        token = future.getResult().getString(AccountManager.KEY_AUTHTOKEN);
    }
    return token;
}