Example usage for android.accounts Account Account

List of usage examples for android.accounts Account Account

Introduction

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

Prototype

public Account(@NonNull Account other, @NonNull String accessId) 

Source Link

Usage

From source file:com.skubit.android.transactions.TransactionsFragment.java

public void getTransactions() {
    String account = mAccountSettings.retrieveBitIdAccount();
    if (!TextUtils.isEmpty(account)) {
        mTransactionService = new TransactionService(new Account(account, "com.google"), getActivity());
        refreshBalance();//from  w w w.  ja  va2 s .c o m
    } else {
        return;
    }

    mTransactionService.getRestService().getTransactions(500, 0, null, new Callback<TransactionsListDto>() {

        @Override
        public void failure(RetrofitError error) {
            error.printStackTrace();
        }

        @Override
        public void success(TransactionsListDto dto, Response response) {
            mAdapter.clear();
            mAdapter.addTransactions(dto.getItems());
        }

    });
}

From source file:org.ohmage.auth.AuthenticatorTest.java

@Override
public void setUp() throws Exception {
    super.setUp();

    fakeAccount = new Account("name", AuthUtil.AUTHTOKEN_TYPE);
    token = new AccessToken(accessToken, refreshToken, fakeAccount.name);

    fakeContext = mock(Context.class);

    mAuthenticator = new Authenticator(fakeContext);
}

From source file:com.browsertophone.AppEngineClient.java

private HttpResponse makeRequestNoRetry(String urlPath, List<NameValuePair> params, boolean newToken)
        throws Exception {

    // Get auth token for account
    Account account = new Account(mAccountName, "com.google");
    String authToken = getAuthToken(mContext, account);
    if (authToken == null)
        throw new PendingAuthException(mAccountName);
    if (newToken) { // invalidate the cached token
        AccountManager accountManager = AccountManager.get(mContext);
        accountManager.invalidateAuthToken(account.type, authToken);
        authToken = getAuthToken(mContext, account);
    }/*from  w  w  w  .  jav  a  2 s.co m*/

    // Get ACSID cookie
    DefaultHttpClient client = new DefaultHttpClient();
    String continueURL = BASE_URL;
    URI uri = new URI(AUTH_URL + "?continue=" + URLEncoder.encode(continueURL, "UTF-8") + "&auth=" + authToken);
    HttpGet method = new HttpGet(uri);
    final HttpParams getParams = new BasicHttpParams();
    HttpClientParams.setRedirecting(getParams, false); // continue is not used
    method.setParams(getParams);

    HttpResponse res = client.execute(method);
    Header[] headers = res.getHeaders("Set-Cookie");
    if (res.getStatusLine().getStatusCode() != 302 || headers.length == 0) {
        return res;
    }

    String ascidCookie = null;
    for (Header header : headers) {
        if (header.getValue().indexOf("ACSID=") >= 0) {
            // let's parse it
            String value = header.getValue();
            String[] pairs = value.split(";");
            ascidCookie = pairs[0];
        }
    }

    // Make POST request
    uri = new URI(BASE_URL + urlPath);
    HttpPost post = new HttpPost(uri);
    UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF-8");
    post.setEntity(entity);
    post.setHeader("Cookie", ascidCookie);
    post.setHeader("X-Same-Domain", "1"); // XSRF
    res = client.execute(post);
    return res;
}

From source file:com.menumomma.chrome2phone.AppEngineClient.java

private HttpResponse makeRequestNoRetry(String urlPath, List<NameValuePair> params, boolean newToken)
        throws Exception {
    // Get auth token for account
    Account account = new Account(mAccountName, "com.google");
    String authToken = getAuthToken(mContext, account);

    if (newToken) { // invalidate the cached token
        AccountManager accountManager = AccountManager.get(mContext);
        accountManager.invalidateAuthToken(account.type, authToken);
        authToken = getAuthToken(mContext, account);
    }/*from   w  ww  .  j  a v  a 2  s.  com*/

    // Get ACSID cookie
    DefaultHttpClient client = new DefaultHttpClient();
    String continueURL = Config.BASE_URL;
    URI uri = new URI(AUTH_URL + "?continue=" + URLEncoder.encode(continueURL, "UTF-8") + "&auth=" + authToken);
    HttpGet method = new HttpGet(uri);
    final HttpParams getParams = new BasicHttpParams();
    HttpClientParams.setRedirecting(getParams, false); // continue is not used
    method.setParams(getParams);

    HttpResponse res = client.execute(method);
    Header[] headers = res.getHeaders("Set-Cookie");
    if (res.getStatusLine().getStatusCode() != 302 || headers.length == 0) {
        return res;
    }

    String ascidCookie = null;
    for (Header header : headers) {
        if (header.getValue().indexOf("ACSID=") >= 0) {
            // let's parse it
            String value = header.getValue();
            String[] pairs = value.split(";");
            ascidCookie = pairs[0];
        }
    }

    // Make POST request
    uri = new URI(Config.BASE_URL + urlPath);
    HttpPost post = new HttpPost(uri);
    UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF-8");
    post.setEntity(entity);
    post.setHeader("Cookie", ascidCookie);
    post.setHeader("X-Same-Domain", "1"); // XSRF
    res = client.execute(post);
    return res;
}

From source file:com.agiro.scanner.android.AppEngineClient.java

