Search in sources :

Example 21 with Options

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

the class DecodeJob method runLoadPath.

private <Data, ResourceType> Resource<R> runLoadPath(Data data, DataSource dataSource, LoadPath<Data, ResourceType, R> path) throws GlideException {
    Options options = getOptionsWithHardwareConfig(dataSource);
    DataRewinder<Data> rewinder = glideContext.getRegistry().getRewinder(data);
    try {
        // ResourceType in DecodeCallback below is required for compilation to work with gradle.
        return path.load(rewinder, options, width, height, new DecodeCallback<ResourceType>(dataSource));
    } finally {
        rewinder.cleanup();
    }
}
Also used : Options(com.bumptech.glide.load.Options)

Example 22 with Options

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

the class ResourceCacheKeyTest method testEqualsAndHashCode.

@Test
public void testEqualsAndHashCode() {
    Options memoryOptions = new Options();
    memoryOptions.set(Option.memory("key", new Object()), new Object());
    Options diskOptions = new Options();
    diskOptions.set(Option.disk("key", new CacheKeyUpdater<String>() {

        @Override
        public void update(@NonNull byte[] keyBytes, @NonNull String value, @NonNull MessageDigest messageDigest) {
            messageDigest.update(keyBytes);
            messageDigest.update(value.getBytes(Key.CHARSET));
        }
    }), "value");
    for (int i = 0; i < 20; i++) {
        byte[] array = new byte[9];
        Arrays.fill(array, (byte) 2);
        arrayPool.put(array);
    }
    keyTester.addEquivalenceGroup(new ResourceCacheKey(arrayPool, new ObjectKey("source"), new ObjectKey("signature"), 100, 100, transformation1, Object.class, new Options()), new ResourceCacheKey(arrayPool, new ObjectKey("source"), new ObjectKey("signature"), 100, 100, transformation1, Object.class, new Options())).addEquivalenceGroup(new ResourceCacheKey(arrayPool, new ObjectKey("otherSource"), new ObjectKey("signature"), 100, 100, transformation1, Object.class, new Options())).addEquivalenceGroup(new ResourceCacheKey(arrayPool, new ObjectKey("source"), new ObjectKey("otherSignature"), 100, 100, transformation1, Object.class, new Options())).addEquivalenceGroup(new ResourceCacheKey(arrayPool, new ObjectKey("source"), new ObjectKey("signature"), 200, 100, transformation1, Object.class, new Options())).addEquivalenceGroup(new ResourceCacheKey(arrayPool, new ObjectKey("source"), new ObjectKey("signature"), 100, 200, transformation1, Object.class, new Options())).addEquivalenceGroup(new ResourceCacheKey(arrayPool, new ObjectKey("source"), new ObjectKey("signature"), 100, 100, transformation2, Object.class, new Options())).addEquivalenceGroup(new ResourceCacheKey(arrayPool, new ObjectKey("source"), new ObjectKey("signature"), 100, 100, transformation1, Integer.class, new Options())).addEquivalenceGroup(new ResourceCacheKey(arrayPool, new ObjectKey("source"), new ObjectKey("signature"), 100, 100, transformation1, Object.class, memoryOptions)).addEquivalenceGroup(new ResourceCacheKey(arrayPool, new ObjectKey("source"), new ObjectKey("signature"), 100, 100, transformation1, Object.class, diskOptions)).addRegressionTest(new ResourceCacheKey(arrayPool, new ObjectKey("source"), new ObjectKey("signature"), 100, 100, transformation1, Object.class, new Options()), "04d632bfe8e588544909fc44edb7328fa28bea6831b96927ade22b44818654e2").addRegressionTest(new ResourceCacheKey(arrayPool, new ObjectKey("source"), new ObjectKey("signature"), 100, 100, transformation1, Object.class, diskOptions), "781ff8cd30aaaf248134580004ea6d63a1b87ae20ea0f769caf379d7d84986d0").test();
}
Also used : Options(com.bumptech.glide.load.Options) CacheKeyUpdater(com.bumptech.glide.load.Option.CacheKeyUpdater) NonNull(android.support.annotation.NonNull) ObjectKey(com.bumptech.glide.signature.ObjectKey) MessageDigest(java.security.MessageDigest) Test(org.junit.Test)

Example 23 with Options

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

the class EngineKeyTest method testEqualsAndHashCode.

