private Bitmap loadImage ( final String path , final Object into , final Transformation transformation ) { if ( into == null || mImagesCache == null || path == null || path . trim ( ) . isEmpty ( ) ) return null ; Log . d ( TAG , "load(" + path + ")" ) ; Bitmap bitmap = null ; if ( transformation == null ) { bitmap = loadFromLruCache ( path , true ) ; } else { final String pathTransformed = generatePathFromTransformation ( path , transformation ) ; bitmap = loadFromLruCache ( pathTransformed , true ) ; if ( bitmap == null ) { //if bitmap transformed not found in cache bitmap = loadFromLruCache ( path , true ) ; //try to get the bitmap without transformation if ( bitmap != null ) { new AsyncTask < Void , Void , Bitmap > ( ) { @ Override protected Bitmap doInBackground ( Void ... params ) { return transformAndSaveBitmap ( path , transformation ) ; } @ Override protected void onPostExecute ( Bitmap bitmap ) { super . onPostExecute ( bitmap ) ; if ( bitmap != null ) { //now its available on cache, can call again loadImage with same parameters loadImage ( path , into , transformation ) ; } } } . execute ( ) ; return null ; } } } Log . d ( TAG , "bitmap from cache " + bitmap + " for " + path ) ; if ( bitmap != null ) { //load directly from cache returnBitmapInto ( bitmap , path , into ) ; Log . d ( TAG , "image " + path + " available in the cache" ) ; } else { Log . d ( TAG , "image " + path + " not available in the cache, trying to download it" ) ; if ( isUrlPath ( path ) ) { Log . d ( TAG , "loadImage " + path + " send request to smartphone " + path . hashCode ( ) ) ; addIntoWaiting ( path , into , transformation ) ; } else { downloadBitmap ( path , into , transformation ) ; } } return bitmap ; }
Start the loading of an image