Example usage for android.accounts Account equals

List of usage examples for android.accounts Account equals

Introduction

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

Prototype

public boolean equals(Object o) 

Source Link

Usage

From source file:Main.java

/**
 * Create a account for the sync adapter.
 *
 * @param _context The application context.
 * @return the new created Account.//from w  ww  . j a  v a  2 s.  com
 */
public static Account createSyncAccount(Context _context, String _username) {
    // create a new a account.
    Account newAccount = new Account(_username, ACCOUNT_TYPE);

    AccountManager accountManager = (AccountManager) _context.getSystemService(Context.ACCOUNT_SERVICE);
    Account[] accounts = accountManager.getAccountsByType(ACCOUNT_TYPE);
    for (Account account : accounts) {
        if (account.equals(newAccount)) {
            // account already exists
            return null;
        }
    }

    // try to login and retrieve the token

    Bundle bundle = new Bundle();
    bundle.putString("Token", "some auth token please");

    if (accountManager.addAccountExplicitly(newAccount, null, bundle)) {

    } else {
        Log.i(TAG, "createSyncAccount: account already exists or an error happened");
    }

    return newAccount;
}

From source file:Main.java

/**
 * Check if the specified account exist//from   w  ww .j  ava  2s . com
 * @param context context
 * @param account account to check
 * @return <code>true</code> if account exist
 */
public static boolean isAccountExist(Context context, Account account) {
    if (account == null)
        return false;
    final AccountManager accountManager = AccountManager.get(context);
    Account[] accounts = accountManager.getAccountsByType(account.type);
    if (accounts == null || accounts.length == 0) {
        return false;
    } else {
        for (Account a : accounts) {
            if (a.equals(account))
                return true;
        }
        return false;
    }
}

From source file:com.google.android.gm.ay.java

private static boolean a(final android.accounts.Account account, final android.accounts.Account[] array) {
    final int length = array.length;
    int n = 0;/*  w  ww.  j  a v a 2 s .c  om*/
    boolean b;
    while (true) {
        b = false;
        if (n >= length) {
            break;
        }
        if (account.equals((Object) array[n])) {
            b = true;
            break;
        }
        ++n;
    }
    return b;
}

From source file:org.anhonesteffort.flock.CalendarCopyService.java

@Override
public void onCalendarCopyFailed(Exception e, Account fromAccount, Account toAccount, Long localId) {
    Log.e(TAG, "onCalendarCopyFailed() from " + fromAccount + ", " + localId + " to " + toAccount, e);

    int failedEvents = 0;
    boolean calendarWasFound = false;

    for (CalendarForCopy calendarForCopy : calendarsForCopy) {
        Account calendarAccount = calendarForCopy.fromAccount;
        Long calendarId = calendarForCopy.calendarId;
        Integer eventCount = calendarForCopy.eventCount;

        if (calendarAccount.equals(fromAccount) && calendarId.equals(localId)) {
            failedEvents = eventCount;//from   w  w  w.  j  av  a 2  s . c om
            calendarWasFound = true;
            break;
        }
    }

    if (calendarWasFound) {
        for (int i = 0; i < failedEvents; i++)
            handleEventCopyFailed(fromAccount);
    }
}

From source file:eu.e43.impeller.activity.MainActivity.java

@Override
protected void gotAccount(Account acct) {
    PreferenceManager.getDefaultSharedPreferences(this).edit().putString("lastAccount", acct.name).commit();

    getSupportActionBar().show();/*from w  w w  .ja v a2s  . c om*/

    if (m_feedFragment == null || !acct.equals(m_feedFragment.getAccount())) {
        FragmentTransaction tx = getSupportFragmentManager().beginTransaction();
        if (m_objectFragment != null) {
            tx.remove(m_objectFragment);
        }
        tx.replace(R.id.feed_fragment, new FeedFragment());
        tx.commit();
        setDisplayMode(Mode.FEED);
    } else
        setDisplayMode(m_displayMode);

    if (m_drawerFragment != null)
        m_drawerFragment.onAccountChanged(acct);

    if (m_pendingIntent) {
        onNewIntent(getIntent());
    }
}

From source file:org.anhonesteffort.flock.ContactCopyService.java

