@Override void complete(RequestHandler.Result result) { if (result == null) { throw new AssertionError( String.format("Attempted to complete action with no result!\n%s", this)); } Bitmap bitmap = result.getBitmap(); if (bitmap != null) { target.onBitmapLoaded(bitmap, result.getLoadedFrom()); if (bitmap.isRecycled()) { throw new IllegalStateException("Target callback must not recycle bitmap!"); } } }
@Override public RequestHandler.Result transform(RequestHandler.Result source) { Bitmap bitmap = source.getBitmap(); if (bitmap == null) { return source; } Bitmap result = createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig()); Bitmap noise; try { noise = picasso.load(R.drawable.noise).get(); } catch (IOException e) { throw new RuntimeException("Failed to apply transformation! Missing resource."); } BitmapShader shader = new BitmapShader(noise, REPEAT, REPEAT); ColorMatrix colorMatrix = new ColorMatrix(); colorMatrix.setSaturation(0); ColorMatrixColorFilter filter = new ColorMatrixColorFilter(colorMatrix); Paint paint = new Paint(ANTI_ALIAS_FLAG); paint.setColorFilter(filter); Canvas canvas = new Canvas(result); canvas.drawBitmap(bitmap, 0, 0, paint); paint.setColorFilter(null); paint.setShader(shader); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY)); canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), paint); bitmap.recycle(); noise.recycle(); return new RequestHandler.Result(result, source.getLoadedFrom(), source.getExifRotation()); }
private void verifyActionComplete(Action action) { ArgumentCaptor<RequestHandler.Result> captor = ArgumentCaptor.forClass(RequestHandler.Result.class); verify(action).complete(captor.capture()); RequestHandler.Result result = captor.getValue(); assertThat(result.getBitmap()).isEqualTo(bitmap); assertThat(result.getLoadedFrom()).isEqualTo(MEMORY); } }
/** * Create or update the drawable on the target {@link ImageView} to display the supplied bitmap * image. */ static void setResult(ImageView target, Context context, RequestHandler.Result result, boolean noFade, boolean debugging) { Drawable placeholder = target.getDrawable(); if (placeholder instanceof Animatable) { ((Animatable) placeholder).stop(); } Bitmap bitmap = result.getBitmap(); if (bitmap != null) { Picasso.LoadedFrom loadedFrom = result.getLoadedFrom(); PicassoDrawable drawable = new PicassoDrawable(context, bitmap, placeholder, loadedFrom, noFade, debugging); target.setImageDrawable(drawable); return; } Drawable drawable = result.getDrawable(); if (drawable != null) { target.setImageDrawable(drawable); if (drawable instanceof Animatable) { ((Animatable) drawable).start(); } } }
private void deliverAction(@Nullable RequestHandler.Result result, Action action, @Nullable Exception e) { if (action.cancelled) { return; } if (!action.willReplay) { targetToAction.remove(action.getTarget()); } if (result != null) { action.complete(result); if (loggingEnabled) { log(OWNER_MAIN, VERB_COMPLETED, action.request.logId(), "from " + result.getLoadedFrom()); } } else { Exception exception = checkNotNull(e, "e == null"); action.error(exception); if (loggingEnabled) { log(OWNER_MAIN, VERB_ERRORED, action.request.logId(), exception.getMessage()); } } }
@Override public RequestHandler.Result transform(RequestHandler.Result source) { Bitmap bitmap = source.getBitmap(); if (bitmap == null) { return source; } bitmap.recycle(); return new RequestHandler.Result(result, source.getLoadedFrom(), source.getExifRotation()); }
@NonNull @Override public RequestHandler.Result transform(@NonNull RequestHandler.Result source) { Bitmap bitmap = source.getBitmap(); if (bitmap == null) { return source; } bitmap = transformResult(data, bitmap, source.getExifRotation()); return new RequestHandler.Result(bitmap, source.getLoadedFrom(), source.getExifRotation()); }
@Override void complete(RequestHandler.Result result) { assertThat(result.getBitmap()).isEqualTo(bitmap); assertThat(result.getLoadedFrom()).isEqualTo(MEMORY); }