本文整理了Java中android.app.Application.getResources()
方法的一些代码示例,展示了Application.getResources()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Application.getResources()
方法的具体详情如下:
包路径:android.app.Application
类名称:Application
方法名:getResources
暂无
代码示例来源:origin: Tencent/tinker
@Override
public Resources getResources() {
Resources resources = super.getResources();
if (applicationLike != null) {
return invokeAppLikeGetResources(applicationLike, resources);
}
return resources;
}
代码示例来源:origin: bumptech/glide
BitmapDrawableResource create() {
return new BitmapDrawableResource(
new BitmapDrawable(RuntimeEnvironment.application.getResources(), bitmap), bitmapPool);
}
}
代码示例来源:origin: bumptech/glide
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
when(bitmapResource.get()).thenReturn(bitmap);
resources = RuntimeEnvironment.application.getResources();
resource =
(LazyBitmapDrawableResource) LazyBitmapDrawableResource.obtain(resources, bitmapResource);
}
代码示例来源:origin: robolectric/robolectric
@Test
@Config(minSdk = LOLLIPOP)
public void testGetBitmapOrVectorDrawableAt21() {
final Drawable aDrawable = context.getResources().getDrawable(R.drawable.an_image_or_vector);
assertThat(aDrawable).isInstanceOf(VectorDrawable.class);
}
代码示例来源:origin: robolectric/robolectric
@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);
}
代码示例来源:origin: robolectric/robolectric
@Test
@Config(qualifiers = "mdpi")
public void drawableShouldLoadImageOfCorrectSizeWithMdpiQualifier() {
final Drawable anImage = context.getResources().getDrawable(R.drawable.robolectric);
assertThat(anImage.getIntrinsicHeight()).isEqualTo(167);
assertThat(anImage.getIntrinsicWidth()).isEqualTo(198);
}
代码示例来源:origin: robolectric/robolectric
@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);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void drawableIntrinsicWidthAndHeightShouldBeCorrect() {
final Drawable anImage = context.getResources().getDrawable(R.drawable.an_image);
assertThat(anImage.getIntrinsicHeight()).isEqualTo(53);
assertThat(anImage.getIntrinsicWidth()).isEqualTo(64);
}
代码示例来源:origin: bumptech/glide
@Before
public void setUp() {
transcoder = new BitmapDrawableTranscoder(RuntimeEnvironment.application.getResources());
}
代码示例来源:origin: bumptech/glide
@Test
public void testReturnsTargetForBitmapDrawables() {
BitmapDrawable drawable = new BitmapDrawable(RuntimeEnvironment.application.getResources(),
Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_4444));
Target<BitmapDrawable> target = factory.buildTarget(view, BitmapDrawable.class);
target.onResourceReady(drawable, null);
assertThat(target).isInstanceOf(DrawableImageViewTarget.class);
}
代码示例来源:origin: bumptech/glide
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
options = new Options();
loader = new ResourceLoader<>(RuntimeEnvironment.application.getResources(), uriLoader);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void createFromResourceStream_shouldWorkWithoutSourceName() {
Drawable drawable =
Drawable.createFromResourceStream(
context.getResources(),
null,
new ByteArrayInputStream(new byte[0]),
null,
new BitmapFactory.Options());
assertNotNull(drawable);
}
代码示例来源:origin: robolectric/robolectric
@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"));
}
代码示例来源:origin: robolectric/robolectric
@Test
public void decodeResourceStream_canTakeOptions() throws Exception {
BitmapFactory.Options options = new BitmapFactory.Options();
InputStream inputStream =
context.getContentResolver().openInputStream(Uri.parse("content:/path"));
options.inSampleSize = 100;
Bitmap bitmap =
BitmapFactory.decodeResourceStream(
context.getResources(), null, inputStream, null, options);
assertEquals(true, shadowOf(bitmap).getDescription().contains("inSampleSize=100"));
}
代码示例来源:origin: robolectric/robolectric
@Before
public void setUp() throws Exception {
context = ApplicationProvider.getApplicationContext();
parser = context.getResources().getXml(R.xml.preferences);
}
代码示例来源:origin: robolectric/robolectric
@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());
}
代码示例来源:origin: robolectric/robolectric
@Test
public void getStyleAttribute_allowStyleAttrReference() throws Exception {
parser = context.getResources().getXml(R.xml.has_style_attribute_reference);
parseUntilNext(XmlResourceParser.START_TAG);
assertThat(parser.getStyleAttribute()).isEqualTo(R.attr.parentStyleReference);
}
代码示例来源:origin: robolectric/robolectric
@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());
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testGetAttributeResourceValueStringStringInt() throws Exception {
parser = context.getResources().getXml(R.xml.has_attribute_resource_value);
parseUntilNext(XmlResourceParser.START_TAG);
assertThat(parser.getAttributeResourceValue(RES_AUTO_NS, "bar", 42)).isEqualTo(R.layout.main);
assertThat(parser.getAttributeResourceValue(RES_AUTO_NS, "foo", 42)).isEqualTo(42);
}
代码示例来源:origin: bumptech/glide
@Test
public void testReturnsNewDrawableFromConstantState() {
Bitmap firstFrame = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
drawable =
new GifDrawable(
RuntimeEnvironment.application,
mock(GifDecoder.class),
transformation,
100,
100,
firstFrame);
assertNotNull(Preconditions.checkNotNull(drawable.getConstantState()).newDrawable());
assertNotNull(
drawable.getConstantState().newDrawable(RuntimeEnvironment.application.getResources()));
}
内容来源于网络,如有侵权,请联系作者删除!