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));
}
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();
}
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);
}
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));
}
}
}
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);
}
}
Aggregations