org.chromium.chrome.browser.profiles.ProfileDownloader Java Examples

The following examples show how to use org.chromium.chrome.browser.profiles.ProfileDownloader. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AccountManagementFragment.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Prefetch the primary account image and name.
 *
 * @param context A context to use.
 * @param profile A profile to use.
 */
public static void prefetchUserNamePicture(Context context, Profile profile) {
    final String accountName = ChromeSigninController.get(context).getSignedInAccountName();
    if (TextUtils.isEmpty(accountName)) return;
    if (sToNamePicture.get(accountName) != null) return;

    ProfileDownloader.addObserver(new ProfileDownloader.Observer() {
        @Override
        public void onProfileDownloaded(String accountId, String fullName, String givenName,
                Bitmap bitmap) {
            if (TextUtils.equals(accountName, accountId)) {
                updateUserNamePictureCache(accountId, fullName, bitmap);
                ProfileDownloader.removeObserver(this);
            }
        }
    });
    startFetchingAccountInformation(context, profile, accountName);
}
 
Example #2
Source File: ProfileDataCache.java    From 365browser with Apache License 2.0 6 votes vote down vote up
public ProfileDataCache(Context context, Profile profile) {
    mContext = context;
    mProfile = profile;

    // There's no WindowAndroid present at this time, so get the default display.
    final DisplayAndroid displayAndroid = DisplayAndroid.getNonMultiDisplay(context);
    mImageSizePx = (int) Math.ceil(PROFILE_IMAGE_SIZE_DP * displayAndroid.getDipScale());
    mImageStrokePx = (int) Math.ceil(PROFILE_IMAGE_STROKE_DP * displayAndroid.getDipScale());
    mImageStrokeColor = Color.WHITE;

    Bitmap placeHolder = BitmapFactory.decodeResource(mContext.getResources(),
            R.drawable.fre_placeholder);
    mPlaceholderImage = getCroppedBitmap(placeHolder);

    ProfileDownloader.addObserver(this);
}
 
Example #3
Source File: AccountManagementFragment.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Prefetch the primary account image and name.
 *
 * @param context A context to use.
 * @param profile A profile to use.
 */
public static void prefetchUserNamePicture(Context context, Profile profile) {
    final String accountName = ChromeSigninController.get(context).getSignedInAccountName();
    if (TextUtils.isEmpty(accountName)) return;
    if (sToNamePicture.get(accountName) != null) return;

    ProfileDownloader.addObserver(new ProfileDownloader.Observer() {
        @Override
        public void onProfileDownloaded(String accountId, String fullName, String givenName,
                Bitmap bitmap) {
            if (TextUtils.equals(accountName, accountId)) {
                updateUserNamePictureCache(accountId, fullName, bitmap);
                ProfileDownloader.removeObserver(this);
            }
        }
    });
    startFetchingAccountInformation(context, profile, accountName);
}
 
Example #4
Source File: SignInPreference.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private void setupSignedIn(String accountName) {
    String title = AccountManagementFragment.getCachedUserName(accountName);
    if (title == null) {
        Profile profile = Profile.getLastUsedProfile();
        String cachedName = ProfileDownloader.getCachedFullName(profile);
        Bitmap cachedBitmap = ProfileDownloader.getCachedAvatar(profile);
        if (TextUtils.isEmpty(cachedName) || cachedBitmap == null) {
            AccountManagementFragment.startFetchingAccountInformation(
                    getContext(), profile, accountName);
        }
        title = TextUtils.isEmpty(cachedName) ? accountName : cachedName;
    }
    setTitle(title);
    setSummary(SyncPreference.getSyncStatusSummary(getContext()));
    setFragment(AccountManagementFragment.class.getName());

    Resources resources = getContext().getResources();
    Bitmap bitmap = AccountManagementFragment.getUserPicture(accountName, resources);
    setIcon(new BitmapDrawable(resources, bitmap));

    setWidgetLayoutResource(
            SyncPreference.showSyncErrorIcon(getContext()) ? R.layout.sync_error_widget : 0);

    setViewEnabled(true);
}
 
