Search in sources :

Example 1 with Request

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);
}
Also used : Request(com.squareup.picasso.Request) Test(org.junit.Test)

Example 2 with Request

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);
}
Also used : ThumborUrlBuilder(com.squareup.pollexor.ThumborUrlBuilder) Request(com.squareup.picasso.Request) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 3 with Request

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);
}
Also used : Request(com.squareup.picasso.Request) Test(org.junit.Test)

Example 4 with Request

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();
}
Also used : ThumborUrlBuilder(com.squareup.pollexor.ThumborUrlBuilder) Request(com.squareup.picasso.Request) Uri(android.net.Uri)

Example 5 with Request

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);
}
Also used : Request(com.squareup.picasso.Request) Test(org.junit.Test)

Aggregations

Request (com.squareup.picasso.Request)11 Test (org.junit.Test)9 ThumborUrlBuilder (com.squareup.pollexor.ThumborUrlBuilder)4 Uri (android.net.Uri)1 CacheControl (okhttp3.CacheControl)1 Config (org.robolectric.annotation.Config)1