com.google.api.client.googleapis.extensions.android2.auth.GoogleAccountManager

Here are the examples of the java api class com.google.api.client.googleapis.extensions.android2.auth.GoogleAccountManager taken from open source projects.

1. ActFmGoogleAuthActivity#onCreate()

Project: astrid
Source File: ActFmGoogleAuthActivity.java
View license
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ContextManager.setContext(this);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.gtasks_login_activity);
    TextView header = new TextView(this);
    header.setText(R.string.actfm_GAA_title);
    header.setTextAppearance(this, R.style.TextAppearance_Medium);
    header.setPadding(10, 0, 10, 50);
    getListView().addHeaderView(header);
    accountManager = new GoogleAccountManager(this);
    Account[] accounts = accountManager.getAccounts();
    ArrayList<String> accountNames = new ArrayList<String>();
    for (Account a : accounts) accountNames.add(a.name);
    nameArray = accountNames.toArray(new String[accountNames.size()]);
    setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, nameArray));
    findViewById(R.id.empty_button).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            onAuthCancel();
        }
    });
}

2. GtasksLoginActivity#onCreate()

Project: astrid
Source File: GtasksLoginActivity.java
View license
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ContextManager.setContext(this);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.gtasks_login_activity);
    TextView header = new TextView(this);
    header.setText(R.string.actfm_GAA_title);
    header.setTextAppearance(this, R.style.TextAppearance_Medium);
    header.setPadding(10, 0, 10, 50);
    getListView().addHeaderView(header);
    accountManager = new GoogleAccountManager(this);
    Account[] accounts = accountManager.getAccounts();
    ArrayList<String> accountNames = new ArrayList<String>();
    for (Account a : accounts) {
        accountNames.add(a.name);
    }
    nameArray = accountNames.toArray(new String[accountNames.size()]);
    setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, nameArray));
    findViewById(R.id.empty_button).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            onAuthCancel();
        }
    });
}

3. GtasksTokenValidator#validateAuthToken()

Project: astrid
Source File: GtasksTokenValidator.java
View license
/**
     * Invalidates and then revalidates the auth token for the currently logged in user
     * Shouldn't be called from the main thread--will block on network calls
     * @param token
     * @return valid token on success, null on failure
     */
public static synchronized String validateAuthToken(Context c, String token) throws GoogleTasksException {
    GoogleAccountManager accountManager = new GoogleAccountManager(ContextManager.getContext());
    if (testToken(token))
        return token;
    // If fail, token may have expired -- get a new one and return that
    String accountName = Preferences.getStringValue(GtasksPreferenceService.PREF_USER_NAME);
    Account a = accountManager.getAccountByName(accountName);
    if (a == null) {
        throw new GoogleTasksException(c.getString(R.string.gtasks_error_accountNotFound, accountName), "account-not-found");
    }
    for (int i = 0; i < REVALIDATION_TRIES; i++) {
        accountManager.invalidateAuthToken(token);
        // try with notify-auth-failure = false
        AccountManagerFuture<Bundle> future = accountManager.manager.getAuthToken(a, GtasksInvoker.AUTH_TOKEN_TYPE, false, null, null);
        token = getTokenFromFuture(c, future);
        if (TOKEN_INTENT_RECEIVED.equals(token))
            return null;
        else if (token != null && testToken(token))
            return token;
    }
    throw new GoogleTasksException(c.getString(R.string.gtasks_error_authRefresh), "auth-token-refresh");
}

4. GtasksNewSyncTest#initializeTestService()

