脚本宝典收集整理的这篇文章主要介绍了

Glide的源码分析(三)

脚本宝典小编觉得挺不错的,现在分享给大家,也给大家做个参考,希望能帮助你少写一行代码,多一份安全和惬意。

Glide取消图片加载
1.在任务刚开始时;
2.在EngineJob中,Future.cancel(true)
3.在加载完成,但没有加载到控件;
RequestManager.java:

     public void pauseRequests() {         Util.assertMainThread();         requestTracker.pauseRequests();     }

RequestTracker.java:

     public void pauseRequests() {         isPaused = true;         for (Request request : Util.getSnapshot(requests)) {             if (request.isRunning()) {                 request.pause();                 pendingRequests.add(request);             }         }     }

GenericRequest.java:

    @Override     public void pause() {         clear();         status = Status.PAUSED;     }

GenericRequest.LoadStatus.java:

    public void cancel() {             engineJob.removeCallback(cb);     }

EngineJob.java:

     public void removeCallback(ResourceCallback cb) {         Util.assertMainThread();         if (hasResource || hasException) {             addIgnoredCallback(cb);         } else {             cbs.remove(cb);             if (cbs.isEmpty()) {                 cancel();             }         }     }     void cancel() {         if (hasException || hasResource || isCancelled) {             return;         }         engineRunnable.cancel();         Future currentFuture = future;         if (currentFuture != null) {             currentFuture.cancel(true);         }         isCancelled = true;         listener.onEngineJobCancelled(this, key);     }

EngineRunnable.java:

     public void cancel() {         isCancelled = true;         decodeJob.cancel();     }

EngineRunnable.java:

    @Override     public void run() {         if (isCancelled) {             return;         }          Exception exception = null;         Resource<?> resource = null;         try {             resource = decode();         } catch (Exception e) {             if (Log.isLoggable(TAG, Log.VERBOSE)) {                 Log.v(TAG, "Exception decoding", e);             }             exception = e;         }          if (isCancelled) {             if (resource != null) {                 resource.recycle();             }             return;         }          if (resource == null) {             onLoadFailed(exception);         } else {             onLoadComplete(resource);         }     }

EngineJob.java:

    private volatile Future<?> future;     void cancel() {         if (hasException || hasResource || isCancelled) {             return;         }         engineRunnable.cancel();         Future currentFuture = future;         if (currentFuture != null) {             currentFuture.cancel(true);         }         isCancelled = true;         listener.onEngineJobCancelled(this, key);     }
    public void start(EngineRunnable engineRunnable) {         this.engineRunnable = engineRunnable;         future = diskCacheService.submit(engineRunnable);     }      @Override     public void submitForSource(EngineRunnable runnable) {         future = sourceService.submit(runnable);     }

总结

以上是脚本宝典为你收集整理的

Glide的源码分析(三)

全部内容,希望文章能够帮你解决

Glide的源码分析(三)

所遇到的程序开发问题,欢迎加入QQ群277859234一起讨论学习。如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典网站推荐给程序员好友。 本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。

80%的人都看过