Search in sources :

Example 6 with Result

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

the class BitmapHunterTest method onlyScaleDownOriginalSmaller.

@Test
public void onlyScaleDownOriginalSmaller() {
    Bitmap source = Bitmap.createBitmap(50, 50, ARGB_8888);
    Request data = new Request.Builder(URI_1).resize(100, 100).onlyScaleDown().build();
    Bitmap result = transformResult(data, source, 0);
    assertThat(result).isSameInstanceAs(source);
    ShadowBitmap shadowBitmap = shadowOf(result);
    assertThat(shadowBitmap.getCreatedFromBitmap()).isNull();
    assertThat(shadowBitmap.getCreatedFromBitmap()).isNotSameInstanceAs(source);
}
Also used : TestUtils.makeBitmap(com.squareup.picasso3.TestUtils.makeBitmap) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Bitmap(android.graphics.Bitmap) BitmapHunter.forRequest(com.squareup.picasso3.BitmapHunter.forRequest) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Test(org.junit.Test)

Example 7 with Result

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

the class BitmapHunterTest method rotation90Sizing.

@Test
public void rotation90Sizing() {
    Request data = new Request.Builder(URI_1).rotate(90).resize(5, 10).build();
    Bitmap source = Bitmap.createBitmap(10, 10, ARGB_8888);
    Bitmap result = transformResult(data, source, 0);
    ShadowBitmap shadowBitmap = shadowOf(result);
    assertThat(shadowBitmap.getCreatedFromBitmap()).isSameInstanceAs(source);
    Matrix matrix = shadowBitmap.getCreatedFromMatrix();
    ShadowMatrix shadowMatrix = shadowOf(matrix);
    assertThat(shadowMatrix.getPreOperations()).contains("scale 1.0 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 8 with Result

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

the class PicassoTest method resumeActionImmediatelyCompletesCachedRequest.

@Test
public void resumeActionImmediatelyCompletesCachedRequest() {
    cache.set(URI_KEY_1, bitmap);
    Request request = new Request.Builder(URI_1, 0, ARGB_8888).build();
    Action action = new Action(mockPicasso(), request) {

        @Override
        public void complete(RequestHandler.Result result) {
            assertThat(result).isInstanceOf(RequestHandler.Result.Bitmap.class);
            RequestHandler.Result.Bitmap bitmapResult = (RequestHandler.Result.Bitmap) result;
            assertThat(bitmapResult.getBitmap()).isEqualTo(bitmap);
            assertThat(bitmapResult.loadedFrom).isEqualTo(MEMORY);
        }

        @Override
        public void error(Exception e) {
            fail("Reading from memory cache should not throw an exception");
        }

        @NonNull
        @Override
        public Object getTarget() {
            return this;
        }
    };
    picasso.resumeAction(action);
}
Also used : FakeAction(com.squareup.picasso3.TestUtils.FakeAction) TestUtils.mockAction(com.squareup.picasso3.TestUtils.mockAction) TestUtils.makeBitmap(com.squareup.picasso3.TestUtils.makeBitmap) Bitmap(android.graphics.Bitmap) Test(org.junit.Test)

Example 9 with Result

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

the class Picasso method complete.

void complete(BitmapHunter hunter) {
    Action single = hunter.getAction();
    List<Action> joined = hunter.getActions();
    boolean hasMultiple = joined != null && !joined.isEmpty();
    boolean shouldDeliver = single != null || hasMultiple;
    if (!shouldDeliver) {
        return;
    }
    Uri uri = checkNotNull(hunter.data.uri, "uri == null");
    Exception exception = hunter.getException();
    Result result = hunter.getResult();
    if (single != null) {
        deliverAction(result, single, exception);
    }
    if (joined != null) {
        // noinspection ForLoopReplaceableByForEach
        for (int i = 0, n = joined.size(); i < n; i++) {
            Action join = joined.get(i);
            deliverAction(result, join, exception);
        }
    }
    if (listener != null && exception != null) {
        listener.onImageLoadFailed(this, uri, exception);
    }
}
Also used : Uri(android.net.Uri) IOException(java.io.IOException) Result(com.squareup.picasso3.RequestHandler.Result)

Example 10 with Result

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

the class BitmapHunterTest method exifTranspose.

@Test
public void exifTranspose() {
    Request data = new Request.Builder(URI_1).rotate(-45).build();
    Bitmap source = Bitmap.createBitmap(10, 10, ARGB_8888);
    Bitmap result = transformResult(data, source, ORIENTATION_TRANSPOSE);
    ShadowBitmap shadowBitmap = shadowOf(result);
    assertThat(shadowBitmap.getCreatedFromBitmap()).isSameInstanceAs(source);
    Matrix matrix = shadowBitmap.getCreatedFromMatrix();
    ShadowMatrix shadowMatrix = shadowOf(matrix);
    assertThat(shadowMatrix.getPostOperations()).containsExactly("scale -1.0 1.0");
    assertThat(shadowMatrix.getPreOperations()).containsExactly("rotate 90.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)

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