Glide 源码解析 之 关键类简介

Glide关键类介绍

Glide

单例,负责全局配置

/**
 * A singleton to present a simple static interface for building requests with
 * {@link RequestBuilder} and maintaining an {@link Engine}, {@link BitmapPool},
 * {@link com.bumptech.glide.load.engine.cache.DiskCache} and {@link MemoryCache}.
 */
复制代码

RequestManager

根据Activity、Fragment的生命周期去管理Request的开始、结束、重试。页面生命周期是如何传递过来的呢?请看:Glide 源码解析 之 生命周期传递

/**
 * A class for managing and starting requests for Glide. Can use activity, fragment and connectivity
 * lifecycle events to intelligently stop, start, and restart requests. Retrieve either by
 * instantiating a new object, or to take advantage built in Activity and Fragment lifecycle
 * handling, use the static Glide.load methods with your Fragment or Activity.
 */
复制代码

RequestBuilder

对各类加载参数进行封装。
在这里,图片的url会被封装成Request,imageView会被封装成Target,方便后期处理。

/**
 * A generic class that can handle setting options and staring loads for generic resource types.
 */
复制代码

Request

接口,封装加载请求

/**
 * A request that loads a resource for an {@link com.bumptech.glide.request.target.Target}.
 */
复制代码

Target

接口,封装加载目的地

/**
 * An interface that Glide can load a resource into and notify of relevant lifecycle events during a
 * load.
 */
复制代码

Engine

负责启动加载任务,管理cache。

/**
 * Responsible for starting loads and managing active and cached resources.
 */
复制代码

EngineJob

EngineJob 是 Engine 和 DecodeJob 中间的桥梁,负责了将 DecodeJob 丢到线程池中,响应 DecodeJob 的回调,并通过hanlder 将回调 切换到 MainThread,把结果传递到Engine中。

/**
 * A class that manages a load by adding and removing callbacks for for the load and notifying
 * callbacks when the load completes.
 */
复制代码

DecodeJob

负责从cache文件和原始数据源(local source,remote source)中加载数据。 实现了Runnable接口,在线程池中执行。

/**
 * A class responsible for decoding resources either from cached data or from the original source
 * and applying transformations and transcodes.
 */
复制代码

ActiveResources

一级内存缓存

LruResourceCache

二级内存缓存

/**
 * An LRU in memory cache for {@link com.bumptech.glide.load.engine.Resource}s.
 */
复制代码

DataFetcher

接口,负责从数据源中取出数据。

/**
 * Lazily retrieves data that can be used to load a resource.
 */
复制代码

ResourceDecoder

接口,负责图片数据的解码

/**
 * An interface for decoding resources.
 */
复制代码

Glide 类整体分析

Glide的类,按分工可以分为2类:

  1. 调度配置型:全部配置,根据不同的输入输出,调度不同的实现类去处理;
  2. 具体实施型:处理(fetch,decode)特定类型的数据;

从上文关键类的介绍可以看到,Glide中有几个关键接口有非常多的实现。之所以有这么多实现类,就是因为Glide支持非常多的加载类型(见下图),不同的实现类在调度类的调度下,处理各自对应的类型,有条不紊。

RequestBuilder的load()方法有非常多的重载方法。

图片加载框架的技术要点:

  1. 生命周期管理;Glide 源码解析 之 生命周期传递
  2. 缓存管理;Glide 源码解析 之 缓存
  3. 支持各种输入类型(本地文件、远程文件、Resource资源)、输出类型(Bitmap、Drawable);
  4. 图片后期处理(裁切、圆角、滤镜);
  5. 自定义配置(缓存类型配置、线程池配置、etc);
  6. 外部Module拓展;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值