@CalledByNative public static Bitmap createHomeScreenIconFromWebIcon(Context context,Bitmap webIcon){
  ActivityManager am=(ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
  int maxInnerSize=Math.round(am.getLauncherLargeIconSize() * MAX_INNER_SIZE_RATIO);
  int innerSize=Math.min(maxInnerSize,Math.max(webIcon.getWidth(),webIcon.getHeight()));
  int padding=Math.round(ICON_PADDING_RATIO * innerSize);
  int outerSize=innerSize + 2 * padding;
  Bitmap bitmap=null;
  try {
    bitmap=Bitmap.createBitmap(outerSize,outerSize,Bitmap.Config.ARGB_8888);
  }
 catch (  OutOfMemoryError e) {
    Log.w(TAG,"OutOfMemoryError while creating bitmap for home screen icon.");
    return webIcon;
  }
  Canvas canvas=new Canvas(bitmap);
  Rect innerBounds=new Rect(padding,padding,outerSize - padding,outerSize - padding);
  Paint paint=new Paint(Paint.ANTI_ALIAS_FLAG);
  paint.setFilterBitmap(true);
  canvas.drawBitmap(webIcon,null,innerBounds,paint);
  int cornerRadius=Math.round(ICON_CORNER_RADIUS_RATIO * outerSize);
  Path path=new Path();
  path.setFillType(Path.FillType.INVERSE_WINDING);
  RectF innerBoundsF=new RectF(innerBounds);
  path.addRoundRect(innerBoundsF,cornerRadius,cornerRadius,Path.Direction.CW);
  paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
  canvas.drawPath(path,paint);
  return bitmap;
}

@ CalledByNative public static Bitmap createHomeScreenIconFromWebIcon ( Context context , Bitmap webIcon ) { ActivityManager am = ( ActivityManager ) context . getSystemService ( Context . ACTIVITY_SERVICE ) ; int maxInnerSize = Math . round ( am . getLauncherLargeIconSize ( ) * MAX_INNER_SIZE_RATIO ) ; int innerSize = Math . min ( maxInnerSize , Math . max ( webIcon . getWidth ( ) , webIcon . getHeight ( ) ) ) ; int padding = Math . round ( ICON_PADDING_RATIO * innerSize ) ; int outerSize = innerSize + 2 * padding ; Bitmap bitmap = null ; try { bitmap = Bitmap . createBitmap ( outerSize , outerSize , Bitmap . Config . ARGB_8888 ) ; } catch ( OutOfMemoryError e ) { Log . w ( TAG , "OutOfMemoryError while creating bitmap for home screen icon." ) ; return webIcon ; } Canvas canvas = new Canvas ( bitmap ) ; Rect innerBounds = new Rect ( padding , padding , outerSize - padding , outerSize - padding ) ; Paint paint = new Paint ( Paint . ANTI_ALIAS_FLAG ) ; paint . setFilterBitmap ( true ) ; canvas . drawBitmap ( webIcon , null , innerBounds , paint ) ; int cornerRadius = Math . round ( ICON_CORNER_RADIUS_RATIO * outerSize ) ; Path path = new Path ( ) ; path . setFillType ( Path . FillType . INVERSE_WINDING ) ; RectF innerBoundsF = new RectF ( innerBounds ) ; path . addRoundRect ( innerBoundsF , cornerRadius , cornerRadius , Path . Direction . CW ) ; paint . setXfermode ( new PorterDuffXfermode ( PorterDuff . Mode . CLEAR ) ) ; canvas . drawPath ( path , paint ) ; return bitmap ; }
adapts a website ' s icon ( e . g . favicon or touch icon ) to the material design style guidelines for home screen icons . this involves adding some padding and rounding the corners .
