Search in sources :

Example 66 with RequestOptions

use of com.bumptech.glide.request.RequestOptions in project glide by bumptech.

the class GifFrameLoader method setFrameTransformation.

void setFrameTransformation(Transformation<Bitmap> transformation, Bitmap firstFrame) {
    this.transformation = Preconditions.checkNotNull(transformation);
    this.firstFrame = Preconditions.checkNotNull(firstFrame);
    requestBuilder = requestBuilder.apply(new RequestOptions().transform(transformation));
}
Also used : RequestOptions(com.bumptech.glide.request.RequestOptions)

Example 67 with RequestOptions

use of com.bumptech.glide.request.RequestOptions in project glide by bumptech.

the class DrawableTransformationTest method load_withColorDrawable_sizeOriginal_requiredTransform_fails.

@Test
public void load_withColorDrawable_sizeOriginal_requiredTransform_fails() throws ExecutionException, InterruptedException {
    Drawable colorDrawable = new ColorDrawable(Color.RED);
    expectedException.expect(ExecutionException.class);
    Glide.with(context).load(colorDrawable).apply(new RequestOptions().centerCrop()).submit().get();
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) RequestOptions(com.bumptech.glide.request.RequestOptions) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Test(org.junit.Test)

Example 68 with RequestOptions

use of com.bumptech.glide.request.RequestOptions in project glide by bumptech.

the class DrawableTransformationTest method load_withColorDrawable_fixedSize_requiredUnitTransform_returnsOriginalDrawable.

/**
 * Transformations that do nothing can simply return the original Bitmap.
 */
@Test
public void load_withColorDrawable_fixedSize_requiredUnitTransform_returnsOriginalDrawable() throws ExecutionException, InterruptedException {
    Drawable colorDrawable = new ColorDrawable(Color.RED);
    Drawable result = Glide.with(context).load(colorDrawable).apply(new RequestOptions().centerCrop()).submit(100, 100).get();
    assertThat(result).isInstanceOf(ColorDrawable.class);
    assertThat(((ColorDrawable) result).getColor()).isEqualTo(Color.RED);
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) RequestOptions(com.bumptech.glide.request.RequestOptions) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Test(org.junit.Test)

Example 69 with RequestOptions

use of com.bumptech.glide.request.RequestOptions in project glide by bumptech.

the class DrawableTransformationTest method load_withColorDrawable_fixedSize_nonUnitRequiredTransform_returnsBitmapDrawable.

/**
 * Transformations that produce a different output color/shape/image etc will end up returning
 * a {@link Bitmap} based on the original {@link Drawable} but with the transformation applied.
 */
@Test
public void load_withColorDrawable_fixedSize_nonUnitRequiredTransform_returnsBitmapDrawable() throws ExecutionException, InterruptedException {
    Drawable colorDrawable = new ColorDrawable(Color.RED);
    Drawable result = Glide.with(context).load(colorDrawable).apply(new RequestOptions().circleCrop()).submit(100, 100).get();
    Bitmap redSquare = Bitmap.createBitmap(100, 100, Config.ARGB_8888);
    Canvas canvas = new Canvas(redSquare);
    canvas.drawColor(Color.RED);
    BitmapPool bitmapPool = mock(BitmapPool.class);
    when(bitmapPool.get(100, 100, Bitmap.Config.ARGB_8888)).thenReturn(Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888));
    Bitmap expected = TransformationUtils.circleCrop(bitmapPool, redSquare, 100, 100);
    assertThat(result).isInstanceOf(BitmapDrawable.class);
    Bitmap bitmap = ((BitmapDrawable) result).getBitmap();
    assertThat(bitmap.getWidth()).isEqualTo(100);
    assertThat(bitmap.getHeight()).isEqualTo(100);
    for (int x = 0; x < bitmap.getWidth(); x++) {
        for (int y = 0; y < bitmap.getHeight(); y++) {
            assertThat(bitmap.getPixel(x, y)).isEqualTo(expected.getPixel(x, y));
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) ColorDrawable(android.graphics.drawable.ColorDrawable) RequestOptions(com.bumptech.glide.request.RequestOptions) Canvas(android.graphics.Canvas) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool) Test(org.junit.Test)

Example 70 with RequestOptions

use of com.bumptech.glide.request.RequestOptions in project glide by bumptech.

the class RequestBuilder method buildThumbnailRequestRecursive.

