2. 加载url,创建并返回一个图片下载请求的构建器RequestCreator
//不仅仅用来存储图片的URL,
public RequestCreator load(String path) {
if (path == null) {
return new RequestCreator(this, null, 0);
}
if (path.trim().length() == 0) {
throw new IllegalArgumentException("Path must not be empty.");
}
return load(Uri.parse(path));
}
//请求构建器,用来存储该图片加载任务的一切信息,比如:
//目标的宽高,图片的显示样式(centerCrop,centerInside),旋转角度和旋转点坐标,以及图片
RequestCreator(Picasso picasso, Uri uri, int resourceId) {
if (picasso.shutdown) {
throw new IllegalStateException("Picasso instance already shut down. Cannot submit new requests.");
}
this.picasso = picasso;
this.data = new Request.Builder(uri, resourceId, picasso.defaultBitmapConfig);
}
//对图片设置矛盾之处的校验,校验通过则返回Request对象,该方法在最初方法链的into方法中(createRequest)调用
public Request build() {
if (centerInside && centerCrop) {
throw new IllegalStateException("Center crop and center inside can not be used together.");
}
if (centerCrop && (targetWidth == 0 && targetHeight == 0)) {
throw new IllegalStateException("Center crop requires calling resize with positive width and height.");
}
if (centerInside && (targetWidth == 0 && targetHeight == 0)) {
throw new IllegalStateException("Center inside requires calling resize with positive width and height.");
}
//默认的优先级为普通
if (priority == null) {
priority = Priority.NORMAL;
}
return new Request(uri, resourceId, stableKey, transformations, targetWidth, targetHeight,
centerCrop, centerInside, onlyScaleDown, rotationDegrees, rotationPivotX, rotationPivotY,
hasRotationPivot, purgeable, config, priority); }} |