private <Data, TResource, Transcode> List<DecodePath<Data, TResource, Transcode>> getDecodePaths( Class<Data> dataClass, Class<TResource> resourceClass, Class<Transcode> transcodeClass) { List<DecodePath<Data, TResource, Transcode>> decodePaths = new ArrayList<>(); List<Class<TResource>> registeredResourceClasses = decoderRegistry.getResourceClasses(dataClass, resourceClass); for (Class<TResource> registeredResourceClass : registeredResourceClasses) { List<Class<Transcode>> registeredTranscodeClasses = transcoderRegistry.getTranscodeClasses(registeredResourceClass, transcodeClass); for (Class<Transcode> registeredTranscodeClass : registeredTranscodeClasses) { List<ResourceDecoder<Data, TResource>> decoders = decoderRegistry.getDecoders(dataClass, registeredResourceClass); ResourceTranscoder<TResource, Transcode> transcoder = transcoderRegistry.get(registeredResourceClass, registeredTranscodeClass); decodePaths.add(new DecodePath<>(dataClass, registeredResourceClass, registeredTranscodeClass, decoders, transcoder, exceptionListPool)); } } return decodePaths; }
private <Data, TResource, Transcode> List<DecodePath<Data, TResource, Transcode>> getDecodePaths( Class<Data> dataClass, Class<TResource> resourceClass, Class<Transcode> transcodeClass) { List<DecodePath<Data, TResource, Transcode>> decodePaths = new ArrayList<>(); List<Class<TResource>> registeredResourceClasses = decoderRegistry.getResourceClasses(dataClass, resourceClass); for (Class<TResource> registeredResourceClass : registeredResourceClasses) { List<Class<Transcode>> registeredTranscodeClasses = transcoderRegistry.getTranscodeClasses(registeredResourceClass, transcodeClass); for (Class<Transcode> registeredTranscodeClass : registeredTranscodeClasses) { List<ResourceDecoder<Data, TResource>> decoders = decoderRegistry.getDecoders(dataClass, registeredResourceClass); ResourceTranscoder<TResource, Transcode> transcoder = transcoderRegistry.get(registeredResourceClass, registeredTranscodeClass); decodePaths.add(new DecodePath<>(dataClass, registeredResourceClass, registeredTranscodeClass, decoders, transcoder, throwableListPool)); } } return decodePaths; }
@Override public void onSizeReady(int width, int height) { if (isCancelled) { return; } width = Math.round(sizeMultiplier * width); height = Math.round(sizeMultiplier * height); ResourceDecoder<InputStream, Z> cacheDecoder = loadProvider.getCacheDecoder(); ResourceDecoder<T, Z> decoder = loadProvider.getSourceDecoder(); ResourceEncoder <Z> encoder = loadProvider.getEncoder(); ResourceTranscoder<Z, R> transcoder = loadProvider.getTranscoder(); ModelLoader<A, T> modelLoader = loadProvider.getModelLoader(); final String id = modelLoader.getId(model); final DataFetcher<T> dataFetcher = modelLoader.getResourceFetcher(model, width, height); loadedFromMemoryCache = true; loadStatus = engine.load(id, width, height, cacheDecoder, dataFetcher, decoder, transformation, encoder, transcoder, priority, isMemoryCacheable, this); loadedFromMemoryCache = resource != null; }
public DecodePath(Class<DataType> dataClass, Class<ResourceType> resourceClass, Class<Transcode> transcodeClass, List<? extends ResourceDecoder<DataType, ResourceType>> decoders, ResourceTranscoder<ResourceType, Transcode> transcoder, Pool<List<Exception>> listPool) { this.dataClass = dataClass; this.decoders = decoders; this.transcoder = transcoder; this.listPool = listPool; failureMessage = "Failed DecodePath{" + dataClass.getSimpleName() + "->" + resourceClass.getSimpleName() + "->" + transcodeClass.getSimpleName() + "}"; }
public DecodePath(Class<DataType> dataClass, Class<ResourceType> resourceClass, Class<Transcode> transcodeClass, List<? extends ResourceDecoder<DataType, ResourceType>> decoders, ResourceTranscoder<ResourceType, Transcode> transcoder, Pool<List<Throwable>> listPool) { this.dataClass = dataClass; this.decoders = decoders; this.transcoder = transcoder; this.listPool = listPool; failureMessage = "Failed DecodePath{" + dataClass.getSimpleName() + "->" + resourceClass.getSimpleName() + "->" + transcodeClass.getSimpleName() + "}"; }
GenericTranscodeRequest(Context context, Glide glide, A model, ModelLoader<A, T> modelLoader, Class<T> dataClass, Class<Z> resourceClass) { super(context, model, build(glide, modelLoader, dataClass, resourceClass, (ResourceTranscoder<Z, Z>) null), resourceClass, glide); this.context = context; this.model = model; this.glide = glide; this.modelLoader = modelLoader; this.dataClass = dataClass; this.resourceClass = resourceClass; }
private static <A, T, Z, R> LoadProvider<A, T, Z, R> build(Glide glide, ModelLoader<A, T> modelLoader, Class<T> dataClass, Class<Z> resourceClass, ResourceTranscoder<Z, R> transcoder) { if (transcoder == null) { transcoder = UnitTranscoder.get(); } return new FixedLoadProvider<A, T, Z, R>(modelLoader, transcoder, glide.buildDataProvider(dataClass, resourceClass)); }
private static <A, Z, R> FixedLoadProvider<A, ImageVideoWrapper, Z, R> buildProvider(Glide glide, ModelLoader<A, InputStream> streamModelLoader, ModelLoader<A, ParcelFileDescriptor> fileDescriptorModelLoader, Class<Z> resourceClass, Class<R> transcodedClass, ResourceTranscoder<Z, R> transcoder) { return streamModelLoader == null && fileDescriptorModelLoader == null ? null : new FixedLoadProvider<A, ImageVideoWrapper, Z, R>( new ImageVideoModelLoader<A>(streamModelLoader, fileDescriptorModelLoader), transcoder != null ? transcoder : glide.buildTranscoder(resourceClass, transcodedClass), glide.buildDataProvider(ImageVideoWrapper.class, resourceClass)); }
public SourceResourceRunner(Key key, int width, int height, DataFetcher<T> dataFetcher, ResourceDecoder<T, Z> decoder, Transformation<Z> transformation, ResourceEncoder<Z> encoder, ResourceTranscoder<Z, R> transcoder, DiskCache diskCache, Priority priority, ResourceCallback cb) { this.key = key; this.width = width; this.height = height; this.fetcher = dataFetcher; this.decoder = decoder; this.transformation = transformation; this.encoder = encoder; this.transcoder = transcoder; this.diskCache = diskCache; this.priority = priority; this.cb = cb; }
public EngineKey(String id, int width, int height, ResourceDecoder cacheDecoder, ResourceDecoder decoder, Transformation transformation, ResourceEncoder encoder, ResourceTranscoder transcoder) { this.id = id; this.width = width; this.height = height; this.cacheDecoder = cacheDecoder; this.decoder = decoder; this.transformation = transformation; this.encoder = encoder; this.transcoder = transcoder; }
public ResourceRunner(Key key, int width, int height, DiskCache diskCache, ResourceDecoder<InputStream, Z> cacheDecoder, ResourceTranscoder<Z, R> transcoder, SourceResourceRunner sourceRunner, ExecutorService executorService, Handler bgHandler, EngineJob job) { this.key = key; this.width = width; this.height = height; this.diskCache = diskCache; this.cacheDecoder = cacheDecoder; this.transcoder = transcoder; this.sourceRunner = sourceRunner; this.executorService = executorService; this.bgHandler = bgHandler; this.job = job; }
/** * * @param id A unique id for the model, dimensions, cache decoder, decoder, and encoder * @param cacheDecoder * @param fetcher * @param decoder * @param encoder * @param transcoder * @param priority * @param <T> The type of data the resource will be decoded from. * @param <Z> The type of the resource that will be decoded. * @param <R> The type of the resource that will be transcoded from the decoded resource. */ public <T, Z, R> LoadStatus load(String id, int width, int height, ResourceDecoder<InputStream, Z> cacheDecoder, DataFetcher<T> fetcher, ResourceDecoder<T, Z> decoder, Transformation<Z> transformation, ResourceEncoder<Z> encoder, ResourceTranscoder<Z, R> transcoder, Priority priority, boolean isMemoryCacheable, ResourceCallback cb) { Key key = keyFactory.buildKey(id, width, height, cacheDecoder, decoder, transformation, encoder, transcoder); Resource cached = cache.get(key); if (cached != null) { cached.acquire(1); cb.onResourceReady(cached); return null; } ResourceRunner current = runners.get(key); if (current != null) { EngineJob job = current.getJob(); job.addCallback(cb); return new LoadStatus(cb, job); } ResourceRunner<Z, R> runner = factory.build(key, width, height, cacheDecoder, fetcher, decoder, transformation, encoder, transcoder, priority, isMemoryCacheable, this); runner.getJob().addCallback(cb); runners.put(key, runner); runner.queue(); return new LoadStatus(cb, runner.getJob()); }
@Override public <T, Z, R> ResourceRunner<Z, R> build(Key key, int width, int height, ResourceDecoder<InputStream, Z> cacheDecoder, DataFetcher<T> fetcher, ResourceDecoder<T, Z> decoder, Transformation<Z> transformation, ResourceEncoder<Z> encoder, ResourceTranscoder<Z, R> transcoder, Priority priority, boolean isMemoryCacheable, EngineJobListener listener) { EngineJob engineJob = new EngineJob(key, memoryCache, mainHandler, isMemoryCacheable, listener); SourceResourceRunner<T, Z, R> sourceRunner = new SourceResourceRunner<T, Z, R>(key, width, height, fetcher, decoder, transformation, encoder, transcoder, diskCache, priority, engineJob); return new ResourceRunner<Z, R>(key, width, height, diskCache, cacheDecoder, transcoder, sourceRunner, service, bgHandler, engineJob); }
private static <A, R> FixedLoadProvider<A, ImageVideoWrapper, Bitmap, R> buildProvider(Glide glide, ModelLoader<A, InputStream> streamModelLoader, ModelLoader<A, ParcelFileDescriptor> fileDescriptorModelLoader, Class<R> transcodedClass, ResourceTranscoder<Bitmap, R> transcoder) { return streamModelLoader == null && fileDescriptorModelLoader == null ? null : new FixedLoadProvider<A, ImageVideoWrapper, Bitmap, R>( new ImageVideoModelLoader<A>(streamModelLoader, fileDescriptorModelLoader), transcoder != null ? transcoder : glide.buildTranscoder(Bitmap.class, transcodedClass), glide.buildDataProvider(ImageVideoWrapper.class, Bitmap.class)); }
@Override public ResourceTranscoder<Z, R> getTranscoder() { if (transcoder != null) { return transcoder; } else { return parent.getTranscoder(); } }
public FixedLoadProvider(ModelLoader<A, T> modelLoader, ResourceTranscoder<Z, R> transcoder, DataLoadProvider<T, Z> dataLoadProvider) { if (modelLoader == null) { throw new NullPointerException("ModelLoader must not be null"); } this.modelLoader = modelLoader; if (transcoder == null) { throw new NullPointerException("Transcoder must not be null"); } this.transcoder = transcoder; if (dataLoadProvider == null) { throw new NullPointerException("DataLoadProvider must not be null"); } this.dataLoadProvider = dataLoadProvider; }