private Request buildThumbnailRequestRecursive(Target<TranscodeType> target, RequestListener<TranscodeType> targetListener, @Nullable RequestCoordinator parentCoordinator, TransitionOptions<?, ? super TranscodeType> transitionOptions, Priority priority, int overrideWidth, int overrideHeight, RequestOptions requestOptions) {
    if (thumbnailBuilder != null) {
        // Recursive case: contains a potentially recursive thumbnail request builder.
        if (isThumbnailBuilt) {
            throw new IllegalStateException("You cannot use a request as both the main request and a " + "thumbnail, consider using clone() on the request(s) passed to thumbnail()");
        }
        TransitionOptions<?, ? super TranscodeType> thumbTransitionOptions = thumbnailBuilder.transitionOptions;
        // that may have been applied on the thumbnail request explicitly.
        if (thumbnailBuilder.isDefaultTransitionOptionsSet) {
            thumbTransitionOptions = transitionOptions;
        }
        Priority thumbPriority = thumbnailBuilder.requestOptions.isPrioritySet() ? thumbnailBuilder.requestOptions.getPriority() : getThumbnailPriority(priority);
        int thumbOverrideWidth = thumbnailBuilder.requestOptions.getOverrideWidth();
        int thumbOverrideHeight = thumbnailBuilder.requestOptions.getOverrideHeight();
        if (Util.isValidDimensions(overrideWidth, overrideHeight) && !thumbnailBuilder.requestOptions.isValidOverride()) {
            thumbOverrideWidth = requestOptions.getOverrideWidth();
            thumbOverrideHeight = requestOptions.getOverrideHeight();
        }
        ThumbnailRequestCoordinator coordinator = new ThumbnailRequestCoordinator(parentCoordinator);
        Request fullRequest = obtainRequest(target, targetListener, requestOptions, coordinator, transitionOptions, priority, overrideWidth, overrideHeight);
        isThumbnailBuilt = true;
        // Recursively generate thumbnail requests.
        Request thumbRequest = thumbnailBuilder.buildRequestRecursive(target, targetListener, coordinator, thumbTransitionOptions, thumbPriority, thumbOverrideWidth, thumbOverrideHeight, thumbnailBuilder.requestOptions);
        isThumbnailBuilt = false;
        coordinator.setRequests(fullRequest, thumbRequest);
        return coordinator;
    } else if (thumbSizeMultiplier != null) {
        // Base case: thumbnail multiplier generates a thumbnail request, but cannot recurse.
        ThumbnailRequestCoordinator coordinator = new ThumbnailRequestCoordinator(parentCoordinator);
        Request fullRequest = obtainRequest(target, targetListener, requestOptions, coordinator, transitionOptions, priority, overrideWidth, overrideHeight);
        RequestOptions thumbnailOptions = requestOptions.clone().sizeMultiplier(thumbSizeMultiplier);
        Request thumbnailRequest = obtainRequest(target, targetListener, thumbnailOptions, coordinator, transitionOptions, getThumbnailPriority(priority), overrideWidth, overrideHeight);
        coordinator.setRequests(fullRequest, thumbnailRequest);
        return coordinator;
    } else {
        // Base case: no thumbnail.
        return obtainRequest(target, targetListener, requestOptions, parentCoordinator, transitionOptions, priority, overrideWidth, overrideHeight);
    }
}
Also used : ThumbnailRequestCoordinator(com.bumptech.glide.request.ThumbnailRequestCoordinator) RequestOptions(com.bumptech.glide.request.RequestOptions) Request(com.bumptech.glide.request.Request) SingleRequest(com.bumptech.glide.request.SingleRequest)

Aggregations

RequestOptions (com.bumptech.glide.request.RequestOptions)96 ImageView (android.widget.ImageView)23 View (android.view.View)18 Drawable (android.graphics.drawable.Drawable)16 TextView (android.widget.TextView)13 Bitmap (android.graphics.Bitmap)9 BitmapDrawable (android.graphics.drawable.BitmapDrawable)8 File (java.io.File)8 Uri (android.net.Uri)7 ColorDrawable (android.graphics.drawable.ColorDrawable)6 Context (android.content.Context)5 Intent (android.content.Intent)5 RecyclerView (android.support.v7.widget.RecyclerView)5 DataSource (com.bumptech.glide.load.DataSource)5 GlideException (com.bumptech.glide.load.engine.GlideException)5 FitCenter (com.bumptech.glide.load.resource.bitmap.FitCenter)5 RoundedCorners (com.bumptech.glide.load.resource.bitmap.RoundedCorners)5 Test (org.junit.Test)5 Activity (android.app.Activity)3 LayoutInflater (android.view.LayoutInflater)3