Glide原理之load过程

上文我们了解到Glide#with方法返回的是RequstManager对象,因此,load方法调用的是RequstManager.load方法。

1. RequstManager#load

  /**
   * 先调用asDrawable然后调用RequestBuilder#load(String)
   * @return A new request builder for loading a {@link Drawable} using the given model.
   */
  @NonNull
  @CheckResult
  @Override
  public RequestBuilder load(@Nullable String string) {
    return asDrawable().load(string);
  }

2. asDrawable

 /**
   * 构建RequestBuilder对象
   * @return A new request builder for loading a {@link Drawable}.
   */
  @NonNull
  @CheckResult
  public RequestBuilder asDrawable() {
    return as(Drawable.class);
  }

  @NonNull
  @CheckResult
  public  RequestBuilder as(
      @NonNull Class resourceClass) {
    return new RequestBuilder<>(glide, this, resourceClass, context);
  }

3. RequestBuilder#load(String)

 @NonNull
  @Override
  @CheckResult
  public RequestBuilder load(@Nullable String string) {
    return loadGeneric(string);
  }

  @NonNull
  private RequestBuilder loadGeneric(@Nullable Object model) {
    this.model = model;
    isModelSet = true;
    return this;
  }

load过程最终只是设置了两个值。model是我们传入的url字符串,isModelSet是一个状态为,标识设置过该参数。真正的加载是在into中完成,我们接下来会分析into过程

 

你可能感兴趣的:(Glide,Android,Glide,load,Glide源码分析)