use of org.chromium.chrome.browser.widget.RoundedIconGenerator in project AndroidChromium by JackyAndroid.
the class ActivityTaskDescriptionIconGenerator method getBitmap.
/**
* Returns the icon to use for the Activity in the recent tasks list. Returns the favicon if it
* is adequate. If the passed in favicon is not adequate, an icon is generated from the
* page URL.
*
* @param pageUrl The URL of the tab.
* @param largestFavicon The largest favicon available at the page URL.
* @return The icon to use in the recent tasks list.
*/
public Bitmap getBitmap(String pageUrl, Bitmap largestFavicon) {
if (largestFavicon != null && largestFavicon.getWidth() >= mMinSizePx && largestFavicon.getHeight() >= mMinSizePx) {
return largestFavicon;
}
if (TextUtils.equals(pageUrl, mGeneratedPageUrl)) {
return mGeneratedIcon;
}
if (mGenerator == null) {
mGenerator = new RoundedIconGenerator(mContext, APP_ICON_SIZE_DP, APP_ICON_SIZE_DP, APP_ICON_CORNER_RADIUS_DP, APP_ICON_DEFAULT_BACKGROUND_COLOR, APP_ICON_TEXT_SIZE_DP);
}
mGeneratedPageUrl = pageUrl;
mGeneratedIcon = mGenerator.generateIconForUrl(pageUrl);
return mGeneratedIcon;
}
use of org.chromium.chrome.browser.widget.RoundedIconGenerator in project AndroidChromium by JackyAndroid.
the class NotificationBuilderBase method createIconGenerator.
@VisibleForTesting
static RoundedIconGenerator createIconGenerator(Resources resources) {
int largeIconWidthPx = resources.getDimensionPixelSize(android.R.dimen.notification_large_icon_width);
int largeIconHeightPx = resources.getDimensionPixelSize(android.R.dimen.notification_large_icon_height);
float density = resources.getDisplayMetrics().density;
int cornerRadiusPx = Math.min(largeIconWidthPx, largeIconHeightPx) / 2;
return new RoundedIconGenerator(largeIconWidthPx, largeIconHeightPx, cornerRadiusPx, NOTIFICATION_ICON_BG_COLOR, NOTIFICATION_ICON_TEXT_SIZE_DP * density);
}
use of org.chromium.chrome.browser.widget.RoundedIconGenerator in project AndroidChromium by JackyAndroid.
the class ShortcutHelper method generateHomeScreenIcon.
/**
* Generates a generic icon to be used in the launcher. This is just a rounded rectangle with
* a letter in the middle taken from the website's domain name.
*
* @param url URL of the shortcut.
* @param red Red component of the dominant icon color.
* @param green Green component of the dominant icon color.
* @param blue Blue component of the dominant icon color.
* @return Bitmap Either the touch-icon or the newly created favicon.
*/
@CalledByNative
public static Bitmap generateHomeScreenIcon(String url, int red, int green, int blue) {
Context context = ContextUtils.getApplicationContext();
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
final int outerSize = am.getLauncherLargeIconSize();
final int iconDensity = am.getLauncherLargeIconDensity();
Bitmap bitmap = null;
try {
bitmap = Bitmap.createBitmap(outerSize, outerSize, Bitmap.Config.ARGB_8888);
} catch (OutOfMemoryError e) {
Log.w(TAG, "OutOfMemoryError while trying to draw bitmap on canvas.");
return null;
}
Canvas canvas = new Canvas(bitmap);
// Draw the drop shadow.
int padding = (int) (GENERATED_ICON_PADDING_RATIO * outerSize);
Rect outerBounds = new Rect(0, 0, outerSize, outerSize);
Bitmap iconShadow = getBitmapFromResourceId(context, R.mipmap.shortcut_icon_shadow, iconDensity);
Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG);
canvas.drawBitmap(iconShadow, null, outerBounds, paint);
// Draw the rounded rectangle and letter.
int innerSize = outerSize - 2 * padding;
int cornerRadius = Math.round(ICON_CORNER_RADIUS_RATIO * outerSize);
int fontSize = Math.round(GENERATED_ICON_FONT_SIZE_RATIO * outerSize);
int color = Color.rgb(red, green, blue);
RoundedIconGenerator generator = new RoundedIconGenerator(innerSize, innerSize, cornerRadius, color, fontSize);
Bitmap icon = generator.generateIconForUrl(url);
// Bookmark URL does not have a domain.
if (icon == null)
return null;
canvas.drawBitmap(icon, padding, padding, null);
return bitmap;
}
use of org.chromium.chrome.browser.widget.RoundedIconGenerator in project AndroidChromium by JackyAndroid.
the class WebsitePreference method onFaviconAvailable.
@Override
public void onFaviconAvailable(Bitmap image, String iconUrl) {
mFaviconHelper.destroy();
mFaviconHelper = null;
if (image == null) {
// Invalid favicon, produce a generic one.
float density = getContext().getResources().getDisplayMetrics().density;
int faviconSizeDp = Math.round(mFaviconSizePx / density);
RoundedIconGenerator faviconGenerator = new RoundedIconGenerator(getContext(), faviconSizeDp, faviconSizeDp, FAVICON_CORNER_RADIUS_DP, FAVICON_BACKGROUND_COLOR, FAVICON_TEXT_SIZE_DP);
image = faviconGenerator.generateIconForUrl(faviconUrl());
}
setIcon(new BitmapDrawable(getContext().getResources(), image));
}
Aggregations