Search in sources :

Example 1 with Options

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

the class DecodeJob method getOptionsWithHardwareConfig.

private Options getOptionsWithHardwareConfig(DataSource dataSource) {
    Options options = this.options;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
        return options;
    }
    if (options.get(Downsampler.ALLOW_HARDWARE_CONFIG) != null) {
        return options;
    }
    if (dataSource == DataSource.RESOURCE_DISK_CACHE || decodeHelper.isScaleOnlyOrNoTransform()) {
        options = new Options();
        options.putAll(this.options);
        options.set(Downsampler.ALLOW_HARDWARE_CONFIG, true);
    }
    return options;
}
Also used : Options(com.bumptech.glide.load.Options)

Example 2 with Options

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

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")
@CheckResult
@Override
public RequestOptions clone() {
    try {
        RequestOptions result = (RequestOptions) super.clone();
        result.options = new Options();
        result.options.putAll(options);
        result.transformations = new HashMap<>();
        result.transformations.putAll(transformations);
        result.isLocked = false;
        result.isAutoCloneEnabled = false;
        return result;
    } catch (CloneNotSupportedException e) {
        throw new RuntimeException(e);
    }
}
Also used : Options(com.bumptech.glide.load.Options) CheckResult(android.support.annotation.CheckResult)

Example 3 with Options

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

the class DownsamplerEmulatorTest method runScaleTest.

/**
 * Returns an error string if the test failed, and {@code null} otherwise.
 */
@Nullable
private static String runScaleTest(CompressFormat format, int initialWidth, int initialHeight, int targetWidth, int targetHeight, DownsampleStrategy strategy, int expectedWidth, int expectedHeight) throws IOException {
    Downsampler downsampler = buildDownsampler();
    InputStream is = openBitmapStream(format, initialWidth, initialHeight);
    Options options = new Options().set(DownsampleStrategy.OPTION, strategy);
    Bitmap bitmap = downsampler.decode(is, targetWidth, targetHeight, options).get();
    try {
        if (bitmap.getWidth() != expectedWidth || bitmap.getHeight() != expectedHeight) {
            return "API: " + Build.VERSION.SDK_INT + ", os: " + Build.VERSION.RELEASE + ", format: " + format + ", strategy: " + strategy + " -" + " Initial " + readableDimens(initialWidth, initialHeight) + " Target " + readableDimens(targetWidth, targetHeight) + " Expected " + readableDimens(expectedWidth, expectedHeight) + ", but Received " + readableDimens(bitmap.getWidth(), bitmap.getHeight());
        }
    } finally {
        bitmap.recycle();
    }
    return null;
}
Also used : Options(com.bumptech.glide.load.Options) Bitmap(android.graphics.Bitmap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Nullable(android.support.annotation.Nullable)

Example 4 with Options

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

the class ReEncodingGifResourceEncoderTest method setUp.

@SuppressWarnings("unchecked")
@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    Application context = RuntimeEnvironment.application;
    ReEncodingGifResourceEncoder.Factory factory = mock(ReEncodingGifResourceEncoder.Factory.class);
    when(decoder.getNextFrame()).thenReturn(Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888));
    when(factory.buildDecoder(any(GifDecoder.BitmapProvider.class))).thenReturn(decoder);
    when(factory.buildParser()).thenReturn(parser);
    when(factory.buildEncoder()).thenReturn(gifEncoder);
    when(factory.buildFrameResource(any(Bitmap.class), any(BitmapPool.class))).thenReturn(frameResource);
    // TODO Util.anyResource once Util is moved to testutil module (remove unchecked above!)
    when(frameTransformation.transform(anyContext(), any(Resource.class), anyInt(), anyInt())).thenReturn(frameResource);
    when(gifDrawable.getFrameTransformation()).thenReturn(frameTransformation);
    when(gifDrawable.getBuffer()).thenReturn(ByteBuffer.allocate(0));
    when(resource.get()).thenReturn(gifDrawable);
    encoder = new ReEncodingGifResourceEncoder(context, mock(BitmapPool.class), factory);
    options = new Options();
    options.set(ReEncodingGifResourceEncoder.ENCODE_TRANSFORMATION, true);
    file = new File(context.getCacheDir(), "test");
}
Also used : Options(com.bumptech.glide.load.Options) Bitmap(android.graphics.Bitmap) Resource(com.bumptech.glide.load.engine.Resource) Application(android.app.Application) BitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool) File(java.io.File) Before(org.junit.Before)

Example 5 with Options

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

the class UriLoaderTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    options = new Options();
    loader = new UriLoader<>(factory);
}
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