Search in sources :

Example 51 with Result

use of com.squareup.picasso3.RequestHandler.Result in project picasso by square.

the class BitmapHunterTest method centerCropWithGravityHorizontalLeft.

@Test
public void centerCropWithGravityHorizontalLeft() {
    Bitmap source = Bitmap.createBitmap(20, 10, ARGB_8888);
    Request data = new Request.Builder(URI_1).resize(40, 40).centerCrop(Gravity.LEFT).build();
    Bitmap result = transformResult(data, source, 0);
    ShadowBitmap shadowBitmap = shadowOf(result);
    assertThat(shadowBitmap.getCreatedFromBitmap()).isSameInstanceAs(source);
    assertThat(shadowBitmap.getCreatedFromX()).isEqualTo(0);
    assertThat(shadowBitmap.getCreatedFromY()).isEqualTo(0);
    assertThat(shadowBitmap.getCreatedFromWidth()).isEqualTo(10);
    assertThat(shadowBitmap.getCreatedFromHeight()).isEqualTo(10);
    Matrix matrix = shadowBitmap.getCreatedFromMatrix();
    ShadowMatrix shadowMatrix = shadowOf(matrix);
    assertThat(shadowMatrix.getPreOperations()).containsExactly("scale 4.0 4.0");
}
Also used : TestUtils.makeBitmap(com.squareup.picasso3.TestUtils.makeBitmap) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) BitmapHunter.forRequest(com.squareup.picasso3.BitmapHunter.forRequest) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) Test(org.junit.Test)

Example 52 with Result

use of com.squareup.picasso3.RequestHandler.Result in project picasso by square.

the class BitmapHunterTest method centerCropTallTooSmall.

@Test
public void centerCropTallTooSmall() {
    Bitmap source = Bitmap.createBitmap(10, 20, ARGB_8888);
    Request data = new Request.Builder(URI_1).resize(40, 40).centerCrop().build();
    Bitmap result = transformResult(data, source, 0);
    ShadowBitmap shadowBitmap = shadowOf(result);
    assertThat(shadowBitmap.getCreatedFromBitmap()).isSameInstanceAs(source);
    assertThat(shadowBitmap.getCreatedFromX()).isEqualTo(0);
    assertThat(shadowBitmap.getCreatedFromY()).isEqualTo(5);
    assertThat(shadowBitmap.getCreatedFromWidth()).isEqualTo(10);
    assertThat(shadowBitmap.getCreatedFromHeight()).isEqualTo(10);
    Matrix matrix = shadowBitmap.getCreatedFromMatrix();
    ShadowMatrix shadowMatrix = shadowOf(matrix);
    assertThat(shadowMatrix.getPreOperations()).containsExactly("scale 4.0 4.0");
}
Also used : TestUtils.makeBitmap(com.squareup.picasso3.TestUtils.makeBitmap) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) BitmapHunter.forRequest(com.squareup.picasso3.BitmapHunter.forRequest) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) Test(org.junit.Test)

Example 53 with Result

use of com.squareup.picasso3.RequestHandler.Result in project picasso by square.

the class BitmapHunterTest method centerCropTallTooLarge.

@Test
public void centerCropTallTooLarge() {
    Bitmap source = Bitmap.createBitmap(100, 200, ARGB_8888);
    Request data = new Request.Builder(URI_1).resize(50, 50).centerCrop().build();
    Bitmap result = transformResult(data, source, 0);
    ShadowBitmap shadowBitmap = shadowOf(result);
    assertThat(shadowBitmap.getCreatedFromBitmap()).isSameInstanceAs(source);
    assertThat(shadowBitmap.getCreatedFromX()).isEqualTo(0);
    assertThat(shadowBitmap.getCreatedFromY()).isEqualTo(50);
    assertThat(shadowBitmap.getCreatedFromWidth()).isEqualTo(100);
    assertThat(shadowBitmap.getCreatedFromHeight()).isEqualTo(100);
    Matrix matrix = shadowBitmap.getCreatedFromMatrix();
    ShadowMatrix shadowMatrix = shadowOf(matrix);
    assertThat(shadowMatrix.getPreOperations()).containsExactly("scale 0.5 0.5");
}
Also used : TestUtils.makeBitmap(com.squareup.picasso3.TestUtils.makeBitmap) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) BitmapHunter.forRequest(com.squareup.picasso3.BitmapHunter.forRequest) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) Test(org.junit.Test)

Example 54 with Result

use of com.squareup.picasso3.RequestHandler.Result in project picasso by square.

the class BitmapHunterTest method centerCropWithGravityVerticalBottom.

@Test
public void centerCropWithGravityVerticalBottom() {
    Bitmap source = Bitmap.createBitmap(10, 20, ARGB_8888);
    Request data = new Request.Builder(URI_1).resize(40, 40).centerCrop(Gravity.BOTTOM).build();
    Bitmap result = transformResult(data, source, 0);
    ShadowBitmap shadowBitmap = shadowOf(result);
    assertThat(shadowBitmap.getCreatedFromBitmap()).isSameInstanceAs(source);
    assertThat(shadowBitmap.getCreatedFromX()).isEqualTo(0);
    assertThat(shadowBitmap.getCreatedFromY()).isEqualTo(10);
    assertThat(shadowBitmap.getCreatedFromWidth()).isEqualTo(10);
    assertThat(shadowBitmap.getCreatedFromHeight()).isEqualTo(10);
    Matrix matrix = shadowBitmap.getCreatedFromMatrix();
    ShadowMatrix shadowMatrix = shadowOf(matrix);
    assertThat(shadowMatrix.getPreOperations()).containsExactly("scale 4.0 4.0");
}
Also used : TestUtils.makeBitmap(com.squareup.picasso3.TestUtils.makeBitmap) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) BitmapHunter.forRequest(com.squareup.picasso3.BitmapHunter.forRequest) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) Test(org.junit.Test)

Example 55 with Result

use of com.squareup.picasso3.RequestHandler.Result in project picasso by square.

the class Dispatcher method performComplete.

void performComplete(BitmapHunter hunter) {
    if (shouldWriteToMemoryCache(hunter.data.memoryPolicy)) {
        Result result = hunter.getResult();
        if (result != null) {
            if (result instanceof Result.Bitmap) {
                Bitmap bitmap = ((Result.Bitmap) result).getBitmap();
                cache.set(hunter.getKey(), bitmap);
            }
        }
    }
    hunterMap.remove(hunter.getKey());
    deliver(hunter);
}
Also used : Bitmap(android.graphics.Bitmap) Result(com.squareup.picasso3.RequestHandler.Result)

Aggregations

Test (org.junit.Test)52 Bitmap (android.graphics.Bitmap)46 TestUtils.makeBitmap (com.squareup.picasso3.TestUtils.makeBitmap)44 BitmapHunter.forRequest (com.squareup.picasso3.BitmapHunter.forRequest)42 ShadowBitmap (org.robolectric.shadows.ShadowBitmap)42 Matrix (android.graphics.Matrix)31 ShadowMatrix (org.robolectric.shadows.ShadowMatrix)31 Result (com.squareup.picasso3.RequestHandler.Result)7 TestUtils.mockAction (com.squareup.picasso3.TestUtils.mockAction)6 MatrixTransformation.transformResult (com.squareup.picasso3.MatrixTransformation.transformResult)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 FakeAction (com.squareup.picasso3.TestUtils.FakeAction)2 Uri (android.net.Uri)1 Message (android.os.Message)1 IOException (java.io.IOException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ResponseBody (okhttp3.ResponseBody)1 Buffer (okio.Buffer)1