Search in sources :

Example 11 with Key

use of com.bumptech.glide.load.Key in project glide by bumptech.

the class ResourceCacheGenerator method startNext.

// See TODO below.
@SuppressWarnings("PMD.CollapsibleIfStatements")
@Override
public boolean startNext() {
    List<Key> sourceIds = helper.getCacheKeys();
    if (sourceIds.isEmpty()) {
        return false;
    }
    List<Class<?>> resourceClasses = helper.getRegisteredResourceClasses();
    if (resourceClasses.isEmpty()) {
        if (File.class.equals(helper.getTranscodeClass())) {
            return false;
        }
    // TODO(b/73882030): This case gets triggered when it shouldn't. With this assertion it causes
    // all loads to fail. Without this assertion it causes loads to miss the disk cache
    // unnecessarily
    // throw new IllegalStateException(
    // "Failed to find any load path from " + helper.getModelClass() + " to "
    // + helper.getTranscodeClass());
    }
    while (modelLoaders == null || !hasNextModelLoader()) {
        resourceClassIndex++;
        if (resourceClassIndex >= resourceClasses.size()) {
            sourceIdIndex++;
            if (sourceIdIndex >= sourceIds.size()) {
                return false;
            }
            resourceClassIndex = 0;
        }
        Key sourceId = sourceIds.get(sourceIdIndex);
        Class<?> resourceClass = resourceClasses.get(resourceClassIndex);
        Transformation<?> transformation = helper.getTransformation(resourceClass);
        // PMD.AvoidInstantiatingObjectsInLoops Each iteration is comparatively expensive anyway,
        // we only run until the first one succeeds, the loop runs for only a limited
        // number of iterations on the order of 10-20 in the worst case.
        currentKey = new // NOPMD AvoidInstantiatingObjectsInLoops
        ResourceCacheKey(helper.getArrayPool(), sourceId, helper.getSignature(), helper.getWidth(), helper.getHeight(), transformation, resourceClass, helper.getOptions());
        cacheFile = helper.getDiskCache().get(currentKey);
        if (cacheFile != null) {
            sourceKey = sourceId;
            modelLoaders = helper.getModelLoaders(cacheFile);
            modelLoaderIndex = 0;
        }
    }
    loadData = null;
    boolean started = false;
    while (!started && hasNextModelLoader()) {
        ModelLoader<File, ?> modelLoader = modelLoaders.get(modelLoaderIndex++);
        loadData = modelLoader.buildLoadData(cacheFile, helper.getWidth(), helper.getHeight(), helper.getOptions());
        if (loadData != null && helper.hasLoadPath(loadData.fetcher.getDataClass())) {
            started = true;
            loadData.fetcher.loadData(helper.getPriority(), this);
        }
    }
    return started;
}
Also used : File(java.io.File) Key(com.bumptech.glide.load.Key)

Example 12 with Key

use of com.bumptech.glide.load.Key in project glide by bumptech.

the class MultiModelLoader method buildLoadData.

@Override
public LoadData<Data> buildLoadData(@NonNull Model model, int width, int height, @NonNull Options options) {
    Key sourceKey = null;
    int size = modelLoaders.size();
    List<DataFetcher<Data>> fetchers = new ArrayList<>(size);
    // noinspection ForLoopReplaceableByForEach to improve perf
    for (int i = 0; i < size; i++) {
        ModelLoader<Model, Data> modelLoader = modelLoaders.get(i);
        if (modelLoader.handles(model)) {
            LoadData<Data> loadData = modelLoader.buildLoadData(model, width, height, options);
            if (loadData != null) {
                sourceKey = loadData.sourceKey;
                fetchers.add(loadData.fetcher);
            }
        }
    }
    return !fetchers.isEmpty() && sourceKey != null ? new LoadData<>(sourceKey, new MultiFetcher<>(fetchers, exceptionListPool)) : null;
}
Also used : ArrayList(java.util.ArrayList) DataFetcher(com.bumptech.glide.load.data.DataFetcher) Key(com.bumptech.glide.load.Key)

