staticintcalculateMemoryCacheSize(Contextcontext){ActivityManageram=getService(context,ACTIVITY_SERVICE);booleanlargeHeap=(context.getApplicationInfo().flags&FLAG_LARGE_HEAP)!=0;intmemoryClass=am.getMemoryClass();if(largeHeap&&SDK_INT>=HONEYCOMB){memoryClass=ActivityManagerHoneycomb.getLargeMemoryClass(am);}// Target ~15% of the available heap.
return1024*1024*memoryClass/7;}
staticDownloadercreateDefaultDownloader(Contextcontext){...//异常信息说明,需要的库为
//com.squareup.okhttp:okhttp:1.6.0 (or newer)
//com.squareup.okhttp:okhttp-urlconnection:1.6.0 (or newer)
if(okHttpClient!=okUrlFactory){thrownewRuntimeException(""+"Picasso detected an unsupported OkHttp on the classpath.\n"+"To use OkHttp with this version of Picasso, you'll need:\n"+"1. com.squareup.okhttp:okhttp:1.6.0 (or newer)\n"+"2. com.squareup.okhttp:okhttp-urlconnection:1.6.0 (or newer)\n"+"Note that OkHttp 2.0.0+ is supported!");}returnokHttpClient?OkHttpLoaderCreator.create(context):newUrlConnectionDownloader(context);}
//BitmapHandler.java
staticBitmaptransformResult(Requestdata,Bitmapresult,intexifRotation){...Matrixmatrix=newMatrix();if(data.needsMatrixTransform()){//重调大小
inttargetWidth=data.targetWidth;inttargetHeight=data.targetHeight;...//旋转
if(targetRotation!=0){if(data.hasRotationPivot){matrix.setRotate(targetRotation,data.rotationPivotX,data.rotationPivotY);}else{matrix.setRotate(targetRotation);}}//居中裁剪
if(data.centerCrop){floatwidthRatio=targetWidth/(float)inWidth;floatheightRatio=targetHeight/(float)inHeight;floatscale;if(widthRatio>heightRatio){scale=widthRatio;intnewSize=(int)Math.ceil(inHeight*(heightRatio/widthRatio));drawY=(inHeight-newSize)/2;drawHeight=newSize;}else{scale=heightRatio;intnewSize=(int)Math.ceil(inWidth*(widthRatio/heightRatio));drawX=(inWidth-newSize)/2;drawWidth=newSize;}matrix.preScale(scale,scale);}elseif(data.centerInside){floatwidthRatio=targetWidth/(float)inWidth;floatheightRatio=targetHeight/(float)inHeight;floatscale=widthRatio<heightRatio?widthRatio:heightRatio;matrix.preScale(scale,scale);}elseif(targetWidth!=0&&targetHeight!=0//
&&(targetWidth!=inWidth||targetHeight!=inHeight)){// If an explicit target size has been specified and they do not match the results bounds,
// pre-scale the existing matrix appropriately.
floatsx=targetWidth/(float)inWidth;floatsy=targetHeight/(float)inHeight;matrix.preScale(sx,sy);}}if(exifRotation!=0){matrix.preRotate(exifRotation);}BitmapnewResult=Bitmap.createBitmap(result,drawX,drawY,drawWidth,drawHeight,matrix,true);if(newResult!=result){result.recycle();result=newResult;}returnresult;}}