@SuppressWarnings({"unchecked", "PMD.UnnecessaryLocalBeforeReturn"}) private Resource<Drawable> newDrawableResource( Context context, Resource<Bitmap> transformed) { Resource<? extends Drawable> result = LazyBitmapDrawableResource.obtain(context.getResources(), transformed); return (Resource<Drawable>) result; }
private static Drawable loadDrawableV4( Context context, @DrawableRes int id, @Nullable Theme theme) { Resources resources = context.getResources(); return ResourcesCompat.getDrawable(resources, id, theme); } }
public static byte[] readAsset(Context context, String filename) throws IOException { InputStream in = context.getResources().getAssets().open(filename); try { return readAllBytes(in); } finally { in.close(); } }
private byte[] loadVideoBytes() throws IOException { Resources resources = context.getResources(); InputStream is = resources.openRawResource(ResourceIds.raw.video); return ByteStreams.toByteArray(is); } }
private byte[] getCanonicalBytes() throws IOException { int resourceId = ResourceIds.raw.canonical; Resources resources = context.getResources(); InputStream is = resources.openRawResource(resourceId); return ByteStreams.toByteArray(is); } }
private static String getResourceEntryName(View view, @IdRes int id) { if (view.isInEditMode()) { return "<unavailable while editing>"; } return view.getContext().getResources().getResourceEntryName(id); }
private static int getResourceId(String type, String resourceName) { Context context = InstrumentationRegistry.getTargetContext(); Resources res = context.getResources(); return res.getIdentifier(resourceName, type, context.getPackageName()); } }
/** * @deprecated Use {@link #obtain(Resources, Resource)} instead, it can be unsafe to extract * {@link Bitmap}s from their wrapped {@link Resource}. */ @Deprecated public static LazyBitmapDrawableResource obtain(Context context, Bitmap bitmap) { return (LazyBitmapDrawableResource) obtain( context.getResources(), BitmapResource.obtain(bitmap, Glide.get(context).getBitmapPool())); }
public void sameAs(@DrawableRes int resourceId) { Context context = InstrumentationRegistry.getTargetContext(); Drawable drawable = ResourcesCompat.getDrawable(context.getResources(), resourceId, context.getTheme()); sameAs(drawable); }
@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 asInt() { IntTarget target = new IntTarget(); int expected = context.getResources().getDimensionPixelSize(R.dimen.twelve_point_two_dp); Unbinder unbinder = new BindDimenTest$IntTarget_ViewBinding(target, context); assertThat(target.actual).isEqualTo(expected); unbinder.unbind(); assertThat(target.actual).isEqualTo(expected); }
@Test public void asFloat() { FloatTarget target = new FloatTarget(); float expected = context.getResources().getDimension(R.dimen.twelve_point_two_dp); Unbinder unbinder = new BindDimenTest$FloatTarget_ViewBinding(target, context); assertThat(target.actual).isEqualTo(expected); unbinder.unbind(); assertThat(target.actual).isEqualTo(expected); } }
@Test public void asStringArray() { StringArrayTarget target = new StringArrayTarget(); String[] expected = context.getResources().getStringArray(R.array.string_one_two_three); Unbinder unbinder = new BindArrayTest$StringArrayTarget_ViewBinding(target, context); assertThat(target.actual).isEqualTo(expected); unbinder.unbind(); assertThat(target.actual).isEqualTo(expected); }
@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 asFloat() { Target target = new Target(); TypedValue value = new TypedValue(); context.getResources().getValue(R.dimen.twelve_point_two, value, true); float expected = value.getFloat(); Unbinder unbinder = new BindFloatTest$Target_ViewBinding(target, context); assertThat(target.actual).isEqualTo(expected); unbinder.unbind(); assertThat(target.actual).isEqualTo(expected); } }
@Test public void asCharSequenceArray() { CharSequenceArrayTarget target = new CharSequenceArrayTarget(); CharSequence[] expected = context.getResources().getTextArray(R.array.int_one_two_three); Unbinder unbinder = new BindArrayTest$CharSequenceArrayTarget_ViewBinding(target, context); assertThat(target.actual).isEqualTo(expected); unbinder.unbind(); assertThat(target.actual).isEqualTo(expected); } }
@Test public void asIntArray() { IntArrayTarget target = new IntArrayTarget(); int[] expected = context.getResources().getIntArray(R.array.int_one_two_three); Unbinder unbinder = new BindArrayTest$IntArrayTarget_ViewBinding(target, context); assertThat(target.actual).isEqualTo(expected); unbinder.unbind(); assertThat(target.actual).isEqualTo(expected); }
@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()); } }
@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 asColorStateList() { ColorStateListTarget target = new ColorStateListTarget(); ColorStateList expected = context.getResources().getColorStateList(R.color.colors); Unbinder unbinder = new BindColorTest$ColorStateListTarget_ViewBinding(target, context); assertThat(target.actual.toString()).isEqualTo(expected.toString()); unbinder.unbind(); assertThat(target.actual.toString()).isEqualTo(expected.toString()); } }