private void handleContactCopyFailed(Account fromAccount) {
    countContactCopiesFailed++;/*from  www  . j ava  2 s.  co m*/
    Log.d(TAG, "handleContactCopyFailed() contact copies failed: " + countContactCopiesFailed);

    boolean accountWasFound = false;
    for (Bundle accountError : accountErrors) {
        Account accountWithError = accountError.getParcelable(KEY_ACCOUNT_WITH_ERROR);
        Integer errorCount = accountError.getInt(KEY_ACCOUNT_ERROR_COUNT, -1);

        if (accountWithError != null && errorCount > 0) {
            if (fromAccount.equals(accountWithError)) {
                accountError.putInt(KEY_ACCOUNT_ERROR_COUNT, errorCount + 1);
                accountWasFound = true;
                break;
            }
        }
    }

    if (!accountWasFound) {
        Bundle errorBundle = new Bundle();
        errorBundle.putParcelable(KEY_ACCOUNT_WITH_ERROR, fromAccount);
        errorBundle.putInt(KEY_ACCOUNT_ERROR_COUNT, 1);

        accountErrors.add(errorBundle);
    }

    notificationBuilder
            .setContentText(getString(R.string.notification_importing_contacts_from) + " " + fromAccount.name)
            .setProgress(countContactsToCopy, countContactsCopied + countContactCopiesFailed, false);

    notifyManager.notify(1023, notificationBuilder.build());
}

From source file:org.anhonesteffort.flock.CalendarCopyService.java

private void handleEventCopyFailed(Account fromAccount) {
    countEventCopiesFailed++;//  w  w  w .j  a v  a2s  .c  o m
    Log.d(TAG, "handleEventCopyFailed() event copies failed: " + countEventCopiesFailed);

    boolean accountWasFound = false;
    for (Bundle accountError : accountErrors) {
        Account accountWithError = accountError.getParcelable(KEY_ACCOUNT_WITH_ERROR);
        Integer errorCount = accountError.getInt(KEY_ACCOUNT_ERROR_COUNT, -1);

        if (accountWithError != null && errorCount > 0) {
            if (fromAccount.equals(accountWithError)) {
                accountError.putInt(KEY_ACCOUNT_ERROR_COUNT, errorCount + 1);
                accountWasFound = true;
                break;
            }
        }
    }

    if (!accountWasFound) {
        Bundle errorBundle = new Bundle();
        errorBundle.putParcelable(KEY_ACCOUNT_WITH_ERROR, fromAccount);
        errorBundle.putInt(KEY_ACCOUNT_ERROR_COUNT, 1);

        accountErrors.add(errorBundle);
    }

    notificationBuilder
            .setContentText(getString(R.string.notification_importing_events_from) + " " + fromAccount.name)
            .setProgress(countEventsToCopy, countEventsCopied + countEventCopiesFailed, false);

    notifyManager.notify(ID_CALENDAR_COPY_NOTIFICATION, notificationBuilder.build());
}

From source file:me.philio.ghost.ui.NavigationDrawerFragment.java

/**
 * Populate the account items//from   w w  w .  j  a v a  2 s .c o  m
 */
private void populateAccountItems() {
    // Add accounts
    mAccountList.removeAllViews();
    LayoutInflater layoutInflater = getActivity().getLayoutInflater();
    for (final Account account : mAccounts) {
        if (account.equals(mSelectedAccount)) {
            continue;
        }
        View view = layoutInflater.inflate(R.layout.item_navigation_drawer_account, mAccountList, false);
        TextView titleView = (TextView) view.findViewById(R.id.txt_title);
        titleView.setText(mAccountManager.getUserData(account, AccountConstants.KEY_EMAIL));
        TextView subtitleView = (TextView) view.findViewById(R.id.txt_subtitle);
        subtitleView.setText(mAccountManager.getUserData(account, AccountConstants.KEY_BLOG_URL));
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // Change selected account
                changeAccount(account);
            }
        });
        colorView(view, false);
        mAccountList.addView(view);
    }

    // Add add account view
    View view = layoutInflater.inflate(R.layout.item_navigation_drawer_account_action, mAccountList, false);
    ImageView iconView = (ImageView) view.findViewById(R.id.img_icon);
    TextView titleView = (TextView) view.findViewById(R.id.txt_title);
    iconView.setImageResource(R.drawable.ic_action_content_add);
    titleView.setText(R.string.navigation_drawer_add_account);
    view.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mAccountManager.addAccount(getString(R.string.account_type), null, null, null, getActivity(),
                    NavigationDrawerFragment.this, null);
        }
    });
    colorView(view, false);
    mAccountList.addView(view);
}

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