@Test
public void testEqualsAndHashCode() {
    Options memoryOptions = new Options();
    memoryOptions.set(Option.memory("key", new Object()), new Object());
    Options diskOptions = new Options();
    diskOptions.set(Option.disk("key", new CacheKeyUpdater<String>() {

        @Override
        public void update(@NonNull byte[] keyBytes, @NonNull String value, @NonNull MessageDigest messageDigest) {
            messageDigest.update(keyBytes);
            messageDigest.update(value.getBytes(Key.CHARSET));
        }
    }), "value");
    new EqualsTester().addEqualityGroup(new EngineKey("id", new ObjectKey("signature"), 100, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Object.class, new Options()), new EngineKey("id", new ObjectKey("signature"), 100, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Object.class, new Options())).addEqualityGroup(new EngineKey("otherId", new ObjectKey("signature"), 100, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Object.class, new Options())).addEqualityGroup(new EngineKey("id", new ObjectKey("otherSignature"), 100, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Object.class, new Options())).addEqualityGroup(new EngineKey("id", new ObjectKey("signature"), 200, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Object.class, new Options())).addEqualityGroup(new EngineKey("id", new ObjectKey("signature"), 100, 200, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Object.class, new Options())).addEqualityGroup(new EngineKey("id", new ObjectKey("signature"), 100, 100, Collections.<Class<?>, Transformation<?>>singletonMap(Object.class, transformation), Object.class, Object.class, new Options())).addEqualityGroup(new EngineKey("id", new ObjectKey("signature"), 100, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Integer.class, Object.class, new Options())).addEqualityGroup(new EngineKey("id", new ObjectKey("signature"), 100, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Integer.class, new Options())).addEqualityGroup(new EngineKey("id", new ObjectKey("signature"), 100, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Object.class, memoryOptions)).addEqualityGroup(new EngineKey("id", new ObjectKey("signature"), 100, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Object.class, diskOptions)).testEquals();
}
Also used : Options(com.bumptech.glide.load.Options) Transformation(com.bumptech.glide.load.Transformation) CacheKeyUpdater(com.bumptech.glide.load.Option.CacheKeyUpdater) EqualsTester(com.google.common.testing.EqualsTester) NonNull(android.support.annotation.NonNull) ObjectKey(com.bumptech.glide.signature.ObjectKey) MessageDigest(java.security.MessageDigest) Test(org.junit.Test)

Example 24 with Options

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

the class RequestOptions method clone.

/**
 * Returns a copy of this request builder with all of the options put so far on this builder.
 *
 * <p> This method returns a "deep" copy in that all non-immutable arguments are copied such that
 * changes to one builder will not affect the other builder. However, in addition to immutable
 * arguments, the current model is not copied copied so changes to the model will affect both
 * builders. </p>
 *
 * <p> Even if this object was locked, the cloned object returned from this method will not be
 * locked. </p>
 */
@SuppressWarnings({ "unchecked", // we don't want to throw to be user friendly
"PMD.CloneThrowsCloneNotSupportedException" })
@CheckResult
@Override
public RequestOptions clone() {
    try {
        RequestOptions result = (RequestOptions) super.clone();
        result.options = new Options();
        result.options.putAll(options);
        result.transformations = new CachedHashCodeArrayMap<>();
        result.transformations.putAll(transformations);
        result.isLocked = false;
        result.isAutoCloneEnabled = false;
        return result;
    } catch (CloneNotSupportedException e) {
        throw new RuntimeException(e);
    }
}
Also used : GifOptions(com.bumptech.glide.load.resource.gif.GifOptions) Options(com.bumptech.glide.load.Options) CheckResult(android.support.annotation.CheckResult)

Example 25 with Options

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

the class FileDecoderTest method setUp.

@Before
public void setUp() {
    decoder = new FileDecoder();
    options = new Options();
}
Also used : Options(com.bumptech.glide.load.Options) Before(org.junit.Before)

Aggregations

Options (com.bumptech.glide.load.Options)33 Before (org.junit.Before)14 Test (org.junit.Test)10 Bitmap (android.graphics.Bitmap)4 Uri (android.net.Uri)3 NonNull (android.support.annotation.NonNull)3 ImageHeaderParser (com.bumptech.glide.load.ImageHeaderParser)3 ObjectKey (com.bumptech.glide.signature.ObjectKey)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 CheckResult (android.support.annotation.CheckResult)2 CacheKeyUpdater (com.bumptech.glide.load.Option.CacheKeyUpdater)2 LruArrayPool (com.bumptech.glide.load.engine.bitmap_recycle.LruArrayPool)2 DefaultImageHeaderParser (com.bumptech.glide.load.resource.bitmap.DefaultImageHeaderParser)2 ByteBuffer (java.nio.ByteBuffer)2 MessageDigest (java.security.MessageDigest)2 Application (android.app.Application)1 AssetManager (android.content.res.AssetManager)1 BitmapFactory (android.graphics.BitmapFactory)1