Example #5
Source File: ProfileDataCache.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
public ProfileDataCache(Context context, Profile profile) {
    ProfileDownloader.addObserver(this);

    mContext = context;
    mProfile = profile;

    // There's no WindowAndroid present at this time, so get the default display.
    final DisplayAndroid displayAndroid = DisplayAndroid.getNonMultiDisplay(context);
    mImageSizePx = (int) Math.ceil(PROFILE_IMAGE_SIZE_DP * displayAndroid.getDipScale());
    mImageStrokePx = (int) Math.ceil(PROFILE_IMAGE_STROKE_DP * displayAndroid.getDipScale());
    mImageStrokeColor = Color.WHITE;

    Bitmap placeHolder = BitmapFactory.decodeResource(mContext.getResources(),
            R.drawable.fre_placeholder);
    mPlaceholderImage = getCroppedBitmap(placeHolder);

    update();
}
 
Example #6
Source File: ProfileDataCache.java    From delion with Apache License 2.0 6 votes vote down vote up
public ProfileDataCache(Context context, Profile profile) {
    ProfileDownloader.addObserver(this);

    mContext = context;
    mProfile = profile;

    final DeviceDisplayInfo info = DeviceDisplayInfo.create(context);
    mImageSizePx = (int) Math.ceil(PROFILE_IMAGE_SIZE_DP * info.getDIPScale());
    mImageStrokePx = (int) Math.ceil(PROFILE_IMAGE_STROKE_DP * info.getDIPScale());
    mImageStrokeColor = Color.WHITE;

    Bitmap placeHolder = BitmapFactory.decodeResource(mContext.getResources(),
            R.drawable.fre_placeholder);
    mPlaceholderImage = getCroppedBitmap(placeHolder);

    update();
}
 
Example #7
Source File: AccountManagementFragment.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    SigninManager.get(getActivity()).addSignInStateObserver(this);
    ProfileDownloader.addObserver(this);
    ProfileSyncService syncService = ProfileSyncService.get();
    if (syncService != null) {
        syncService.addSyncStateChangedListener(this);
    }

    update();
}
 
Example #8
Source File: SignInPreference.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Stops listening for updates to the sign-in and sync state. Every call to registerForUpdates()
 * must be matched with a call to this method.
 */
public void unregisterForUpdates() {
    SigninManager manager = SigninManager.get(getContext());
    manager.removeSignInAllowedObserver(this);
    ProfileDownloader.removeObserver(this);
    AndroidSyncSettings.unregisterObserver(getContext(), this);
    ProfileSyncService syncService = ProfileSyncService.get();
    if (syncService != null) {
        syncService.removeSyncStateChangedListener(this);
    }
}
 
Example #9
Source File: ProfileDataCache.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Initiate fetching the user accounts data (images and the full name).
 * Fetched data will be sent to observers of ProfileDownloader.
 */
public void update() {
    if (mProfile == null) return;

    Account[] accounts = AccountManagerHelper.get(mContext).getGoogleAccounts();
    for (int i = 0; i < accounts.length; i++) {
        if (mCacheEntries.get(accounts[i].name) == null) {
            ProfileDownloader.startFetchingAccountInfoFor(
                    mContext, mProfile, accounts[i].name, mImageSizePx, true);
        }
    }
}
 
Example #10
Source File: AccountManagementFragment.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    SigninManager.get(getActivity()).addSignInStateObserver(this);
    ProfileDownloader.addObserver(this);
    ProfileSyncService syncService = ProfileSyncService.get();
    if (syncService != null) {
        syncService.addSyncStateChangedListener(this);
    }

    update();
}
 
Example #11
Source File: AccountManagementFragment.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onPause() {
    super.onPause();
    SigninManager.get(getActivity()).removeSignInStateObserver(this);
    ProfileDownloader.removeObserver(this);
    ProfileSyncService syncService = ProfileSyncService.get();
    if (syncService != null) {
        syncService.removeSyncStateChangedListener(this);
    }
}
 