Example 13 with Key

use of com.bumptech.glide.load.Key in project glide by bumptech.

the class ApplicationVersionSignatureTest method testUnresolvablePackageInfo.

@Test
public void testUnresolvablePackageInfo() throws NameNotFoundException {
    Context context = mock(Context.class, Answers.RETURNS_DEEP_STUBS.get());
    String packageName = "my.package";
    when(context.getPackageName()).thenReturn(packageName);
    when(context.getPackageManager().getPackageInfo(packageName, 0)).thenThrow(new NameNotFoundException("test"));
    Key key = ApplicationVersionSignature.obtain(context);
    assertNotNull(key);
}
Also used : Context(android.content.Context) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Key(com.bumptech.glide.load.Key) Test(org.junit.Test)

Example 14 with Key

use of com.bumptech.glide.load.Key in project glide by bumptech.

the class ApplicationVersionSignatureTest method testCanGetKeyForSignature.

@Test
public void testCanGetKeyForSignature() {
    Key key = ApplicationVersionSignature.obtain(context);
    assertNotNull(key);
}
Also used : Key(com.bumptech.glide.load.Key) Test(org.junit.Test)

Example 15 with Key

use of com.bumptech.glide.load.Key in project Rocket by mozilla-tw.

the class DataCacheGenerator method startNext.

@Override
public boolean startNext() {
    while (modelLoaders == null || !hasNextModelLoader()) {
        sourceIdIndex++;
        if (sourceIdIndex >= cacheKeys.size()) {
            return false;
        }
        Key sourceId = cacheKeys.get(sourceIdIndex);
        Key originalKey = new DataCacheKey(sourceId, helper.getSignature());
        cacheFile = helper.getDiskCache().get(originalKey);
        if (cacheFile != null) {
            this.sourceKey = sourceId;
            modelLoaders = helper.getModelLoaders(cacheFile);
            modelLoaderIndex = 0;
        }
    }
    loadData = null;
    boolean started = false;
    while (!started && hasNextModelLoader()) {
        ModelLoader<File, ?> modelLoader = modelLoaders.get(modelLoaderIndex++);
        loadData = modelLoader.buildLoadData(cacheFile, helper.getWidth(), helper.getHeight(), helper.getOptions());
        if (loadData != null && helper.hasLoadPath(loadData.fetcher.getDataClass())) {
            started = true;
            loadData.fetcher.loadData(helper.getPriority(), this);
        }
    }
    return started;
}
Also used : File(java.io.File) Key(com.bumptech.glide.load.Key)

Aggregations

Key (com.bumptech.glide.load.Key)24 Test (org.junit.Test)13 ResourceWeakReference (com.bumptech.glide.load.engine.ActiveResources.ResourceWeakReference)7 File (java.io.File)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 Context (android.content.Context)2 NonNull (android.support.annotation.NonNull)2 DataFetcher (com.bumptech.glide.load.data.DataFetcher)2 ArrayList (java.util.ArrayList)2 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1 Bitmap (android.graphics.Bitmap)1 VisibleForTesting (android.support.annotation.VisibleForTesting)1 EncodeStrategy (com.bumptech.glide.load.EncodeStrategy)1 Resource (com.bumptech.glide.load.engine.Resource)1 ResourceRemovedListener (com.bumptech.glide.load.engine.cache.MemoryCache.ResourceRemovedListener)1 MediaStoreSignature (com.bumptech.glide.signature.MediaStoreSignature)1 Util.anyResource (com.bumptech.glide.tests.Util.anyResource)1 Util.mockResource (com.bumptech.glide.tests.Util.mockResource)1 LruCache (com.bumptech.glide.util.LruCache)1 Synthetic (com.bumptech.glide.util.Synthetic)1