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

The following examples show how to use org.chromium.chrome.browser.profiles.ProfileDownloader. These examples are extracted from open source projects. 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 Project: delion   Source File: AccountManagementFragment.java    License: 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 Project: delion   Source File: ProfileDataCache.java    License: 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 3
Source Project: AndroidChromium   Source File: AccountManagementFragment.java    License: 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 Project: AndroidChromium   Source File: ProfileDataCache.java    License: 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 5
Source Project: 365browser   Source File: SignInPreference.java    License: 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 6
Source Project: 365browser   Source File: ProfileDataCache.java    License: 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 7
Source Project: delion   Source File: AccountManagementFragment.java    License: 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 Project: delion   Source File: AccountManagementFragment.java    License: 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 9
Source Project: delion   Source File: AccountManagementFragment.java    License: 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 10
Source Project: delion   Source File: AccountManagementFragment.java    License: 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 11
Source Project: delion   Source File: SignInPreference.java    License: 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 12
Source Project: delion   Source File: SignInPreference.java    License: 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 13
Source Project: delion   Source File: ProfileDataCache.java    License: 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 14
Source Project: AndroidChromium   Source File: AccountManagementFragment.java    License: 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 15
Source Project: AndroidChromium   Source File: AccountManagementFragment.java    License: 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 16
Source Project: AndroidChromium   Source File: AccountManagementFragment.java    License: 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 17
Source Project: AndroidChromium   Source File: AccountManagementFragment.java    License: 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 18
Source Project: AndroidChromium   Source File: SignInPreference.java    License: 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 19
Source Project: AndroidChromium   Source File: SignInPreference.java    License: 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 20
Source Project: AndroidChromium   Source File: ProfileDataCache.java    License: 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 21
Source Project: 365browser   Source File: AccountManagementFragment.java    License: 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 22
Source Project: 365browser   Source File: AccountManagementFragment.java    License: 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 23
Source Project: 365browser   Source File: AccountManagementFragment.java    License: 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 24
Source Project: 365browser   Source File: AccountManagementFragment.java    License: 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 25
Source Project: 365browser   Source File: SignInPreference.java    License: 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 26
Source Project: 365browser   Source File: SignInPreference.java    License: 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 27
Source Project: 365browser   Source File: ProfileDataCache.java    License: 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 28
Source Project: 365browser   Source File: ProfileDataCache.java    License: 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 29
Source Project: delion   Source File: SignInPreference.java    License: 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 Project: delion   Source File: ProfileDataCache.java    License: Apache License 2.0 4 votes vote down vote up
public void destroy() {
    ProfileDownloader.removeObserver(this);
    mObserver = null;
}