public Check(Context context) { super(context); setBackgroundResource(R.drawable.background_checkbox_uncheck); sprite = BitmapFactory.decodeResource(context.getResources(), R.drawable.sprite_check); }
private static @Nullable Unbinder parseBindBitmap(Object target, Field field, View source) { BindBitmap bindBitmap = field.getAnnotation(BindBitmap.class); if (bindBitmap == null) { return null; } validateMember(field); int id = bindBitmap.value(); Resources resources = source.getContext().getResources(); Object value; Class<?> fieldType = field.getType(); if (fieldType == Bitmap.class) { value = BitmapFactory.decodeResource(resources, id); } else { throw new IllegalStateException(); // TODO } trySet(field, target, value); return Unbinder.EMPTY; }
private static Bitmap decodeResourcePreP(Resources resources, int id, Request request) { final BitmapFactory.Options options = createBitmapOptions(request); if (requiresInSampleSize(options)) { BitmapFactory.decodeResource(resources, id, options); calculateInSampleSize(request.targetWidth, request.targetHeight, checkNotNull(options, "options == null"), request); } return BitmapFactory.decodeResource(resources, id, options); }
@Before public void setUp() { Resources resources = ApplicationProvider.getApplicationContext().getResources(); drawable1000 = new BitmapDrawable(BitmapFactory.decodeResource(resources, R.drawable.an_image)); drawable2000 = new BitmapDrawable(BitmapFactory.decodeResource(resources, R.drawable.an_other_image)); drawable3000 = new BitmapDrawable(BitmapFactory.decodeResource(resources, R.drawable.third_image)); drawable4000 = new BitmapDrawable(BitmapFactory.decodeResource(resources, R.drawable.fourth_image)); drawables = new Drawable[]{drawable1000, drawable2000, drawable3000}; }
private Bitmap decodeExpected() { int resourceId = context.getResources() .getIdentifier(getResourceName(), RESOURCE_TYPE, context.getPackageName()); if (resourceId == 0) { throw new IllegalArgumentException("Failed to find resource for: " + getResourceName() + " with type: " + RESOURCE_TYPE + " and package: " + context.getPackageName()); } BitmapFactory.Options options = new BitmapFactory.Options(); options.inScaled = false; return BitmapFactory.decodeResource(context.getResources(), resourceId, options); } }
private Bitmap decodeBitmap() { Context context = InstrumentationRegistry.getTargetContext(); BitmapFactory.Options options = new BitmapFactory.Options(); options.inScaled = false; int resourceId = ResourceIds.raw.canonical; Bitmap result = BitmapFactory.decodeResource(context.getResources(), resourceId, options); if (scaleFactor != null) { result = Bitmap.createScaledBitmap( result, (int) (result.getWidth() * scaleFactor), (int) (result.getHeight() * scaleFactor), /*filter=*/false); } // Make sure the Bitmap is immutable. return result; } }
private void drawNinepath(Canvas canvas, int resId, Rect rect) { Bitmap bmp = BitmapFactory.decodeResource(getResources(), resId); NinePatch patch = new NinePatch(bmp, bmp.getNinePatchChunk(), null); patch.draw(canvas, rect); }
@Test public void loadBitmapDrawable_asBytes_providesBytesOfBitmap() { Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), ResourceIds.raw.canonical); byte[] data = concurrency.get( Glide.with(context) .as(byte[].class) .load(new BitmapDrawable(context.getResources(), bitmap)) .submit()); assertThat(data).isNotNull(); assertThat(BitmapFactory.decodeByteArray(data, 0, data.length)).isNotNull(); }
@Test public void loadBitmap_asBytes_providesBytesOfBitmap() { Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), ResourceIds.raw.canonical); byte[] data = concurrency.get( Glide.with(context) .as(byte[].class) .load(bitmap) .submit()); assertThat(data).isNotNull(); assertThat(BitmapFactory.decodeByteArray(data, 0, data.length)).isNotNull(); }
@Test public void decodeResource_canTakeOptions() { BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 100; Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.an_image, options); assertEquals(true, shadowOf(bitmap).getDescription().contains("inSampleSize=100")); }
@Test public void transform_withLoadedBitmapDrawable_doesNotRecycleBitmap() { Glide.init( context, glideBuilder .setMemoryCache(new MemoryCacheAdapter()) .setBitmapPool(new BitmapPoolAdapter())); Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), ResourceIds.raw.canonical); BitmapDrawable drawable = new BitmapDrawable(context.getResources(), bitmap); concurrency.wait( GlideApp.with(context) .load(drawable) .centerCrop() .submit(100, 100)); assertThat(bitmap.isRecycled()).isFalse(); }
@Test public void asBitmap() { Target target = new Target(); Bitmap expected = BitmapFactory.decodeResource(context.getResources(), R.drawable.pixel); Unbinder unbinder = new BindBitmapTest$Target_ViewBinding(target, context); assertTrue(target.actual.sameAs(expected)); unbinder.unbind(); assertTrue(target.actual.sameAs(expected)); } }
@Test public void decodeResource_shouldGetWidthAndHeightFromHints() { ShadowBitmapFactory.provideWidthAndHeightHints(R.drawable.an_image, 123, 456); Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.an_image); assertEquals("Bitmap for resource:org.robolectric:drawable/an_image", shadowOf(bitmap).getDescription()); assertEquals(123, bitmap.getWidth()); assertEquals(456, bitmap.getHeight()); }
@Test public void decodeResource_shouldSetDescriptionAndCreatedFrom() { Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.an_image); ShadowBitmap shadowBitmap = shadowOf(bitmap); assertEquals("Bitmap for resource:org.robolectric:drawable/an_image", shadowBitmap.getDescription()); assertEquals(R.drawable.an_image, shadowBitmap.getCreatedFromResId()); assertEquals(64, bitmap.getWidth()); assertEquals(53, bitmap.getHeight()); }
@Test public void transformFromRequestManager_withLoadedBitmap_doesNotRecycleBitmap() { Glide.init( context, new GlideBuilder() .setMemoryCache(new MemoryCacheAdapter()) .setBitmapPool(new BitmapPoolAdapter())); Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), ResourceIds.raw.canonical); concurrency.wait( GlideApp.with(context) .load(bitmap) .centerCrop() .submit(100, 100)); assertThat(bitmap.isRecycled()).isFalse(); }
@Test public void clearFromRequestManager_withLoadedBitmap_doesNotRecycleBitmap() { Glide.init( context, new GlideBuilder() .setMemoryCache(new MemoryCacheAdapter()) .setBitmapPool(new BitmapPoolAdapter())); Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), ResourceIds.raw.canonical); Target<Drawable> target = concurrency.wait( GlideApp.with(context) .load(bitmap) .submit(100, 100)); Glide.with(context).clear(target); // Allow Glide's resource recycler to run on the main thread. concurrency.pokeMainThread(); assertThat(bitmap.isRecycled()).isFalse(); }
@Test public void clearFromRequestBuilder_withLoadedBitmap_asBitmap_doesNotRecycleBitmap() { Glide.init( context, new GlideBuilder() .setMemoryCache(new MemoryCacheAdapter()) .setBitmapPool(new BitmapPoolAdapter())); Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), ResourceIds.raw.canonical); Target<Bitmap> target = concurrency.wait( GlideApp.with(context) .asBitmap() .load(bitmap) .submit(100, 100)); Glide.with(context).clear(target); // Allow Glide's resource recycler to run on the main thread. concurrency.pokeMainThread(); assertThat(bitmap.isRecycled()).isFalse(); }
@Test public void transformFromRequestBuilder_withLoadedBitmap_asBitmap_doesNotRecycleBitmap() { Glide.init( context, new GlideBuilder() .setMemoryCache(new MemoryCacheAdapter()) .setBitmapPool(new BitmapPoolAdapter())); Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), ResourceIds.raw.canonical); concurrency.wait( GlideApp.with(context) .asBitmap() .load(bitmap) .centerCrop() .submit(100, 100)); assertThat(bitmap.isRecycled()).isFalse(); }
@Test public void clearFromRequestBuilder_asDrawable_withLoadedBitmap_doesNotRecycleBitmap() { Glide.init( context, new GlideBuilder() .setMemoryCache(new MemoryCacheAdapter()) .setBitmapPool(new BitmapPoolAdapter())); Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), ResourceIds.raw.canonical); Target<Drawable> target = concurrency.wait( GlideApp.with(context) .asDrawable() .load(bitmap) .submit(100, 100)); Glide.with(context).clear(target); // Allow Glide's resource recycler to run on the main thread. concurrency.pokeMainThread(); assertThat(bitmap.isRecycled()).isFalse(); }
@Test public void transformFromRequestBuilder_asDrawable_withLoadedBitmap_doesNotRecycleBitmap() { Glide.init( context, new GlideBuilder() .setMemoryCache(new MemoryCacheAdapter()) .setBitmapPool(new BitmapPoolAdapter())); Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), ResourceIds.raw.canonical); concurrency.wait( GlideApp.with(context) .asDrawable() .load(bitmap) .centerCrop() .submit(100, 100)); assertThat(bitmap.isRecycled()).isFalse(); }