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));
}
}
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);
}
Aggregations