Picasso源码完全解析(三)--Request和Action的创建
来源:互联网 发布:tftp软件怎么使用 编辑:程序博客网 时间:2024/05/22 23:04
Picasso源码完全解析(一)--概述
Picasso源码完全解析(二)--Picasso实例的创建
Picasso源码完全解析(三)--Request和Action的创建
Picasso源码完全解析(四)--Action分发和执行
Picasso源码完全解析(五)--图片的获取(BitmapHunter)
Picasso源码完全解析(六)--请求的取消、暂停、和恢复
Picasso源码完全解析(七)-- CleanupThread 取消请求
Picasso源码完全解析(三)--Request和Action的创建
使用Picasso可以加载链接、文件、Uri以及引用自带的res资源,
public RequestCreator load(@Nullable Uri uri) { return new RequestCreator(this, uri, 0);}public RequestCreator load(@Nullable 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));}public RequestCreator load(@NonNull File file) { if (file == null) { return new RequestCreator(this, null, 0); } return load(Uri.fromFile(file));}public RequestCreator load(@DrawableRes int resourceId) { if (resourceId == 0) { throw new IllegalArgumentException("Resource ID must not be zero."); } return new RequestCreator(this, null, resourceId);}
可以看出最终是创建了一个RequestCreator对象
private static final AtomicInteger nextId = new AtomicInteger();private final Picasso picasso;private final Request.Builder data;private boolean noFade;private boolean deferred;private boolean setPlaceholder = true;private int placeholderResId;private int errorResId;private int memoryPolicy;private int networkPolicy;private Drawable placeholderDrawable;private Drawable errorDrawable;private Object tag;
这个类有13个属性,其方法主要分为两部分,一类是设置属性,一类是发起请求的方法,主要有 get()、fetch()、into()三种方式。
其中 Request.Builder data 是采用建造者模式来创建请求的。我们
//fetch()方式 Action action = new FetchAction(picasso, request, memoryPolicy, networkPolicy, tag, key, callback); picasso.submit(action);//into()方式 Action action = new ImageViewAction(picasso, target, request, memoryPolicy, networkPolicy, errorResId, errorDrawable, requestKey, tag, callback, noFade); picasso.enqueueAndSubmit(action);
可以看到fetch()和into方式最终都是通过Picasso.submit()或者picasso.enqueueAndSubmit()两种方式提交的。到此,每个请求生成一个对应的Action,被提交给Picasso执行。
阅读全文
0 0
- Picasso源码完全解析(三)--Request和Action的创建
- Picasso源码完全解析(二)--Picasso实例的创建
- Picasso源码完全解析(四)--Action分发和执行
- Picasso源码完全解析(六)--请求的取消、暂停、和恢复
- Picasso源码完全解析(一)--概述
- Picasso的使用和源码解析
- Picasso的使用和源码解析
- Picasso源码完全解析(七)-- CleanupThread 取消请求
- Picasso源码完全解析(五)--图片的获取(BitmapHunter)
- Android Volley 完全解析(三),定制自己的Request
- Picasso源码的简单解析(一)
- Picasso源码的简单解析(二)
- Picasso源码的简单解析(一)
- Picasso源码分析(四):不变模式、建造者模式和Request的预处理
- Android 图片加载框架Picasso基本使用和源码完全解析
- Android Volley完全解析(三),定制自己的Request
- Android Volley完全解析(三),定制自己的Request
- Android Volley完全解析(三),定制自己的Request
- 网络与信息安全
- Java分支语句(if和switch)
- 桥梁模式【Bridge Pattern】
- [PAT-乙级]1032.挖掘机技术哪家强
- bootstrap图标菜单和按钮组件
- Picasso源码完全解析(三)--Request和Action的创建
- ARC 下 C++/OC 混编计数器的问题
- Java运算符
- 【Redis缓存机制】5.List链表类型介绍和操作
- Mariadb数据库
- 05--MySQL自学教程:DDL(Data Definition Language:数据库定义语言)操作数据库中的表(二)
- SAP HANA XS Administration Tool
- uboot源码——mmc驱动分析
- 强制关闭tomcat.运维小工具