Search in sources :

Example 1 with IconAvailabilityCallback

use of org.chromium.chrome.browser.favicon.FaviconHelper.IconAvailabilityCallback in project AndroidChromium by JackyAndroid.

the class NewTabPageView method onPopularURLsAvailable.

@Override
public void onPopularURLsAvailable(String[] urls, String[] faviconUrls, String[] largeIconUrls) {
    for (int i = 0; i < urls.length; i++) {
        final String url = urls[i];
        boolean useLargeIcon = !largeIconUrls[i].isEmpty();
        // Only fetch one of favicon or large icon based on what is required on the NTP.
        // The other will be fetched on visiting the site.
        String iconUrl = useLargeIcon ? largeIconUrls[i] : faviconUrls[i];
        if (iconUrl.isEmpty())
            continue;
        IconAvailabilityCallback callback = new IconAvailabilityCallback() {

            @Override
            public void onIconAvailabilityChecked(boolean newlyAvailable) {
                if (newlyAvailable) {
                    mMostVisitedDesign.onIconUpdated(url);
                }
            }
        };
        mManager.ensureIconIsAvailable(url, iconUrl, useLargeIcon, /*isTemporary=*/
        false, callback);
    }
}
Also used : IconAvailabilityCallback(org.chromium.chrome.browser.favicon.FaviconHelper.IconAvailabilityCallback) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 2 with IconAvailabilityCallback

use of org.chromium.chrome.browser.favicon.FaviconHelper.IconAvailabilityCallback in project AndroidChromium by JackyAndroid.

the class SnippetArticleViewHolder method fetchFaviconFromService.

// TODO(crbug.com/635567): Fix this properly.
@SuppressLint("DefaultLocale")
private void fetchFaviconFromService(final URI snippetUri) {
    // Show the default favicon immediately.
    setDefaultFaviconOnView();
    if (!mUseFaviconService)
        return;
    int sizePx = getFaviconServiceSupportedSize();
    if (sizePx == 0)
        return;
    // Replace the default icon by another one from the service when it is fetched.
    mNewTabPageManager.ensureIconIsAvailable(// Store to the cache for the whole domain.
    getSnippetDomain(snippetUri), String.format(FAVICON_SERVICE_FORMAT, snippetUri.getHost(), sizePx), /*useLargeIcon=*/
    false, /*isTemporary=*/
    true, new IconAvailabilityCallback() {

        @Override
        public void onIconAvailabilityChecked(boolean newlyAvailable) {
            if (!newlyAvailable)
                return;
            // The download succeeded, the favicon is in the cache; fetch it.
            fetchFaviconFromLocalCache(snippetUri, /*fallbackToService=*/
            false);
        }
    });
}
Also used : IconAvailabilityCallback(org.chromium.chrome.browser.favicon.FaviconHelper.IconAvailabilityCallback) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Aggregations

SuppressLint (android.annotation.SuppressLint)2 IconAvailabilityCallback (org.chromium.chrome.browser.favicon.FaviconHelper.IconAvailabilityCallback)2 Point (android.graphics.Point)1