Example #12
Source File: AccountManagementFragment.java    From 365browser with Apache License 2.0 5 votes vote down vote up
public void update() {
    final Context context = getActivity();
    if (context == null) return;

    if (getPreferenceScreen() != null) getPreferenceScreen().removeAll();

    mSignedInAccountName = ChromeSigninController.get().getSignedInAccountName();
    if (mSignedInAccountName == null) {
        // 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 fullName = getCachedUserName(mSignedInAccountName);
    if (TextUtils.isEmpty(fullName)) {
        fullName = ProfileDownloader.getCachedFullName(mProfile);
    }
    if (TextUtils.isEmpty(fullName)) fullName = mSignedInAccountName;

    getActivity().setTitle(fullName);

    configureSignOutSwitch();
    configureAddAccountPreference();
    configureChildAccountPreferences();
    configureSyncSettings();
    configureGoogleActivityControls();

    updateAccountsList();
}
 
Example #13
Source File: AccountManagementFragment.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Initiate fetching of an image and a picture of a given account. Fetched data will be sent to
 * observers of ProfileDownloader.
 *
 * @param context A context.
 * @param profile A profile.
 * @param accountName An account name.
 */
public static void startFetchingAccountInformation(
        Context context, Profile profile, String accountName) {
    if (TextUtils.isEmpty(accountName)) return;
    if (sToNamePicture.get(accountName) != null) return;

    final int imageSidePixels =
            context.getResources().getDimensionPixelOffset(R.dimen.user_picture_size);
    ProfileDownloader.startFetchingAccountInfoFor(
            context, profile, accountName, imageSidePixels, false);
}
 
Example #14
Source File: SignInPreference.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Starts listening for updates to the sign-in and sync state.
 */
public void registerForUpdates() {
    SigninManager manager = SigninManager.get(getContext());
    manager.addSignInAllowedObserver(this);
    ProfileDownloader.addObserver(this);
    FirstRunSignInProcessor.updateSigninManagerFirstRunCheckDone(getContext());
    AndroidSyncSettings.registerObserver(getContext(), this);
    ProfileSyncService syncService = ProfileSyncService.get();
    if (syncService != null) {
        syncService.addSyncStateChangedListener(this);
    }
}
 
Example #15
Source File: SignInPreference.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Stops listening for updates to the sign-in and sync state. Every call to registerForUpdates()
 * must be matched with a call to this method.
 */
public void unregisterForUpdates() {
    SigninManager manager = SigninManager.get(getContext());
    manager.removeSignInAllowedObserver(this);
    ProfileDownloader.removeObserver(this);
    AndroidSyncSettings.unregisterObserver(getContext(), this);
    ProfileSyncService syncService = ProfileSyncService.get();
    if (syncService != null) {
        syncService.removeSyncStateChangedListener(this);
    }
}
 
Example #16
Source File: ProfileDataCache.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Initiate fetching the user accounts data (images and the full name).
 * Fetched data will be sent to observers of ProfileDownloader.
 */
public void update(List<String> accounts) {
    for (int i = 0; i < accounts.size(); i++) {
        if (mCacheEntries.get(accounts.get(i)) == null) {
            ProfileDownloader.startFetchingAccountInfoFor(
                    mContext, mProfile, accounts.get(i), mImageSizePx, true);
        }
    }
}
 
Example #17
Source File: ProfileDataCache.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onProfileDownloaded(String accountId, String fullName, String givenName,
        Bitmap bitmap) {
    bitmap = getCroppedBitmap(bitmap);
    mCacheEntries.put(accountId, new CacheEntry(bitmap, fullName, givenName));
    for (ProfileDownloader.Observer observer : mObservers) {
        observer.onProfileDownloaded(accountId, fullName, givenName, bitmap);
    }
}
 
Example #18
Source File: AccountManagementFragment.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public void onPause() {
    super.onPause();
    SigninManager.get(getActivity()).removeSignInStateObserver(this);
    ProfileDownloader.removeObserver(this);
    ProfileSyncService syncService = ProfileSyncService.get();
    if (syncService != null) {
        syncService.removeSyncStateChangedListener(this);
    }
}
 
Example #19
Source File: AccountManagementFragment.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Initiate fetching of an image and a picture of a given account. Fetched data will be sent to
 * observers of ProfileDownloader.
 *
 * @param context A context.
 * @param profile A profile.
 * @param accountName An account name.
 */
public static void startFetchingAccountInformation(
        Context context, Profile profile, String accountName) {
    if (TextUtils.isEmpty(accountName)) return;
    if (sToNamePicture.get(accountName) != null) return;

    final int imageSidePixels =
            context.getResources().getDimensionPixelOffset(R.dimen.user_picture_size);
    ProfileDownloader.startFetchingAccountInfoFor(
            context, profile, accountName, imageSidePixels, false);
}
 
Example #20
Source File: AccountManagementFragment.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #21
Source File: AccountManagementFragment.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void onPause() {
    super.onPause();
    SigninManager.get(getActivity()).removeSignInStateObserver(this);
    ProfileDownloader.removeObserver(this);
    ProfileSyncService syncService = ProfileSyncService.get();
    if (syncService != null) {
        syncService.removeSyncStateChangedListener(this);
    }
}
 
Example #22
Source File: AccountManagementFragment.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    SigninManager.get(getActivity()).addSignInStateObserver(this);
    ProfileDownloader.addObserver(this);
    ProfileSyncService syncService = ProfileSyncService.get();
    if (syncService != null) {
        syncService.addSyncStateChangedListener(this);
    }

    update();
}
 
