/** * 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, @Nullable Callback callback) { long started = System.nanoTime(); if (remoteViews == null) { throw new IllegalArgumentException("RemoteViews must not be null."); } if (notification == null) { throw new IllegalArgumentException("Notification must not be null."); } if (deferred) { throw new IllegalStateException("Fit cannot be used with RemoteViews."); } if (placeholderDrawable != null || errorDrawable != null) { throw new IllegalArgumentException( "Cannot use placeholder or error drawables with remote views."); } Request request = createRequest(started); RemoteViewsAction action = new NotificationAction(picasso, request, errorResId, new RemoteViewsTarget(remoteViews, viewId), notificationId, notification, notificationTag, callback); performRemoteViewInto(request, action); }
/** * 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, @NonNull int[] appWidgetIds, @Nullable Callback callback) { long started = System.nanoTime(); if (remoteViews == null) { throw new IllegalArgumentException("remoteViews must not be null."); } if (appWidgetIds == null) { throw new IllegalArgumentException("appWidgetIds must not be null."); } if (deferred) { throw new IllegalStateException("Fit cannot be used with remote views."); } if (placeholderDrawable != null || errorDrawable != null) { throw new IllegalArgumentException( "Cannot use placeholder or error drawables with remote views."); } Request request = createRequest(started); RemoteViewsAction action = new AppWidgetAction(picasso, request, errorResId, new RemoteViewsTarget(remoteViews, viewId), appWidgetIds, callback); performRemoteViewInto(request, action); }
/** * Cancel any existing requests for the specified {@link RemoteViews} target with the given {@code * viewId}. */ public void cancelRequest(@NonNull RemoteViews remoteViews, @IdRes int viewId) { // checkMain() is called from cancelExistingRequest() checkNotNull(remoteViews, "remoteViews == null"); cancelExistingRequest(new RemoteViewsAction.RemoteViewsTarget(remoteViews, viewId)); }
@Config(sdk = 16) // This test fails on 23 so restore the default level. @Test public void cancelExistingRequestWithRemoteViewTarget() { int layoutId = 0; int viewId = 1; RemoteViews remoteViews = new RemoteViews("packageName", layoutId); RemoteViewsTarget target = new RemoteViewsTarget(remoteViews, viewId); Action action = mockAction(URI_KEY_1, URI_1, target); picasso.enqueueAndSubmit(action); assertThat(picasso.targetToAction).hasSize(1); picasso.cancelRequest(remoteViews, viewId); assertThat(picasso.targetToAction).isEmpty(); verify(action).cancel(); verify(dispatcher).dispatchCancel(action); }
private TestableRemoteViewsAction createAction(int errorResId, Callback callback) { return new TestableRemoteViewsAction(picasso, null, errorResId, new RemoteViewsTarget(remoteViews, 1), callback); }