Search in sources :

Example 1 with ChromeSigninController

use of org.chromium.components.signin.ChromeSigninController in project AndroidChromium by JackyAndroid.

the class AccountManagementFragment method update.

public void update() {
    final Context context = getActivity();
    if (context == null)
        return;
    if (getPreferenceScreen() != null)
        getPreferenceScreen().removeAll();
    ChromeSigninController signInController = ChromeSigninController.get(context);
    if (!signInController.isSignedIn()) {
        // The AccountManagementFragment can only be shown when the user is signed in. If the
        // user is signed out, exit the fragment.
        getActivity().finish();
        return;
    }
    addPreferencesFromResource(R.xml.account_management_preferences);
    String signedInAccountName = ChromeSigninController.get(getActivity()).getSignedInAccountName();
    String fullName = getCachedUserName(signedInAccountName);
    if (TextUtils.isEmpty(fullName)) {
        fullName = ProfileDownloader.getCachedFullName(Profile.getLastUsedProfile());
    }
    if (TextUtils.isEmpty(fullName))
        fullName = signedInAccountName;
    getActivity().setTitle(fullName);
    configureSignOutSwitch();
    configureAddAccountPreference();
    configureChildAccountPreferences();
    configureSyncSettings();
    configureGoogleActivityControls();
    updateAccountsList();
}
Also used : Context(android.content.Context) ChromeSigninController(org.chromium.components.signin.ChromeSigninController)

Example 2 with ChromeSigninController

use of org.chromium.components.signin.ChromeSigninController in project AndroidChromium by JackyAndroid.

the class SignInPreference method update.

/**
     * Updates the title, summary, and image based on the current sign-in state.
     */
private void update() {
    String title;
    String summary;
    String fragment;
    Account account = ChromeSigninController.get(getContext()).getSignedInUser();
    if (account == null) {
        title = getContext().getString(R.string.sign_in_to_chrome);
        summary = getContext().getString(R.string.sign_in_to_chrome_summary);
        fragment = null;
    } else {
        summary = SyncPreference.getSyncStatusSummary(getContext());
        fragment = AccountManagementFragment.class.getName();
        title = AccountManagementFragment.getCachedUserName(account.name);
        if (title == null) {
            final Profile profile = Profile.getLastUsedProfile();
            String cachedName = ProfileDownloader.getCachedFullName(profile);
            Bitmap cachedBitmap = ProfileDownloader.getCachedAvatar(profile);
            if (TextUtils.isEmpty(cachedName) || cachedBitmap == null) {
                AccountManagementFragment.startFetchingAccountInformation(getContext(), profile, account.name);
            }
            title = TextUtils.isEmpty(cachedName) ? account.name : cachedName;
        }
    }
    setTitle(title);
    setSummary(summary);
    setFragment(fragment);
    updateSyncStatusIcon();
    ChromeSigninController signinController = ChromeSigninController.get(getContext());
    boolean enabled = signinController.isSignedIn() || SigninManager.get(getContext()).isSignInAllowed();
    if (mViewEnabled != enabled) {
        mViewEnabled = enabled;
        notifyChanged();
    }
    if (!enabled)
        setFragment(null);
    if (SigninManager.get(getContext()).isSigninDisabledByPolicy()) {
        setIcon(ManagedPreferencesUtils.getManagedByEnterpriseIconId());
    } else {
        Resources resources = getContext().getResources();
        Bitmap bitmap = AccountManagementFragment.getUserPicture(signinController.getSignedInAccountName(), resources);
        setIcon(new BitmapDrawable(resources, bitmap));
    }
    setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            if (!AccountSigninActivity.startIfAllowed(getContext(), SigninAccessPoint.SETTINGS)) {
                return false;
            }
            setEnabled(false);
            return true;
        }
    });
    if (account == null && enabled) {
        RecordUserAction.record("Signin_Impression_FromSettings");
    }
}
Also used : Account(android.accounts.Account) Bitmap(android.graphics.Bitmap) ChromeSigninController(org.chromium.components.signin.ChromeSigninController) Preference(android.preference.Preference) AccountManagementFragment(org.chromium.chrome.browser.signin.AccountManagementFragment) Resources(android.content.res.Resources) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Profile(org.chromium.chrome.browser.profiles.Profile)

Aggregations

ChromeSigninController (org.chromium.components.signin.ChromeSigninController)2 Account (android.accounts.Account)1 Context (android.content.Context)1 Resources (android.content.res.Resources)1 Bitmap (android.graphics.Bitmap)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 Preference (android.preference.Preference)1 Profile (org.chromium.chrome.browser.profiles.Profile)1 AccountManagementFragment (org.chromium.chrome.browser.signin.AccountManagementFragment)1