Example #23
Source File: ProfileDataCache.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Initiate fetching the user accounts data (images and the full name).
 * Fetched data will be sent to observers of ProfileDownloader.
 */
public void update() {
    if (mProfile == null) return;

    Account[] accounts = AccountManagerHelper.get(mContext).getGoogleAccounts();
    for (int i = 0; i < accounts.length; i++) {
        if (mCacheEntries.get(accounts[i].name) == null) {
            ProfileDownloader.startFetchingAccountInfoFor(
                    mContext, mProfile, accounts[i].name, mImageSizePx, true);
        }
    }
}
 
Example #24
Source File: SignInPreference.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Starts listening for updates to the sign-in and sync state.
 */
public void registerForUpdates() {
    SigninManager manager = SigninManager.get(getContext());
    manager.addSignInAllowedObserver(this);
    ProfileDownloader.addObserver(this);
    FirstRunSignInProcessor.updateSigninManagerFirstRunCheckDone(getContext());
    AndroidSyncSettings.registerObserver(getContext(), this);
    ProfileSyncService syncService = ProfileSyncService.get();
    if (syncService != null) {
        syncService.addSyncStateChangedListener(this);
    }
}
 
Example #25
Source File: SignInPreference.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Stops listening for updates to the sign-in and sync state. Every call to registerForUpdates()
 * must be matched with a call to this method.
 */
public void unregisterForUpdates() {
    SigninManager manager = SigninManager.get(getContext());
    manager.removeSignInAllowedObserver(this);
    ProfileDownloader.removeObserver(this);
    AndroidSyncSettings.unregisterObserver(getContext(), this);
    ProfileSyncService syncService = ProfileSyncService.get();
    if (syncService != null) {
        syncService.removeSyncStateChangedListener(this);
    }
}
 
Example #26
Source File: SignInPreference.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Starts listening for updates to the sign-in and sync state.
 */
public void registerForUpdates() {
    SigninManager manager = SigninManager.get(getContext());
    manager.addSignInAllowedObserver(this);
    ProfileDownloader.addObserver(this);
    FirstRunSignInProcessor.updateSigninManagerFirstRunCheckDone(getContext());
    AndroidSyncSettings.registerObserver(getContext(), this);
    ProfileSyncService syncService = ProfileSyncService.get();
    if (syncService != null) {
        syncService.addSyncStateChangedListener(this);
    }
}
 
Example #27
Source File: AccountManagementFragment.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Initiate fetching of an image and a picture of a given account. Fetched data will be sent to
 * observers of ProfileDownloader.
 *
 * @param context A context.
 * @param profile A profile.
 * @param accountName An account name.
 */
public static void startFetchingAccountInformation(
        Context context, Profile profile, String accountName) {
    if (TextUtils.isEmpty(accountName)) return;
    if (sToNamePicture.get(accountName) != null) return;

    final int imageSidePixels =
            context.getResources().getDimensionPixelOffset(R.dimen.user_picture_size);
    ProfileDownloader.startFetchingAccountInfoFor(
            context, profile, accountName, imageSidePixels, false);
}
 
Example #28
Source File: AccountManagementFragment.java    From delion with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #29
Source File: SignInPreference.java    From delion with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
        }
    });
}
 
Example #30
Source File: ProfileDataCache.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * @param observer Observer that was added by {@link #addObserver} and should be removed.
 */
public void removeObserver(ProfileDownloader.Observer observer) {
    mObservers.removeObserver(observer);
}