/** * Asynchronously fulfills the request into the specified {@link ImageView}. * <p> * <em>Note:</em> This method will automatically support object recycling. */ public void into(@NonNull ImageView target) { into(target, null); }
/** * Asynchronously fulfills the request into the specified {@link RemoteViews} object with the * given {@code viewId}. This is used for loading bitmaps into a {@link Notification}. */ public void into(@NonNull RemoteViews remoteViews, @IdRes int viewId, int notificationId, @NonNull Notification notification) { into(remoteViews, viewId, notificationId, notification, null); }
/** * Asynchronously fulfills the request into the specified {@link RemoteViews} object with the * given {@code viewId}. This is used for loading bitmaps into a {@link Notification}. */ public void into(@NonNull RemoteViews remoteViews, @IdRes int viewId, int notificationId, @NonNull Notification notification, @Nullable String notificationTag) { into(remoteViews, viewId, notificationId, notification, notificationTag, null); }
/** * Asynchronously fulfills the request into the specified {@link RemoteViews} object with the * given {@code viewId}. This is used for loading bitmaps into all instances of a widget. */ public void into(@NonNull RemoteViews remoteViews, @IdRes int viewId, int appWidgetId, @Nullable Callback callback) { into(remoteViews, viewId, new int[] { appWidgetId }, callback); }
@Test public void intoImageViewWithFitAndNoDimensionsQueuesDeferredImageViewRequest() { ImageView target = mockFitImageViewTarget(true); when(target.getWidth()).thenReturn(0); when(target.getHeight()).thenReturn(0); new RequestCreator(picasso, URI_1, 0).fit().into(target); verify(picasso, never()).enqueueAndSubmit(any(Action.class)); verify(picasso).defer(eq(target), any(DeferredRequestCreator.class)); }
@Test public void intoImageViewWithFitAndDimensionsQueuesImageViewRequest() { ImageView target = mockFitImageViewTarget(true); when(target.getWidth()).thenReturn(100); when(target.getHeight()).thenReturn(100); new RequestCreator(picasso, URI_1, 0).fit().into(target); verify(picasso).enqueueAndSubmit(actionCaptor.capture()); assertThat(actionCaptor.getValue()).isInstanceOf(ImageViewAction.class); }
private void loadImage() { // Index 1 is the progress bar. Show it while we're loading the image. animator.setDisplayedChild(1); PicassoProvider.get().load(image).fit().centerInside().into(imageView, new EmptyCallback() { @Override public void onSuccess() { // Index 0 is the image view. animator.setDisplayedChild(0); } }); } }
@Test public void intoImageViewWithNullUriAndResourceIdSkipsAndCancels() { ImageView target = mockImageViewTarget(); new RequestCreator(picasso, null, 0).into(target); verify(picasso).cancelRequest(target); verify(picasso, never()).quickMemoryCacheCheck(anyString()); verify(picasso, never()).enqueueAndSubmit(any(Action.class)); }
@Test public void intoTargetWithQuickMemoryCacheCheckDoesNotSubmit() { when(picasso.quickMemoryCacheCheck(URI_KEY_1)).thenReturn(bitmap); BitmapTarget target = mockTarget(); new RequestCreator(picasso, URI_1, 0).into(target); verify(target).onBitmapLoaded(bitmap, MEMORY); verify(picasso).cancelRequest(target); verify(picasso, never()).enqueueAndSubmit(any(Action.class)); }
@Test public void targetActionWithDefaultTag() { new RequestCreator(picasso, URI_1, 0).into(mockTarget()); verify(picasso).enqueueAndSubmit(actionCaptor.capture()); assertThat(actionCaptor.getValue().getTag()).isEqualTo(actionCaptor.getValue()); }
@Test public void intoRemoteViewsNotificationQueuesNotificationAction() { new RequestCreator(picasso, URI_1, 0).into(mockRemoteViews(), 0, 0, mockNotification()); verify(picasso).enqueueAndSubmit(actionCaptor.capture()); assertThat(actionCaptor.getValue()).isInstanceOf(NotificationAction.class); }
@Test public void notificationActionWithDefaultPriority() { new RequestCreator(picasso, URI_1, 0).into(mockRemoteViews(), 0, 0, mockNotification()); verify(picasso).enqueueAndSubmit(actionCaptor.capture()); assertThat(actionCaptor.getValue().request.priority).isEqualTo(NORMAL); }
@Test public void imageViewActionWithStableKey() { new RequestCreator(picasso, URI_1, 0).stableKey(STABLE_1).into(mockImageViewTarget()); verify(picasso).enqueueAndSubmit(actionCaptor.capture()); assertThat(actionCaptor.getValue().request.key).isEqualTo(STABLE_URI_KEY_1); }
@Test public void notificationActionWithDefaultTag() { new RequestCreator(picasso, URI_1, 0).into(mockRemoteViews(), 0, 0, mockNotification()); verify(picasso).enqueueAndSubmit(actionCaptor.capture()); assertThat(actionCaptor.getValue().getTag()).isEqualTo(actionCaptor.getValue()); }
@Test public void intoTargetWithNullUriAndResourceIdSkipsAndCancels() { BitmapTarget target = mockTarget(); Drawable placeHolderDrawable = mock(Drawable.class); new RequestCreator(picasso, null, 0).placeholder(placeHolderDrawable).into(target); verify(picasso).cancelRequest(target); verify(target).onPrepareLoad(placeHolderDrawable); verifyNoMoreInteractions(picasso); }
@Test public void imageViewActionWithStableKeyNull() { new RequestCreator(picasso, URI_1, 0).stableKey(null).into(mockImageViewTarget()); verify(picasso).enqueueAndSubmit(actionCaptor.capture()); assertThat(actionCaptor.getValue().request.key).isEqualTo(URI_KEY_1); }
@Test public void intoRemoteViewsWidgetWithNullRemoteViewsThrows() { try { new RequestCreator(picasso, URI_1, 0).into(null, 0, new int[] { 1, 2, 3 }); fail("Calling into() with null RemoteViews should throw exception"); } catch (IllegalArgumentException ignored) { } }
@Test public void intoRemoteViewsNotificationWithPlaceholderDrawableThrows() { try { new RequestCreator(picasso, URI_1, 0).placeholder(new ColorDrawable(0)) .into(mockRemoteViews(), 0, 0, mockNotification()); fail("Calling into() with error drawable should throw exception"); } catch (IllegalArgumentException ignored) { } }
@Test public void intoTargetWithFitThrows() { try { BitmapTarget target = mockTarget(); new RequestCreator(picasso, URI_1, 0).fit().into(target); fail("Calling into() target with fit() should throw exception"); } catch (IllegalStateException ignored) { } }
@Test public void intoImageViewWithFitAndResizeThrows() { try { ImageView target = mockImageViewTarget(); new RequestCreator(picasso, URI_1, 0).fit().resize(10, 10).into(target); fail("Calling into() ImageView with fit() and resize() should throw exception"); } catch (IllegalStateException ignored) { } }