/** Mimics Glide.get with a specific set of modules */ public void replace(List<Class<? extends GlideModule>> moduleClasses) { Glide originalGlide = null; if (isSetup()) { originalGlide = Glide.get(applicationContext); tearDown(); } Log.d(TAG, "Setting up new Glide..."); GlideBuilder builder = newBuilder(); List<GlideModule> modules = createModules(moduleClasses); Log.v(TAG, "using modules: " + modules); applyOptions(modules, builder); Glide glide = createGlide(builder); registerComponents(modules, glide); Log.i(TAG, "Glide has been replaced, original=" + originalGlide + ", new=" + glide); }
/** new ManifestParser(applicationContext).parse(); */ protected List<GlideModule> createModules(List<Class<? extends GlideModule>> moduleClasses) { List<GlideModule> modules = new ArrayList<>(); for (Class<? extends GlideModule> moduleClass : moduleClasses) { try { modules.add(moduleClass.newInstance()); } catch (Exception ex) { throw new IllegalArgumentException("Cannot create GlideModule: " + moduleClass, ex); } } return modules; }
@Override protected boolean isTargetClass(Class<?> clazz) { boolean accessible = !Modifier.isAbstract(clazz.getModifiers()) && Modifier.isPublic(clazz.getModifiers()); return accessible && ( Fragment.class.isAssignableFrom(clazz) || GlideModule.class.isAssignableFrom(clazz) || Activity.class.isAssignableFrom(clazz) ); }
public IssueInfo(ClassNameSplitter clazz, List< Class<? extends GlideModule>> modules) { this.clazz = clazz; this.source = clazz.getHostPackageName(); this.name = clazz.getPackageName(); this.modules = modules; }
public List<Class<? extends GlideModule>> getModules() { return modules; }
@Override protected void registerComponents(List<GlideModule> modules, Glide glide) { for (GlideModule module : modules) { module.registerComponents(applicationContext, glide); } }
@Override protected void applyOptions(List<GlideModule> modules, GlideBuilder builder) { for (GlideModule module : modules) { module.applyOptions(applicationContext, builder); } }
@Override protected void registerComponents(List<GlideModule> modules, Glide glide) { for (GlideModule module : modules) { module.registerComponents(applicationContext, glide.getRegistry()); } }
protected abstract void registerComponents(List<GlideModule> modules, Glide glide);
protected abstract void applyOptions(List<GlideModule> modules, GlideBuilder builder);