Java Code Examples for android.graphics.drawable.Icon#createWithAdaptiveBitmap()

The following examples show how to use android.graphics.drawable.Icon#createWithAdaptiveBitmap() . 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 File: ShortcutsManager.java    From GeometricWeather with GNU Lesser General Public License v3.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.O)
@NonNull
private static Icon getAdaptiveIcon(ResourceProvider provider, WeatherCode code, boolean daytime) {
    return Icon.createWithAdaptiveBitmap(
            drawableToBitmap(
                    ResourceHelper.getShortcutsForegroundIcon(provider, code, daytime)
            )
    );
}
 
Example 2
Source File: ShortcutsManager.java    From Mysplash with GNU Lesser General Public License v3.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
private static Icon getShortcutsIcon(Context context,
                                     @DrawableRes int id, @DrawableRes int foregroundId) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        try {
            DisplayUtils utils = new DisplayUtils(context);
            int size = (int) Math.min(utils.dpToPx(108), 288);
            Bitmap bitmap = ImageHelper.loadBitmap(context, foregroundId, new int[] {size, size});
            return Icon.createWithAdaptiveBitmap(bitmap);
        } catch (ExecutionException | InterruptedException ignored) {

        }
    }
    return Icon.createWithResource(context, id);
}
 
Example 3
Source File: ShortcutIcons.java    From island with Apache License 2.0 5 votes vote down vote up
@RequiresApi(O) static Icon createAdaptiveIcon(final AdaptiveIconDrawable drawable) {
	final int width = drawable.getIntrinsicWidth() * 3 / 2, height = drawable.getIntrinsicHeight() * 3 / 2,
			start = drawable.getIntrinsicWidth() / 4, top = drawable.getIntrinsicHeight() / 4;
	drawable.setBounds(start, top, width - start, height - top);
	final Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
	final Canvas canvas = new Canvas(bitmap);
	drawable.draw(canvas);
	return Icon.createWithAdaptiveBitmap(bitmap);
}