Glide源码——初始化

基于Glide v4.9,调用Glide.with(Context context)的时候,会触发Glide的初始化,内部是一个单例静态变量glide,初始化方法:initializeGlide(context, new GlideBuilder())。如果不希望使用Glide的默认配置,那么可以调用Glide的静态方法:public static synchronized void init(@NonNull Context context, @NonNull GlideBuilder builder),自己构造好GlideBuilder,否则会用默认的new GlideBuilder()。

void initializeGlide(@NonNull Context context, @NonNull GlideBuilder builder)方法中涉及annotationGeneratedModule,manifestModules,RequestManagerRetriever.RequestManagerFactory factory,registerComponents,glide.registry……看起来是会读取AndroidManifest.xml获取一些配置,这块还不熟悉,后续补充。如果RequestManagerFactory为空,那么会使用默认的DEFAULT_FACTORY作为RequestManagerRetriever的成员变量,构造函数:

public RequestManagerRetriever(@Nullable RequestManagerFactory factory) {
  this.factory = factory != null ? factory : DEFAULT_FACTORY;
  handler = new Handler(Looper.getMainLooper(), this /* Callback */);
}

再回过头来看调用链:Glide.with(context) ->

public static RequestManager with(@NonNull Context context) {

  return getRetriever(context).get(context);

}

(retriever [rɪˈtriːvər],寻回犬,取回的人,取组织器) 

->

private static RequestManagerRetriever getRetriever(@Nullable Context context) {

  return Glide.get(context).getRequestManagerRetriever();

}

最终就走到了RequestManagerRetriever的get(Context context)方法来获取当前需要的RequestManager,关于RequestManager放到另一篇写。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值