public Drawable getImageOnLoading(Resources res) { return imageResOnLoading != 0 ? res.getDrawable(imageResOnLoading) : imageOnLoading; }
public Drawable getImageForEmptyUri(Resources res) { return imageResForEmptyUri != 0 ? res.getDrawable(imageResForEmptyUri) : imageForEmptyUri; }
public Drawable getImageOnFail(Resources res) { return imageResOnFail != 0 ? res.getDrawable(imageResOnFail) : imageOnFail; }
Resources r = getResources(); Drawable[] layers = new Drawable[2]; layers[0] = r.getDrawable(R.drawable.t); layers[1] = r.getDrawable(R.drawable.tt); LayerDrawable layerDrawable = new LayerDrawable(layers); testimage.setImageDrawable(layerDrawable);
/** * Constructor. Sets up the MarkerView with a custom layout resource. * * @param context * @param drawableResourceId the drawable resource to render */ public MarkerImage(Context context, int drawableResourceId) { mContext = context; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mDrawable = mContext.getResources().getDrawable(drawableResourceId, null); } else { mDrawable = mContext.getResources().getDrawable(drawableResourceId); } }
@Override public MenuItem setIcon(int iconRes) { this.icon = iconRes == 0 ? null : context.getResources().getDrawable(iconRes); return this; }
@TargetApi(23) private static void configureEditModeLogoV23(Resources resources, ImageView logo) { logo.setImageDrawable(resources.getDrawable(R.drawable.exo_edit_mode_logo, null)); logo.setBackgroundColor(resources.getColor(R.color.exo_edit_mode_background_color, null)); }
@SuppressWarnings("deprecation") private static void configureEditModeLogo(Resources resources, ImageView logo) { logo.setImageDrawable(resources.getDrawable(R.drawable.exo_edit_mode_logo)); logo.setBackgroundColor(resources.getColor(R.color.exo_edit_mode_background_color)); }
private LoadingImageGetter(final Context context, @DimenRes final int size) { int imageSize = context.getResources().getDimensionPixelSize(size); image = context.getResources().getDrawable( R.drawable.image_loading_icon); image.setBounds(0, 0, imageSize, imageSize); }
@Test public void shouldCreateAnimsAndColors() throws Exception { assertThat(resources.getDrawable(R.color.grey42)).isInstanceOf((Class<? extends android.graphics.drawable.Drawable>) ColorDrawable.class); } }
@Test @Config(qualifiers = "hdpi") public void drawableShouldLoadImageOfCorrectSizeWithHdpiQualifier() { final Drawable anImage = context.getResources().getDrawable(R.drawable.robolectric); assertThat(anImage.getIntrinsicHeight()).isEqualTo(251); assertThat(anImage.getIntrinsicWidth()).isEqualTo(297); }
@Test public void drawableIntrinsicWidthAndHeightShouldBeCorrect() { final Drawable anImage = context.getResources().getDrawable(R.drawable.an_image); assertThat(anImage.getIntrinsicHeight()).isEqualTo(53); assertThat(anImage.getIntrinsicWidth()).isEqualTo(64); }
@Test @Config(maxSdk = KITKAT_WATCH) public void testGetBitmapOrVectorDrawableAt19() { // at API 21+ and mdpi, the drawable-anydpi-v21/image_or_vector.xml should be loaded instead // of drawable/image_or_vector.png final Drawable aDrawable = context.getResources().getDrawable(R.drawable.an_image_or_vector); assertThat(aDrawable).isInstanceOf(BitmapDrawable.class); }
@Test public void testGetDrawable_rainbow() throws Exception { assertNotNull( ApplicationProvider.getApplicationContext().getResources().getDrawable(R.drawable.rainbow)); }
@Test @Config(qualifiers = "land") public void testLayerDrawable_xlarge() { assertEquals( 6, ((LayerDrawable) ApplicationProvider.getApplicationContext() .getResources() .getDrawable(R.drawable.rainbow)) .getNumberOfLayers()); }
@Test public void getBitmap_shouldReturnBitmapUsedToDraw() throws Exception { BitmapDrawable drawable = (BitmapDrawable) resources.getDrawable(R.drawable.an_image); assertThat(shadowOf(drawable.getBitmap()).getDescription()).isEqualTo("Bitmap for resource:org.robolectric:drawable/an_image"); }
@Test public void getIcon_shouldReturnDrawableFromSetIconDrawable() throws Exception { Drawable testDrawable = ApplicationProvider.getApplicationContext().getResources().getDrawable(R.drawable.an_image); assertThat(testDrawable).isNotNull(); assertThat(item.getIcon()).isNull(); item.setIcon(testDrawable); assertThat(item.getIcon()).isSameAs(testDrawable); }
@Test public void testLayerDrawable() { assertEquals( 8, ((LayerDrawable) ApplicationProvider.getApplicationContext() .getResources() .getDrawable(R.drawable.rainbow)) .getNumberOfLayers()); }
@Test public void draw_shouldCopyDescriptionToCanvas() throws Exception { BitmapDrawable drawable = (BitmapDrawable) resources.getDrawable(R.drawable.an_image); Canvas canvas = new Canvas(); drawable.draw(canvas); assertThat(shadowOf(canvas).getDescription()).isEqualTo("Bitmap for resource:org.robolectric:drawable/an_image"); }
@Test public void asDrawable() { Target target = new Target(); Drawable expected = context.getResources().getDrawable(R.drawable.circle); Unbinder unbinder = new BindDrawableTest$Target_ViewBinding(target, context); assertThat(target.actual.getConstantState()).isEqualTo(expected.getConstantState()); unbinder.unbind(); assertThat(target.actual.getConstantState()).isEqualTo(expected.getConstantState()); } }