@Test public void decodesImageThumbnailWithImageMimeType() throws Exception { Bitmap bitmap = makeBitmap(20, 20); Request request = new Request.Builder(MEDIA_STORE_CONTENT_1_URL, 0, ARGB_8888).resize(100, 100).build(); Action action = mockAction(MEDIA_STORE_CONTENT_KEY_1, request); MediaStoreRequestHandler requestHandler = create("image/png"); Bitmap result = requestHandler.load(action.getRequest(), 0).getBitmap(); assertBitmapsEqual(result, bitmap); }
@Override public Result load(Request request, int networkPolicy) throws IOException { ContentResolver contentResolver = context.getContentResolver(); int exifOrientation = getExifOrientation(contentResolver, request.uri); String mimeType = contentResolver.getType(request.uri); boolean isVideo = mimeType != null && mimeType.startsWith("video/"); if (request.hasSize()) { PicassoKind picassoKind = getPicassoKind(request.targetWidth, request.targetHeight); if (!isVideo && picassoKind == FULL) { return new Result(null, getInputStream(request), DISK, exifOrientation); } long id = parseId(request.uri); BitmapFactory.Options options = createBitmapOptions(request); options.inJustDecodeBounds = true; calculateInSampleSize(request.targetWidth, request.targetHeight, picassoKind.width, picassoKind.height, options, request); Bitmap bitmap; if (isVideo) { int kind = (picassoKind == FULL) ? Video.Thumbnails.MINI_KIND : picassoKind.androidKind; bitmap = Video.Thumbnails.getThumbnail(contentResolver, id, kind, options); } else { bitmap = Images.Thumbnails.getThumbnail(contentResolver, id, picassoKind.androidKind, options); } if (bitmap != null) { return new Result(bitmap, null, DISK, exifOrientation); } } return new Result(null, getInputStream(request), DISK, exifOrientation); }
MediaStoreRequestHandler extends ContentStreamRequestHandler { @Override public Result load(Request request, int networkPolicy) throws IOException { ContentResolver contentResolver = context.getContentResolver(); int exifOrientation = getExifOrientation(contentResolver, request.uri); String mimeType = contentResolver.getType(request.uri); boolean isVideo = mimeType != null && mimeType.startsWith("video/"); if (request.hasSize()) { PicassoKind picassoKind = getPicassoKind(request.targetWidth, request.targetHeight); if (!isVideo && picassoKind == FULL) { return new Result(null, getInputStream(request), DISK, exifOrientation); } long id = parseId(request.uri); BitmapFactory.Options options = createBitmapOptions(request); options.inJustDecodeBounds = true; calculateInSampleSize(request.targetWidth, request.targetHeight, picassoKind.width, picassoKind.height, options, request); Bitmap bitmap; if (isVideo) { int kind = (picassoKind == FULL) ? Video.Thumbnails.MINI_KIND : picassoKind.androidKind; bitmap = Video.Thumbnails.getThumbnail(contentResolver, id, kind, options); } else { bitmap = Images.Thumbnails.getThumbnail(contentResolver, id, picassoKind.androidKind, options); } if (bitmap != null) { return new Result(bitmap, null, DISK, exifOrientation); } } return new Result(null, getInputStream(request), DISK, exifOrientation); } }
MediaStoreRequestHandler extends ContentStreamRequestHandler { @Override public Result load(Request request, int networkPolicy) throws IOException { ContentResolver contentResolver = context.getContentResolver(); int exifOrientation = getExifOrientation(contentResolver, request.uri); String mimeType = contentResolver.getType(request.uri); boolean isVideo = mimeType != null && mimeType.startsWith("video/"); if (request.hasSize()) { PicassoKind picassoKind = getPicassoKind(request.targetWidth, request.targetHeight); if (!isVideo && picassoKind == FULL) { return new Result(null, getInputStream(request), DISK, exifOrientation); } long id = parseId(request.uri); BitmapFactory.Options options = createBitmapOptions(request); options.inJustDecodeBounds = true; calculateInSampleSize(request.targetWidth, request.targetHeight, picassoKind.width, picassoKind.height, options, request); Bitmap bitmap; if (isVideo) { int kind = (picassoKind == FULL) ? Video.Thumbnails.MINI_KIND : picassoKind.androidKind; bitmap = Video.Thumbnails.getThumbnail(contentResolver, id, kind, options); } else { bitmap = Images.Thumbnails.getThumbnail(contentResolver, id, picassoKind.androidKind, options); } if (bitmap != null) { return new Result(bitmap, null, DISK, exifOrientation); } } return new Result(null, getInputStream(request), DISK, exifOrientation); } MediaStoreRequestHandler(Context context); }
MediaStoreRequestHandler extends ContentStreamRequestHandler { @Override public Result load(Request request, int networkPolicy) throws IOException { ContentResolver contentResolver = context.getContentResolver(); int exifOrientation = getExifOrientation(contentResolver, request.uri); String mimeType = contentResolver.getType(request.uri); boolean isVideo = mimeType != null && mimeType.startsWith("video/"); if (request.hasSize()) { PicassoKind picassoKind = getPicassoKind(request.targetWidth, request.targetHeight); if (!isVideo && picassoKind == FULL) { return new Result(null, getInputStream(request), DISK, exifOrientation); } long id = parseId(request.uri); BitmapFactory.Options options = createBitmapOptions(request); options.inJustDecodeBounds = true; calculateInSampleSize(request.targetWidth, request.targetHeight, picassoKind.width, picassoKind.height, options, request); Bitmap bitmap; if (isVideo) { int kind = (picassoKind == FULL) ? Video.Thumbnails.MINI_KIND : picassoKind.androidKind; bitmap = Video.Thumbnails.getThumbnail(contentResolver, id, kind, options); } else { bitmap = Images.Thumbnails.getThumbnail(contentResolver, id, picassoKind.androidKind, options); } if (bitmap != null) { return new Result(bitmap, null, DISK, exifOrientation); } } return new Result(null, getInputStream(request), DISK, exifOrientation); } MediaStoreRequestHandler(Context context); @Override boolean canHandleRequest(Request data); @Override Result load(Request request, int networkPolicy); }
MediaStoreRequestHandler extends ContentStreamRequestHandler { @Override public Result load(Request request, int networkPolicy) throws IOException { ContentResolver contentResolver = context.getContentResolver(); int exifOrientation = getExifOrientation(contentResolver, request.uri); String mimeType = contentResolver.getType(request.uri); boolean isVideo = mimeType != null && mimeType.startsWith("video/"); if (request.hasSize()) { PicassoKind picassoKind = getPicassoKind(request.targetWidth, request.targetHeight); if (!isVideo && picassoKind == FULL) { return new Result(null, getInputStream(request), DISK, exifOrientation); } long id = parseId(request.uri); BitmapFactory.Options options = createBitmapOptions(request); options.inJustDecodeBounds = true; calculateInSampleSize(request.targetWidth, request.targetHeight, picassoKind.width, picassoKind.height, options, request); Bitmap bitmap; if (isVideo) { int kind = (picassoKind == FULL) ? Video.Thumbnails.MINI_KIND : picassoKind.androidKind; bitmap = Video.Thumbnails.getThumbnail(contentResolver, id, kind, options); } else { bitmap = Images.Thumbnails.getThumbnail(contentResolver, id, picassoKind.androidKind, options); } if (bitmap != null) { return new Result(bitmap, null, DISK, exifOrientation); } } return new Result(null, getInputStream(request), DISK, exifOrientation); } MediaStoreRequestHandler(Context context); @Override boolean canHandleRequest(Request data); @Override Result load(Request request, int networkPolicy);  }