public static Bitmap createIcon ( IconRow icon , float density , IconCache iconCache ) { Bitmap iconImage = null ; if ( icon != null ) { if ( iconCache != null ) { iconImage = iconCache . get ( icon . getId ( ) ) ; } if ( iconImage == null ) { BitmapFactory . Options options = icon . getDataBounds ( ) ; int dataWidth = options . outWidth ; int dataHeight = options . outHeight ; double styleWidth = dataWidth ; double styleHeight = dataHeight ; double widthDensity = DisplayMetrics . DENSITY_DEFAULT ; double heightDensity = DisplayMetrics . DENSITY_DEFAULT ; if ( icon . getWidth ( ) != null ) { styleWidth = icon . getWidth ( ) ; double widthRatio = dataWidth / styleWidth ; widthDensity *= widthRatio ; if ( icon . getHeight ( ) == null ) { heightDensity = widthDensity ; } } if ( icon . getHeight ( ) != null ) { styleHeight = icon . getHeight ( ) ; double heightRatio = dataHeight / styleHeight ; heightDensity *= heightRatio ; if ( icon . getWidth ( ) == null ) { widthDensity = heightDensity ; } } options = new BitmapFactory . Options ( ) ; options . inDensity = ( int ) ( Math . min ( widthDensity , heightDensity ) + 0.5f ) ; options . inTargetDensity = ( int ) ( DisplayMetrics . DENSITY_DEFAULT * density + 0.5f ) ; iconImage = icon . getDataBitmap ( options ) ; if ( widthDensity != heightDensity ) { int width = ( int ) ( styleWidth * density + 0.5f ) ; int height = ( int ) ( styleHeight * density + 0.5f ) ; if ( width != iconImage . getWidth ( ) || height != iconImage . getHeight ( ) ) { Bitmap scaledBitmap = Bitmap . createScaledBitmap ( iconImage , width , height , false ) ; iconImage . recycle ( ) ; iconImage = scaledBitmap ; } } if ( iconCache != null ) { iconCache . put ( icon . getId ( ) , iconImage ) ; } } } return iconImage ; }
Create or retrieve from cache an icon bitmap for the icon row