use of com.squareup.picasso.Request in project picasso by square.
the class PollexorRequestTransformerTest method resourceIdRequestsAreNotTransformed.
@Test
public void resourceIdRequestsAreNotTransformed() {
Request input = new Request.Builder(12).build();
Request output = transformer.transformRequest(input);
assertThat(output).isSameAs(input);
}
use of com.squareup.picasso.Request in project picasso by square.
the class PollexorRequestTransformerTest method simpleResizeOnJbMr2UsesWebP.
@Config(sdk = 18)
@Test
public void simpleResizeOnJbMr2UsesWebP() {
Request input = new Request.Builder(IMAGE_URI).resize(50, 50).build();
Request output = transformer.transformRequest(input);
assertThat(output).isNotSameAs(input);
assertThat(output.hasSize()).isFalse();
String expected = Thumbor.create(HOST).buildImage(IMAGE).resize(50, 50).filter(format(ImageFormat.WEBP)).toUrl();
assertThat(output.uri.toString()).isEqualTo(expected);
}
use of com.squareup.picasso.Request in project picasso by square.
the class PollexorRequestTransformerTest method nonResizedRequestsAreNotTransformed.
@Test
public void nonResizedRequestsAreNotTransformed() {
Request input = new Request.Builder(IMAGE_URI).build();
Request output = transformer.transformRequest(input);
assertThat(output).isSameAs(input);
}
use of com.squareup.picasso.Request in project picasso by square.
the class PollexorRequestTransformer method transformRequest.
@Override
public Request transformRequest(Request request) {
if (request.resourceId != 0) {
// Don't transform resource requests.
return request;
}
Uri uri = request.uri;
String scheme = uri.getScheme();
if (!"https".equals(scheme) && !"http".equals(scheme)) {
// Thumbor only supports remote images.
return request;
}
if (!request.hasSize()) {
// Thumbor only works with resizing images.
return request;
}
// Start building a new request for us to mutate.
Request.Builder newRequest = request.buildUpon();
// Create the url builder to use.
ThumborUrlBuilder urlBuilder = thumbor.buildImage(uri.toString());
// Resize the image to the target size.
urlBuilder.resize(request.targetWidth, request.targetHeight);
newRequest.clearResize();
// If the center inside flag is set, perform that with Thumbor as well.
if (request.centerInside) {
urlBuilder.fitIn();
newRequest.clearCenterInside();
}
// If the Android version is modern enough use WebP for downloading.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
urlBuilder.filter(format(ImageFormat.WEBP));
}
// Update the request with the completed Thumbor URL.
newRequest.setUri(Uri.parse(urlBuilder.toUrl()));
return newRequest.build();
}
use of com.squareup.picasso.Request in project picasso by square.
the class PollexorRequestTransformerTest method simpleResizeWithCenterInside.
@Test
public void simpleResizeWithCenterInside() {
Request input = new Request.Builder(IMAGE_URI).resize(50, 50).centerInside().build();
Request output = transformer.transformRequest(input);
assertThat(output).isNotSameAs(input);
assertThat(output.hasSize()).isFalse();
assertThat(output.centerInside).isFalse();
String expected = Thumbor.create(HOST).buildImage(IMAGE).resize(50, 50).fitIn().toUrl();
assertThat(output.uri.toString()).isEqualTo(expected);
}
Aggregations