public static Bitmap create(String name, BitmapFactory.Options options) { return create(name, options, null); }
static Bitmap create(String name) { return create(name, null); }
@Implementation protected static Bitmap getBitmap(ContentResolver cr, Uri url) { return ShadowBitmapFactory.create(url.toString()); } }
@Implementation protected static Bitmap decodeByteArray( byte[] data, int offset, int length, BitmapFactory.Options opts) { String desc = new String(data, UTF_8); if (offset != 0 || length != data.length) { desc += " bytes " + offset + ".." + length; } Point imageSize = getImageSizeFromStream(new ByteArrayInputStream(data, offset, length)); return create(desc, opts, imageSize); }
@Implementation protected static Bitmap decodeFile(String pathName, BitmapFactory.Options options) { Bitmap bitmap = create("file:" + pathName, options); ShadowBitmap shadowBitmap = Shadow.extract(bitmap); shadowBitmap.createdFromPath = pathName; return bitmap; }
@SuppressWarnings("ObjectToString") @Implementation protected static Bitmap decodeFileDescriptor( FileDescriptor fd, Rect outPadding, BitmapFactory.Options opts) { Bitmap bitmap = create("fd:" + fd, opts); ShadowBitmap shadowBitmap = Shadow.extract(bitmap); shadowBitmap.createdFromFileDescriptor = fd; return bitmap; }
@Implementation protected static Bitmap decodeResource(Resources res, int id, BitmapFactory.Options options) { if (id == 0) { return null; } final TypedValue value = new TypedValue(); InputStream is = res.openRawResource(id, value); Point imageSizeFromStream = getImageSizeFromStream(is); Bitmap bitmap = create("resource:" + res.getResourceName(id), options, imageSizeFromStream); ShadowBitmap shadowBitmap = Shadow.extract(bitmap); shadowBitmap.createdFromResId = id; return bitmap; }
@Test public void createShouldSetSizeToParameterAsSecondPriority() { final Bitmap bitmap = ShadowBitmapFactory.create(null, null, new Point(70, 80)); assertThat(bitmap.getWidth()).isEqualTo(70); assertThat(bitmap.getHeight()).isEqualTo(80); }
@Test public void createShouldSetSizeToHardcodedValueAsLastPriority() { final Bitmap bitmap = ShadowBitmapFactory.create(null, null, null); assertThat(bitmap.getWidth()).isEqualTo(100); assertThat(bitmap.getHeight()).isEqualTo(100); } }
@Test public void decodeWithDifferentSampleSize() { String name = "test"; BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 0; Bitmap bm = ShadowBitmapFactory.create(name, options); assertThat(bm.getWidth()).isEqualTo(100); assertThat(bm.getHeight()).isEqualTo(100); options.inSampleSize = 2; bm = ShadowBitmapFactory.create(name, options); assertThat(bm.getWidth()).isEqualTo(50); assertThat(bm.getHeight()).isEqualTo(50); options.inSampleSize = 101; bm = ShadowBitmapFactory.create(name, options); assertThat(bm.getWidth()).isEqualTo(1); assertThat(bm.getHeight()).isEqualTo(1); }
@Test public void createShouldSetSizeToValueFromMapAsFirstPriority() { ShadowBitmapFactory.provideWidthAndHeightHints("image.png", 111, 222); final Bitmap bitmap = ShadowBitmapFactory.create("file:image.png", null, new Point(50, 60)); assertThat(bitmap.getWidth()).isEqualTo(111); assertThat(bitmap.getHeight()).isEqualTo(222); }
@Implementation protected static Bitmap decodeStream( InputStream is, Rect outPadding, BitmapFactory.Options opts) { byte[] ninePatchChunk = null; if (is instanceof AssetInputStream) { ShadowAssetInputStream sais = Shadow.extract(is); if (sais.isNinePatch()) { ninePatchChunk = new byte[0]; } if (sais.getDelegate() != null) { is = sais.getDelegate(); } } try { if (is != null) { is.reset(); } } catch (IOException e) { // ignore } String name = (is instanceof NamedStream) ? is.toString().replace("stream for ", "") : null; Point imageSize = (is instanceof NamedStream) ? null : getImageSizeFromStream(is); Bitmap bitmap = create(name, opts, imageSize); bitmap.setNinePatchChunk(ninePatchChunk); ShadowBitmap shadowBitmap = Shadow.extract(bitmap); shadowBitmap.createdFromStream = is; return bitmap; }
@Implementation protected static Bitmap getBitmap(ContentResolver cr, Uri url) { return ShadowBitmapFactory.create(url.toString()); } }
@Implementation public static Bitmap getBitmap(ContentResolver cr, Uri url) { return ShadowBitmapFactory.create(url.toString()); } }
@Implementation public static Bitmap decodeFile(String pathName, BitmapFactory.Options options) { Bitmap bitmap = create("file:" + pathName, options); ShadowBitmap shadowBitmap = Shadows.shadowOf(bitmap); shadowBitmap.createdFromPath = pathName; return bitmap; }
@Implementation public static Bitmap decodeFileDescriptor(FileDescriptor fd, Rect outPadding, BitmapFactory.Options opts) { Bitmap bitmap = create("fd:" + fd, opts); ShadowBitmap shadowBitmap = Shadows.shadowOf(bitmap); shadowBitmap.createdFromFileDescriptor = fd; return bitmap; }
@SuppressWarnings("ObjectToString") @Implementation protected static Bitmap decodeFileDescriptor( FileDescriptor fd, Rect outPadding, BitmapFactory.Options opts) { Bitmap bitmap = create("fd:" + fd, opts); ShadowBitmap shadowBitmap = Shadow.extract(bitmap); shadowBitmap.createdFromFileDescriptor = fd; return bitmap; }
@Implementation public static Bitmap decodeFile(String pathName, BitmapFactory.Options options) { Bitmap bitmap = create("file:" + pathName, options); ShadowBitmap shadowBitmap = Shadows.shadowOf(bitmap); shadowBitmap.createdFromPath = pathName; return bitmap; }
@Implementation public static Bitmap decodeResource(Resources res, int id, BitmapFactory.Options options) { if (id == 0) { return null; } Bitmap bitmap = create("resource:" + RuntimeEnvironment.application.getResources().getResourceName(id), options); Shadows.shadowOf(bitmap).createdFromResId = id; return bitmap; }
@Implementation public static Bitmap decodeResource(Resources res, int id, BitmapFactory.Options options) { if (id == 0) { return null; } Bitmap bitmap = create("resource:" + RuntimeEnvironment.application.getResources().getResourceName(id), options); Shadows.shadowOf(bitmap).createdFromResId = id; return bitmap; }