private HttpResponse makeRequestNoRetry(String urlPath, List<NameValuePair> params, boolean newToken)
        throws Exception {

    // Get auth token for account
    Account account = new Account(mAccountName, "com.google");
    //        String authToken = getAuthToken(mContext, account);
    //        if (authToken == null) throw new PendingAuthException(mAccountName);
    //        if (newToken) {  // invalidate the cached token
    //            AccountManager accountManager = AccountManager.get(mContext);
    //            accountManager.invalidateAuthToken(account.type, authToken);
    //            authToken = getAuthToken(mContext, account);
    //        }/*from   w w  w. j a v a 2 s  .  co  m*/
    String authToken = "";
    // Get ACSID cookie
    DefaultHttpClient client = new DefaultHttpClient();
    String continueURL = BASE_URL;
    URI uri = new URI(AUTH_URL + "?continue=" + URLEncoder.encode(continueURL, "UTF-8") + "&auth=" + authToken);
    HttpPost method = new HttpPost(uri);
    final HttpParams getParams = new BasicHttpParams();
    HttpClientParams.setRedirecting(getParams, false); // continue is not used
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
    nameValuePairs.add(new BasicNameValuePair("email", mAccountName));
    nameValuePairs.add(new BasicNameValuePair("action", "Log+In"));
    method.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    method.setParams(getParams);

    HttpResponse res = client.execute(method);
    Header[] headers = res.getHeaders("Set-Cookie");
    if (res.getStatusLine().getStatusCode() != 302 || headers.length == 0) {
        return res;
    }

    String ascidCookie = null;
    for (Header header : headers) {
        if (header.getValue().indexOf("ACSID=") >= 0) {
            // let's parse it
            String value = header.getValue();
            String[] pairs = value.split(";");
            ascidCookie = pairs[0];
        }
    }

    // Make POST request
    uri = new URI(BASE_URL + urlPath);
    Log.e(TAG, "" + uri.toString());
    HttpPost post = new HttpPost(uri);
    UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF-8");
    post.setEntity(entity);
    post.setHeader("Cookie", ascidCookie);
    post.setHeader("X-Same-Domain", "1"); // XSRF
    res = client.execute(post);
    return res;
}

From source file:saschpe.birthdays.service.loader.ContactAccountListLoader.java

@Override
public List<AccountModel> loadInBackground() {
    if (!AccountHelper.isAccountActivated(getContext())) {
        AccountHelper.addAccount(getContext());
    }//from   ww  w  .  jav  a  2  s  . c o m

    // Retrieve all accounts that are actively used for contacts
    HashSet<Account> contactAccounts = new HashSet<>();
    Cursor cursor = null;
    try {
        cursor = getContext().getContentResolver()
                .query(ContactsContract.RawContacts.CONTENT_URI, new String[] {
                        ContactsContract.RawContacts.ACCOUNT_NAME, ContactsContract.RawContacts.ACCOUNT_TYPE },
                        null, null, null);

        while (cursor.moveToNext()) {
            String account_name = cursor
                    .getString(cursor.getColumnIndex(ContactsContract.RawContacts.ACCOUNT_NAME));
            String account_type = cursor
                    .getString(cursor.getColumnIndex(ContactsContract.RawContacts.ACCOUNT_TYPE));
            Account account = new Account(account_name, account_type);
            contactAccounts.add(account);
        }
    } catch (Exception e) {
        Log.e(TAG, "Error retrieving accounts", e);
    } finally {
        if (cursor != null && !cursor.isClosed()) {
            cursor.close();
        }
    }

    List<Account> accountBlacklist = AccountProviderHelper.getAccountList(getContext());
    Log.d(TAG, "Stored account list: " + accountBlacklist);

    AccountManager manager = AccountManager.get(getContext());
    AuthenticatorDescription[] descriptions = manager.getAuthenticatorTypes();

    ArrayList<AccountModel> items = new ArrayList<>();
    for (Account account : contactAccounts) {
        for (AuthenticatorDescription description : descriptions) {
            if (description.type.equals(account.type)) {
                boolean disabled = accountBlacklist.contains(account);
                items.add(new AccountModel(getContext(), account, description, !disabled));
            }
        }
    }

    // Sort the list
    Collections.sort(items, ALPHA_COMPARATOR);

    return items;
}

From source file:com.ntsync.android.sync.shared.SyncUtils.java

/**
 * Check if a Sync is active/*from   www . j  ava 2 s. c o m*/
 * 
 * @param accountName
 * @return true if a Sync is active with the current Account Name
 */
public static boolean isSyncActive(String accountName) {
    Account account = new Account(accountName, Constants.ACCOUNT_TYPE);
    return ContentResolver.isSyncActive(account, ContactsContract.AUTHORITY);
}

From source file:inforuh.eventfinder.sync.SyncAdapter.java

public static Account getAccount(Context context) {
    AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);

    Account account = new Account(context.getString(R.string.app_name),
            context.getString(R.string.account_type));

    if (accountManager.getPassword(account) == null) {
        accountManager.addAccountExplicitly(account, "", null);
        onAccountCreated(account, context);
    }//from www.j  av  a2s  . c  o  m
    return account;
}

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

/**
 * Remove account from Android system//from  w  w w  .  j a  va 2  s . com
 */
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.ohmage.sync.StreamSyncAdapterTest.java

@Override
public void setUp() throws Exception {
    super.setUp();

    fakeContext = mock(Context.class);
    fakeContentProviderClient = mock(ContentProviderClient.class);
    fakeAccount = spy(new Account("name", AuthUtil.AUTHTOKEN_TYPE));
    fakeWriter = mock(StreamWriterOutput.class);
    fakeSyncResult = new SyncResult();

    mSyncAdapter = new StreamSyncAdapter(fakeContext, false, false);
}