Example usage for android.accounts Account hashCode

List of usage examples for android.accounts Account hashCode

Introduction

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

Prototype

public int hashCode() 

Source Link

Usage

From source file:eu.masconsult.bgbanking.activity.fragment.AccountsListFragment.java

private void addAccount(Bank bank, Account account, boolean sample) {
    View header = getActivity().getLayoutInflater().inflate(R.layout.row_bank_account_header, null);
    View bank_icon = header.findViewById(R.id.bank_icon);
    if (bank_icon != null && bank_icon instanceof ImageView) {
        ((ImageView) bank_icon).setImageResource(bank.iconResource);
    }/* w w  w .  ja v a  2 s.c  o  m*/
    View bank_name = header.findViewById(R.id.bank_name);
    if (bank_name != null && bank_name instanceof TextView) {
        ((TextView) bank_name).setText(bank.labelRes);
    }
    View account_name = header.findViewById(R.id.account_name);
    if (account_name != null && account_name instanceof TextView) {
        ((TextView) account_name).setText(account.name);
    }
    mAdapter.addView(header);
    BankAccountsAdapter adapter = new BankAccountsAdapter(getActivity(), R.layout.row_bank_account, null, 0);
    EmptyBankAccountsAdapter adapter2 = new EmptyBankAccountsAdapter(getActivity(), account, adapter);
    adapters.put(account.hashCode(), adapter);
    mAdapter.addAdapter(adapter2);

    accounts.put(account.hashCode(), account);
    if (sample) {
        Log.d(TAG, "Adding sample account cursor");
        adapter.swapCursor(new SampleCursor(getActivity()));
    } else {
        Log.d(TAG, String.format("Requesting loader %d", account.hashCode()));
        getLoaderManager().initLoader(account.hashCode(), null, this);
    }
}

From source file:org.tigase.messenger.phone.pro.service.XMPPService.java

private final void updateJaxmppInstances() {
    final HashSet<BareJID> accountsJids = new HashSet<BareJID>();
    for (JaxmppCore jaxmpp : multiJaxmpp.get()) {
        accountsJids.add(jaxmpp.getSessionObject().getUserBareJid());
    }/* w  ww .  ja  v  a  2 s . c  o  m*/

    final AccountManager am = AccountManager.get(this);
    for (Account account : am.getAccountsByType(Authenticator.ACCOUNT_TYPE)) {
        BareJID accountJid = BareJID.bareJIDInstance(account.name);
        Jaxmpp jaxmpp = multiJaxmpp.get(accountJid);
        if (jaxmpp == null) {
            jaxmpp = createJaxmpp(accountJid, account.hashCode());
            multiJaxmpp.add(jaxmpp);
        }

        // workaround for unknown certificate error
        jaxmpp.getSessionObject().setProperty("jaxmpp#ThrowedException", null);

        String password = am.getPassword(account);
        String nickname = am.getUserData(account, AccountsConstants.FIELD_NICKNAME);
        String hostname = am.getUserData(account, AccountsConstants.FIELD_HOSTNAME);
        String resource = am.getUserData(account, AccountsConstants.FIELD_RESOURCE);
        hostname = hostname == null ? null : hostname.trim();

        jaxmpp.getSessionObject().setUserProperty(SessionObject.PASSWORD, password);
        jaxmpp.getSessionObject().setUserProperty(SessionObject.NICKNAME, nickname);
        if (hostname != null && TextUtils.isEmpty(hostname))
            hostname = null;
        // sessionObject.setUserProperty(SessionObject.DOMAIN_NAME,
        // hostname);
        if (TextUtils.isEmpty(resource))
            resource = null;
        jaxmpp.getSessionObject().setUserProperty(SessionObject.RESOURCE, resource);

        MobileModeFeature.updateSettings(account, jaxmpp, this);

        boolean disabled = !Boolean.parseBoolean(am.getUserData(account, AccountsConstants.FIELD_ACTIVE));
        jaxmpp.getSessionObject().setUserProperty("CC:DISABLED", disabled);

        if (disabled) {
            if (jaxmpp.isConnected()) {
                this.disconnectJaxmpp(jaxmpp, true);
            }
        } else {
            if (!jaxmpp.isConnected()) {
                this.connectJaxmpp(jaxmpp, 1L);
            }
        }

        accountsJids.remove(accountJid);
    }

    for (BareJID accountJid : accountsJids) {
        final Jaxmpp jaxmpp = multiJaxmpp.get(accountJid);
        if (jaxmpp != null) {
            multiJaxmpp.remove(jaxmpp);
            (new AsyncTask<Void, Void, Void>() {
                @Override
                protected Void doInBackground(Void... params) {
                    try {
                        jaxmpp.disconnect();
                        // clear presences for account?
                        // app.clearPresences(jaxmpp.getSessionObject(),
                        // false);
                        // is this needed any more??
                        // JaxmppService.this.rosterProvider.resetStatus(jaxmpp.getSessionObject());
                    } catch (Exception ex) {
                        Log.e(TAG, "Can't disconnect", ex);
                    }

                    return null;
                }
            }).execute();
        }
    }

    dataRemover.removeUnusedData(this);
}