git clone git@github.com:bumptech/glide.git # use https://github.com/bumptech/glide.git if "Permission Denied" cd glide git submodule init && git submodule update ./gradlew jar
public RequestManager get(Context context){ if (context == null) { thrownew IllegalArgumentException("You cannot start a load on a null Context"); } elseif (Util.isOnMainThread() && !(context instanceof Application)) { if (context instanceof FragmentActivity) { return get((FragmentActivity) context); } elseif (context instanceof Activity) { return get((Activity) context); } elseif (context instanceof ContextWrapper) { return get(((ContextWrapper) context).getBaseContext()); } }
return getApplicationManager(context); }
public RequestManager get(FragmentActivity activity){ if (Util.isOnBackgroundThread()) { // 不在主线程 return get(activity.getApplicationContext()); } else { assertNotDestroyed(activity); FragmentManager fm = activity.getSupportFragmentManager(); return supportFragmentGet(activity, fm, null); } }
public RequestManager get(Fragment fragment){ if (fragment.getActivity() == null) { thrownew IllegalArgumentException( "You cannot start a load on a fragment before it is attached"); } if (Util.isOnBackgroundThread()) { // 不在主线程 return get(fragment.getActivity().getApplicationContext()); } else { FragmentManager fm = fragment.getChildFragmentManager(); return supportFragmentGet(fragment.getActivity(), fm, fragment); } }
public RequestManager get(Activity activity){ // 不在主线程 if (Util.isOnBackgroundThread() || Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { return get(activity.getApplicationContext()); } else { assertNotDestroyed(activity); android.app.FragmentManager fm = activity.getFragmentManager(); return fragmentGet(activity, fm, null); } }
private RequestManager getApplicationManager(Context context){ // Either an application context or we're on a background thread. if (applicationManager == null) { synchronized (this) { if (applicationManager == null) { // Normally pause/resume is taken care of by the fragment we add to the fragment or // activity. However, in this case since the manager attached to the application will not // receive lifecycle events, we must force the manager to start resumed using // ApplicationLifecycle.
// TODO(b/27524013): Factor out this Glide.get() call. Glide glide = Glide.get(context); applicationManager = new RequestManager( glide, new ApplicationLifecycle(), new EmptyRequestManagerTreeNode()); } } }
public <Y extends Target<TranscodeType>> Y into(@NonNull Y target){ Util.assertMainThread(); Preconditions.checkNotNull(target); if (!isModelSet) { thrownew IllegalArgumentException("You must call #load() before calling #into()"); }
Request previous = target.getRequest();
if (previous != null) { requestManager.clear(target); }
private Request buildRequestRecursive(Target<TranscodeType> target, @Nullable ThumbnailRequestCoordinator parentCoordinator, TransitionOptions<?, ? super TranscodeType> transitionOptions, Priority priority, int overrideWidth, int overrideHeight){ // 缩略图请求 if (thumbnailBuilder != null) { // Recursive case: contains a potentially recursive thumbnail request builder. if (isThumbnailBuilt) { thrownew IllegalStateException("You cannot use a request as both the main request and a " + "thumbnail, consider using clone() on the request(s) passed to thumbnail()"); }
TransitionOptions<?, ? super TranscodeType> thumbTransitionOptions = thumbnailBuilder.transitionOptions; if (DEFAULT_ANIMATION_OPTIONS.equals(thumbTransitionOptions)) { thumbTransitionOptions = transitionOptions; }
publicvoidrun(){ // This should be much more fine grained, but since Java's thread pool implementation silently // swallows all otherwise fatal exceptions, this will at least make it obvious to developers // that something is failing. try { if (isCancelled) { notifyFailed(); return; } runWrapped(); } catch (RuntimeException e) { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "DecodeJob threw unexpectedly" + ", isCancelled: " + isCancelled + ", stage: " + stage, e); } // When we're encoding we've already notified our callback and it isn't safe to do so again. if (stage != Stage.ENCODE) { notifyFailed(); } if (!isCancelled) { throw e; } } }
privatevoidrunWrapped(){ switch (runReason) { // 初始化 获取下一个阶段状态 case INITIALIZE: stage = getNextStage(Stage.INITIALIZE); currentGenerator = getNextGenerator(); // 运行load数据 runGenerators(); break; case SWITCH_TO_SOURCE_SERVICE: runGenerators(); break; case DECODE_DATA: // 处理已经load到的数据 decodeFromRetrievedData(); break; default: thrownew IllegalStateException("Unrecognized run reason: " + runReason); }
private DataFetcherGenerator getNextGenerator(){ switch (stage) { case RESOURCE_CACHE: returnnew ResourceCacheGenerator(decodeHelper, this); case DATA_CACHE: returnnew DataCacheGenerator(decodeHelper, this); case SOURCE: returnnew SourceGenerator(decodeHelper, this); case FINISHED: returnnull; default: thrownew IllegalStateException("Unrecognized stage: " + stage); } }
private Stage getNextStage(Stage current){ switch (current) { case INITIALIZE: return diskCacheStrategy.decodeCachedResource() ? Stage.RESOURCE_CACHE : getNextStage(Stage.RESOURCE_CACHE); case RESOURCE_CACHE: return diskCacheStrategy.decodeCachedData() ? Stage.DATA_CACHE : getNextStage(Stage.DATA_CACHE); case DATA_CACHE: // Skip loading from source if the user opted to only retrieve the resource from cache. return onlyRetrieveFromCache ? Stage.FINISHED : Stage.SOURCE; case SOURCE: case FINISHED: return Stage.FINISHED; default: thrownew IllegalArgumentException("Unrecognized stage: " + current); } }
publicvoidonDataReady(Object data){ DiskCacheStrategy diskCacheStrategy = helper.getDiskCacheStrategy(); if (data != null && diskCacheStrategy.isDataCacheable(loadData.fetcher.getDataSource())) { dataToCache = data; // We might be being called back on someone else's thread. Before doing anything, we should // reschedule to get back onto Glide's thread. cb.reschedule(); } else { cb.onDataFetcherReady(loadData.sourceKey, data, loadData.fetcher, loadData.fetcher.getDataSource(), originalKey); } }