Search in sources :

Example 1 with AccountPreference

use of com.android.settings.AccountPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ManageAccountsSettings method showAccountsIfNeeded.

private void showAccountsIfNeeded() {
    if (getActivity() == null)
        return;
    Account[] accounts = AccountManager.get(getActivity()).getAccountsAsUser(mUserHandle.getIdentifier());
    getPreferenceScreen().removeAll();
    mFirstAccount = null;
    addPreferencesFromResource(R.xml.manage_accounts_settings);
    for (int i = 0, n = accounts.length; i < n; i++) {
        final Account account = accounts[i];
        if (!Utils.showAccount(getActivity(), account.type)) {
            // If needn't to show the account, skip this account.
            continue;
        }
        // If an account type is specified for this screen, skip other types
        if (mAccountType != null && !account.type.equals(mAccountType))
            continue;
        final ArrayList<String> auths = getAuthoritiesForAccountType(account.type);
        boolean showAccount = true;
        if (mAuthorities != null && auths != null) {
            showAccount = false;
            for (String requestedAuthority : mAuthorities) {
                if (auths.contains(requestedAuthority)) {
                    showAccount = true;
                    break;
                }
            }
        }
        if (showAccount) {
            final Drawable icon = getDrawableForType(account.type);
            final AccountPreference preference = new AccountPreference(getPrefContext(), account, icon, auths, false);
            getPreferenceScreen().addPreference(preference);
            if (mFirstAccount == null) {
                mFirstAccount = account;
            }
        }
    }
    if (mAccountType != null && mFirstAccount != null) {
        addAuthenticatorSettings();
    } else {
        // There's no account, close activity
        finish();
    }
}
Also used : Account(android.accounts.Account) Drawable(android.graphics.drawable.Drawable) AccountPreference(com.android.settings.AccountPreference)

Example 2 with AccountPreference

use of com.android.settings.AccountPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ManageAccountsSettings method requestOrCancelSyncForAccounts.

private void requestOrCancelSyncForAccounts(boolean sync) {
    final int userId = mUserHandle.getIdentifier();
    SyncAdapterType[] syncAdapters = ContentResolver.getSyncAdapterTypesAsUser(userId);
    Bundle extras = new Bundle();
    extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
    int count = getPreferenceScreen().getPreferenceCount();
    // For each account
    for (int i = 0; i < count; i++) {
        Preference pref = getPreferenceScreen().getPreference(i);
        if (pref instanceof AccountPreference) {
            Account account = ((AccountPreference) pref).getAccount();
            // For all available sync authorities, sync those that are enabled for the account
            for (int j = 0; j < syncAdapters.length; j++) {
                SyncAdapterType sa = syncAdapters[j];
                if (syncAdapters[j].accountType.equals(mAccountType) && ContentResolver.getSyncAutomaticallyAsUser(account, sa.authority, userId)) {
                    if (sync) {
                        ContentResolver.requestSyncAsUser(account, sa.authority, userId, extras);
                    } else {
                        ContentResolver.cancelSyncAsUser(account, sa.authority, userId);
                    }
                }
            }
        }
    }
}
Also used : Account(android.accounts.Account) AccountPreference(com.android.settings.AccountPreference) Preference(android.support.v7.preference.Preference) Bundle(android.os.Bundle) SyncAdapterType(android.content.SyncAdapterType) AccountPreference(com.android.settings.AccountPreference)

Example 3 with AccountPreference

use of com.android.settings.AccountPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ManageAccountsSettings method showSyncState.

/**
     * Shows the sync state of the accounts. Note: it must be called after the accounts have been
     * loaded, @see #showAccountsIfNeeded().
     */