Project: astrid
Source File: GtasksNewSyncTest.java
View license
private void initializeTestService() throws Exception {
    GoogleAccountManager manager = new GoogleAccountManager(ContextManager.getContext());
    Account[] accounts = manager.getAccounts();
    Account toUse = null;
    for (Account a : accounts) {
        if (a.name.equals(TEST_ACCOUNT)) {
            toUse = a;
            break;
        }
    }
    if (toUse == null) {
        if (accounts.length == 0) {
            bypassTests = true;
            return;
        }
        toUse = accounts[0];
    }
    Preferences.setString(GtasksPreferenceService.PREF_USER_NAME, toUse.name);
    AccountManagerFuture<Bundle> accountManagerFuture = manager.manager.getAuthToken(toUse, "oauth2:https://www.googleapis.com/auth/tasks", true, null, null);
    Bundle authTokenBundle = accountManagerFuture.getResult();
    if (authTokenBundle.containsKey(AccountManager.KEY_INTENT)) {
        Intent i = (Intent) authTokenBundle.get(AccountManager.KEY_INTENT);
        ContextManager.getContext().startActivity(i);
        return;
    }
    String authToken = authTokenBundle.getString(AccountManager.KEY_AUTHTOKEN);
    authToken = GtasksTokenValidator.validateAuthToken(getContext(), authToken);
    gtasksPreferenceService.setToken(authToken);
    gtasksService = new GtasksInvoker(authToken);
    initialized = true;
}

5. GtasksSyncOnSaveTest#initializeTestService()

Project: astrid
Source File: GtasksSyncOnSaveTest.java
View license
private void initializeTestService() throws Exception {
    GoogleAccountManager manager = new GoogleAccountManager(ContextManager.getContext());
    Account[] accounts = manager.getAccounts();
    Account toUse = null;
    for (Account a : accounts) {
        if (a.name.equals(TEST_ACCOUNT)) {
            toUse = a;
            break;
        }
    }
    if (toUse == null) {
        if (accounts.length == 0) {
            bypassTests = true;
            return;
        }
        toUse = accounts[0];
    }
    Preferences.setString(GtasksPreferenceService.PREF_USER_NAME, toUse.name);
    AccountManagerFuture<Bundle> accountManagerFuture = manager.manager.getAuthToken(toUse, "oauth2:https://www.googleapis.com/auth/tasks", true, null, null);
    Bundle authTokenBundle = accountManagerFuture.getResult();
    if (authTokenBundle.containsKey(AccountManager.KEY_INTENT)) {
        Intent i = (Intent) authTokenBundle.get(AccountManager.KEY_INTENT);
        ContextManager.getContext().startActivity(i);
        return;
    }
    String authToken = authTokenBundle.getString(AccountManager.KEY_AUTHTOKEN);
    authToken = GtasksTokenValidator.validateAuthToken(getContext(), authToken);
    gtasksPreferenceService.setToken(authToken);
    gtasksService = new GtasksInvoker(authToken);
    initialized = true;
}

6. RepeatTestsGtasksSync#initializeTestService()

Project: astrid
Source File: RepeatTestsGtasksSync.java
View license
private void initializeTestService() throws Exception {
    GoogleAccountManager manager = new GoogleAccountManager(ContextManager.getContext());
    Account[] accounts = manager.getAccounts();
    Account toUse = null;
    for (Account a : accounts) {
        if (a.name.equals(TEST_ACCOUNT)) {
            toUse = a;
            break;
        }
    }
    if (toUse == null) {
        if (accounts.length == 0) {
            return;
        }
        toUse = accounts[0];
    }
    Preferences.setString(GtasksPreferenceService.PREF_USER_NAME, toUse.name);
    AccountManagerFuture<Bundle> accountManagerFuture = manager.manager.getAuthToken(toUse, "oauth2:https://www.googleapis.com/auth/tasks", true, null, null);
    Bundle authTokenBundle = accountManagerFuture.getResult();
    if (authTokenBundle.containsKey(AccountManager.KEY_INTENT)) {
        Intent i = (Intent) authTokenBundle.get(AccountManager.KEY_INTENT);
        ContextManager.getContext().startActivity(i);
        return;
    }
    String authToken = authTokenBundle.getString(AccountManager.KEY_AUTHTOKEN);
    authToken = GtasksTokenValidator.validateAuthToken(getContext(), authToken);
    gtasksPreferenceService.setToken(authToken);
    gtasksService = new GtasksInvoker(authToken);
    initialized = true;
}