Search in sources :

Example 1 with AdaptiveIconDrawable

use of android.graphics.drawable.AdaptiveIconDrawable in project Phonograph by kabouzeid.

the class AppShortcutIconGenerator method generateThemedIcon.

private static IconCompat generateThemedIcon(Context context, int iconId, int foregroundColor, int backgroundColor) {
    // Get and tint foreground and background drawables
    Drawable vectorDrawable = Util.getTintedVectorDrawable(context, iconId, foregroundColor);
    Drawable backgroundDrawable = Util.getTintedVectorDrawable(context, R.drawable.ic_app_shortcut_background, backgroundColor);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        AdaptiveIconDrawable adaptiveIconDrawable = new AdaptiveIconDrawable(backgroundDrawable, vectorDrawable);
        return IconCompat.createWithAdaptiveBitmap(drawableToBitmap(adaptiveIconDrawable));
    } else {
        // Squash the two drawables together
        LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] { backgroundDrawable, vectorDrawable });
        // Return as an Icon
        return IconCompat.createWithBitmap(drawableToBitmap(layerDrawable));
    }
}
Also used : LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) AdaptiveIconDrawable(android.graphics.drawable.AdaptiveIconDrawable) Drawable(android.graphics.drawable.Drawable) AdaptiveIconDrawable(android.graphics.drawable.AdaptiveIconDrawable)

Example 2 with AdaptiveIconDrawable

use of android.graphics.drawable.AdaptiveIconDrawable in project emerald by HenriDellal.

the class IconPackManager method getDefaultBitmap.

/* Returns Bitmap for default icon pack.
	 * Includes code for retrieving Oreo+ adaptive icons.
	 */
public Bitmap getDefaultBitmap(Drawable d) {
    if (d instanceof BitmapDrawable) {
        return ((BitmapDrawable) d).getBitmap();
    } else if ((Build.VERSION.SDK_INT >= 26) && (d instanceof AdaptiveIconDrawable)) {
        AdaptiveIconDrawable icon = ((AdaptiveIconDrawable) d);
        int w = icon.getIntrinsicWidth();
        int h = icon.getIntrinsicHeight();
        Bitmap result = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(result);
        icon.setBounds(0, 0, w, h);
        icon.draw(canvas);
        return result;
    }
    float density = context.getResources().getDisplayMetrics().density;
    int defaultWidth = (int) (48 * density);
    int defaultHeight = (int) (48 * density);
    return Bitmap.createBitmap(defaultWidth, defaultHeight, Bitmap.Config.ARGB_8888);
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) BitmapDrawable(android.graphics.drawable.BitmapDrawable) AdaptiveIconDrawable(android.graphics.drawable.AdaptiveIconDrawable) Paint(android.graphics.Paint)

Aggregations

AdaptiveIconDrawable (android.graphics.drawable.AdaptiveIconDrawable)2 Bitmap (android.graphics.Bitmap)1 Canvas (android.graphics.Canvas)1 Paint (android.graphics.Paint)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 Drawable (android.graphics.drawable.Drawable)1 LayerDrawable (android.graphics.drawable.LayerDrawable)1