private void showSyncState() {
    // Catch any delayed delivery of update messages
    if (getActivity() == null || getActivity().isFinishing())
        return;
    final int userId = mUserHandle.getIdentifier();
    // iterate over all the preferences, setting the state properly for each
    List<SyncInfo> currentSyncs = ContentResolver.getCurrentSyncsAsUser(userId);
    // true if sync on any account failed
    boolean anySyncFailed = false;
    Date date = new Date();
    // only track userfacing sync adapters when deciding if account is synced or not
    final SyncAdapterType[] syncAdapters = ContentResolver.getSyncAdapterTypesAsUser(userId);
    HashSet<String> userFacing = new HashSet<String>();
    for (int k = 0, n = syncAdapters.length; k < n; k++) {
        final SyncAdapterType sa = syncAdapters[k];
        if (sa.isUserVisible()) {
            userFacing.add(sa.authority);
        }
    }
    for (int i = 0, count = getPreferenceScreen().getPreferenceCount(); i < count; i++) {
        Preference pref = getPreferenceScreen().getPreference(i);
        if (!(pref instanceof AccountPreference)) {
            continue;
        }
        AccountPreference accountPref = (AccountPreference) pref;
        Account account = accountPref.getAccount();
        int syncCount = 0;
        long lastSuccessTime = 0;
        boolean syncIsFailing = false;
        final ArrayList<String> authorities = accountPref.getAuthorities();
        boolean syncingNow = false;
        if (authorities != null) {
            for (String authority : authorities) {
                SyncStatusInfo status = ContentResolver.getSyncStatusAsUser(account, authority, userId);
                boolean syncEnabled = isSyncEnabled(userId, account, authority);
                boolean authorityIsPending = ContentResolver.isSyncPending(account, authority);
                boolean activelySyncing = isSyncing(currentSyncs, account, authority);
                boolean lastSyncFailed = status != null && syncEnabled && status.lastFailureTime != 0 && status.getLastFailureMesgAsInt(0) != ContentResolver.SYNC_ERROR_SYNC_ALREADY_IN_PROGRESS;
                if (lastSyncFailed && !activelySyncing && !authorityIsPending) {
                    syncIsFailing = true;
                    anySyncFailed = true;
                }
                syncingNow |= activelySyncing;
                if (status != null && lastSuccessTime < status.lastSuccessTime) {
                    lastSuccessTime = status.lastSuccessTime;
                }
                syncCount += syncEnabled && userFacing.contains(authority) ? 1 : 0;
            }
        } else {
            if (Log.isLoggable(TAG, Log.VERBOSE)) {
                Log.v(TAG, "no syncadapters found for " + account);
            }
        }
        if (syncIsFailing) {
            accountPref.setSyncStatus(AccountPreference.SYNC_ERROR, true);
        } else if (syncCount == 0) {
            accountPref.setSyncStatus(AccountPreference.SYNC_DISABLED, true);
        } else if (syncCount > 0) {
            if (syncingNow) {
                accountPref.setSyncStatus(AccountPreference.SYNC_IN_PROGRESS, true);
            } else {
                accountPref.setSyncStatus(AccountPreference.SYNC_ENABLED, true);
                if (lastSuccessTime > 0) {
                    accountPref.setSyncStatus(AccountPreference.SYNC_ENABLED, false);
                    date.setTime(lastSuccessTime);
                    final String timeString = formatSyncDate(date);
                    accountPref.setSummary(getResources().getString(R.string.last_synced, timeString));
                }
            }
        } else {
            accountPref.setSyncStatus(AccountPreference.SYNC_DISABLED, true);
        }
    }
    mErrorInfoView.setVisibility(anySyncFailed ? View.VISIBLE : View.GONE);
}
Also used : Account(android.accounts.Account) SyncStatusInfo(android.content.SyncStatusInfo) SyncAdapterType(android.content.SyncAdapterType) Date(java.util.Date) AccountPreference(com.android.settings.AccountPreference) Preference(android.support.v7.preference.Preference) SyncInfo(android.content.SyncInfo) AccountPreference(com.android.settings.AccountPreference) HashSet(java.util.HashSet)

Example 4 with AccountPreference

use of com.android.settings.AccountPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ManageAccountsSettings method onAuthDescriptionsUpdated.

@Override
protected void onAuthDescriptionsUpdated() {
    // Update account icons for all account preference items
    for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); i++) {
        Preference pref = getPreferenceScreen().getPreference(i);
        if (pref instanceof AccountPreference) {
            AccountPreference accPref = (AccountPreference) pref;
            accPref.setSummary(getLabelForType(accPref.getAccount().type));
        }
    }
}
Also used : AccountPreference(com.android.settings.AccountPreference) Preference(android.support.v7.preference.Preference) AccountPreference(com.android.settings.AccountPreference)

Aggregations

AccountPreference (com.android.settings.AccountPreference)4 Account (android.accounts.Account)3 Preference (android.support.v7.preference.Preference)3 SyncAdapterType (android.content.SyncAdapterType)2 SyncInfo (android.content.SyncInfo)1 SyncStatusInfo (android.content.SyncStatusInfo)1 Drawable (android.graphics.drawable.Drawable)1 Bundle (android.os.Bundle)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1