/**
 * populates the avatar drawer array with the first three ownCloud {@link Account}s while the first element is
 * always the current account./*  w w w . j  a  v  a2 s  .  co  m*/
 */
private void populateDrawerOwnCloudAccounts() {
    mAccountsWithAvatars = new Account[3];
    Account[] accountsAll = AccountManager.get(this).getAccountsByType(MainApp.getAccountType());
    Account currentAccount = AccountUtils.getCurrentOwnCloudAccount(this);

    mAccountsWithAvatars[0] = currentAccount;
    int j = 0;
    for (int i = 1; i <= 2 && i < accountsAll.length && j < accountsAll.length; j++) {
        if (!currentAccount.equals(accountsAll[j])) {
            mAccountsWithAvatars[i] = accountsAll[j];
            i++;
        }
    }
}

From source file:net.sf.diningout.content.SyncAdapter.java

@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider,
        SyncResult result) {//w  w  w  .ja  v  a  2  s  .  c om
    Account selected = Accounts.selected();
    if (!account.equals(selected)) {
        if (selected != null) { // never going to sync this account that wasn't selected
            ContentResolver.setIsSyncable(account, AUTHORITY, 0);
        }
        return;
    }
    if (extras.containsKey(SYNC_EXTRAS_INITIALIZE)) {
        return; // will initialise on first normal sync
    }
    Context context = getContext();
    SharedPreferences prefs = Prefs.get(context, APP);
    try {
        if (!prefs.getBoolean(ACCOUNT_INITIALISED, false)) { // first run, log the user in
            initUser(context, provider);
        }
        if (extras.getBoolean(SYNC_EXTRAS_CONTACTS_ONLY)) {
            refreshContacts(context, provider);
            uploadContacts(context, provider);
            return;
        }
        if (!prefs.getBoolean(ONBOARDED, false)) {
            return; // don't sync yet
        }
        long now = System.currentTimeMillis(); // full upload and download daily
        boolean dailySync = now - prefs.getLong(LAST_SYNC, 0L) >= DAY_IN_MILLIS;
        if (dailySync || extras.containsKey(SYNC_EXTRAS_MANUAL)) {
            extras.putBoolean(SYNC_EXTRAS_UPLOAD, true);
            extras.putBoolean(SYNC_EXTRAS_DOWNLOAD, true);
            refreshContacts(context, provider);
        }
        if (extras.containsKey(SYNC_EXTRAS_UPLOAD) || extras.containsKey(SYNC_EXTRAS_DOWNLOAD)) {
            uploadContacts(context, provider);
            uploadRestaurants(provider);
            uploadReviews(provider);
            uploadReviewDrafts(provider);
        }
        if (extras.containsKey(SYNC_EXTRAS_DOWNLOAD)) {
            download(provider);
            prefs.edit().putLong(LAST_SYNC, now).apply();
            if (dailySync) {
                refreshRestaurants(context, provider);
                geofenceRestaurants(context, provider);
            }
            Notifications.sync(context);
        }
        if (!prefs.contains(CLOUD_ID)) { // get GCM registration ID and user notification key
            String id = uploadCloudId(context);
            if (!TextUtils.isEmpty(id)) {
                prefs.edit().putString(CLOUD_ID, id).apply();
                // todo service returns HTTP 401, probably should decouple this from cloud_id
                // String key = getCloudNotificationKey(context, selected, id);
                // if (!TextUtils.isEmpty(key)) {
                //     prefs.edit().putString(CLOUD_NOTIFICATION_KEY, key).apply();
                // }
            }
        }
    } catch (RemoteException e) {
        result.databaseError = true;
        Log.e(TAG, "syncing the ContentProvider", e);
        exception(e);
    }
}