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 fragm ent 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 applicationManager = new RequestManager(context.getApp licationContext(), new ApplicationLifecycle(), new EmptyRequestMa nagerTreeNode()); } } } return applicationManager; }
public RequestManager get(Context context){ if (context == null) { thrownew IllegalArgumentException("You cannot start a load o n a null Context"); } elseif (Util.isOnMainThread() && !(context instanceof Applicat ion)) { 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); } }
public RequestManager get(Fragment fragment){ if (fragment.getActivity() == null) { thrownew IllegalArgumentException("You cannot start a load o n a fragment before it is attached"); } if (Util.isOnBackgroundThread()) { return get(fragment.getActivity().getApplicationContext()); } else { FragmentManager fm = fragment.getChildFragmentManager(); return supportFragmentGet(fragment.getActivity(), fm); } }
@TargetApi(Build.VERSION_CODES.HONEYCOMB) 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); } }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) privatestaticvoidassertNotDestroyed(Activity activity){ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 & & activity.isDestroyed()) { thrownew IllegalArgumentException("You cannot start a load f or a destroyed activity"); } }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public RequestManager get(android.app.Fragment fragment){ if (fragment.getActivity() == null) { thrownew IllegalArgumentException("You cannot start a load o n a fragment before it is attached"); }if (Util.isOnBackgroundThread() || Build.VERSION.SDK_INT < Build. VERSION_CODES.JELLY_BEAN_MR1) { return get(fragment.getActivity().getApplicationContext()); } else { android.app.FragmentManager fm = fragment.getChildFragmentMan ager(); return fragmentGet(fragment.getActivity(), fm); } }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) RequestManagerFragment getRequestManagerFragment(final android.app.F ragmentManager fm){ RequestManagerFragment current = (RequestManagerFragment) fm.find FragmentByTag(FRAGMENT_TAG); if (current == null) { current = pendingRequestManagerFragments.get(fm); if (current == null) { current = new RequestManagerFragment(); pendingRequestManagerFragments.put(fm, current); fm.beginTransaction().add(current, FRAGMENT_TAG).commitAl lowingStateLoss(); handler.obtainMessage(ID_REMOVE_FRAGMENT_MANAGER, fm).sendToTarget(); } } return current; }
@TargetApi(Build.VERSION_CODES.HONEYCOMB) RequestManager fragmentGet(Context context, android.app.FragmentMana ger fm){ RequestManagerFragment current = getRequestManagerFragment(fm); RequestManager requestManager = current.getRequestManager(); if (requestManager == null) { requestManager = new RequestManager(context, current.getLifec ycle(), current.getRequestManagerTreeNode()); current.setRequestManager(requestManager); } return requestManager; }
SupportRequestManagerFragment getSupportRequestManagerFragment(final FragmentManager fm){ SupportRequestManagerFragment current = (SupportRequestManagerFr agment) fm.findFragmentByTag(FRAGMENT_TAG); if (current == null) { current = pendingSupportRequestManagerFragments.get(fm); if (current == null) { current = new SupportRequestManagerFragment(); pendingSupportRequestManagerFragments.put(fm, current); fm.beginTransaction().add(current, FRAGMENT_TAG).commitAllowingStateLoss(); handler.obtainMessage(ID_REMOVE_SUPPORT_FRAGMENT_MANAGER, fm).sendToTarget(); } } return current; }
RequestManager supportFragmentGet(Context context, FragmentManager f m){ SupportRequestManagerFragment current = getSupportRequestManager Fragment(fm); RequestManager requestManager = current.getRequestManager(); if (requestManager == null) { requestManager = new RequestManager(context, current.getLifec ycle(), current.getRequestManagerTreeNode()); current.setRequestManager(requestManager); } return requestManager; }
/** * Returns a request builder to load the given {@link String}. * signature. * * @see #fromString() * @see #load(Object) * * @param string A file path, or a uri or url handled by {@link com.b umptech.glide.load.model.UriLoader}. */ public DrawableTypeRequest<String> load(String string){ return (DrawableTypeRequest<String>) fromString().load(string); }
/*** Returns a request builder that loads data from {@link String}s using an empty signature. * * <p> * Note - this method caches data using only the given String as the cache key. If the data is a Uri outside of * your control, or you otherwise expect the data represented by the given String to change without the String * identifier changing, Consider using * {@link GenericRequestBuilder#signature(Key)} to mixin a signature * you create that identifies the data currently at the given String that will invalidate the cache if that data * changes. Alternatively, using {@link DiskCacheStrategy#NONE} a nd/or * {@link DrawableRequestBuilder#skipMemoryCache(boolean)} may be appropriate. * </p> * * @see #from(Class) * @see #load(String) */ public DrawableTypeRequest<String> fromString(){ return loadGeneric(String.class); }
private <T> DrawableTypeRequest<T> loadGeneric(Class<T> modelClass){ ModelLoader<T, InputStream> streamModelLoader = Glide.buildStream ModelLoader(modelClass, context); ModelLoader<T, ParcelFileDescriptor> fileDescriptorModelLoader = Glide.buildFileDescriptorModelLoader(modelClass, contex t); if (modelClass != null && streamModelLoader == null && fileDescri ptorModelLoader == null) { thrownew IllegalArgumentException("Unknown type " + modelCla ss + ". You must provide a Model of a type for" + " which there is a registered ModelLoader, if you ar e using a custom model, you must first call" + " Glide#register with a ModelLoaderFactory for your custom model class"); }
/** * Attempts to always load the resource as a {@link android.graphics. Bitmap}, even if it could actually be animated. * * @return A new request builder for loading a {@link android.graphic s.Bitmap} */ public BitmapTypeRequest<ModelType> asBitmap(){ return optionsApplier.apply(new BitmapTypeRequest<ModelType>(this, streamModelLoader, fileDescriptorModelLoader, optionsApplier)); }
/** * Attempts to always load the resource as a {@link com.bumptech.glide.load.resource.gif.GifDrawable}. * <p> * If the underlying data is not a GIF, this will fail. As a result, this should only be used if the model * represents an animated GIF and the caller wants to interact with the GIfDrawable directly. Normally using * just an {@link DrawableTypeRequest} is sufficient because it will determine whether or * not the given data represents an animated GIF and return the appropriate animated or not animated * {@link android.graphics.drawable.Drawable} automatically. * </p> * * @return A new request builder for loading a {@link com.bumptech.glide.load.resource.gif.GifDrawable}. */ public GifTypeRequest<ModelType> asGif(){ return optionsApplier.apply(new GifTypeRequest<ModelType>(this, streamModelLoader, optionsApplier)); } ... }