android.content.Context.getResources()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.0k)|赞(0)|评价(0)|浏览(191)

本文整理了Java中android.content.Context.getResources()方法的一些代码示例,展示了Context.getResources()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.getResources()方法的具体详情如下:
包路径:android.content.Context
类名称:Context
方法名:getResources

Context.getResources介绍

暂无

代码示例

代码示例来源:origin: bumptech/glide

@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;
}

代码示例来源:origin: bumptech/glide

private static Drawable loadDrawableV4(
   Context context, @DrawableRes int id, @Nullable Theme theme) {
  Resources resources = context.getResources();
  return ResourcesCompat.getDrawable(resources, id, theme);
 }
}

代码示例来源:origin: greenrobot/greenDAO

public static byte[] readAsset(Context context, String filename) throws IOException {
  InputStream in = context.getResources().getAssets().open(filename);
  try {
    return readAllBytes(in);
  } finally {
    in.close();
  }
}

代码示例来源:origin: bumptech/glide

private byte[] loadVideoBytes() throws IOException {
  Resources resources = context.getResources();
  InputStream is = resources.openRawResource(ResourceIds.raw.video);
  return ByteStreams.toByteArray(is);
 }
}

代码示例来源:origin: bumptech/glide

private byte[] getCanonicalBytes() throws IOException {
  int resourceId = ResourceIds.raw.canonical;
  Resources resources = context.getResources();
  InputStream is = resources.openRawResource(resourceId);
  return ByteStreams.toByteArray(is);
 }
}

代码示例来源:origin: JakeWharton/butterknife

private static String getResourceEntryName(View view, @IdRes int id) {
 if (view.isInEditMode()) {
  return "<unavailable while editing>";
 }
 return view.getContext().getResources().getResourceEntryName(id);
}

代码示例来源:origin: bumptech/glide

private static int getResourceId(String type, String resourceName) {
  Context context = InstrumentationRegistry.getTargetContext();
  Resources res = context.getResources();
  return res.getIdentifier(resourceName, type, context.getPackageName());
 }
}

代码示例来源:origin: bumptech/glide

/**
 * @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()));
}

代码示例来源:origin: bumptech/glide

public void sameAs(@DrawableRes int resourceId) {
 Context context = InstrumentationRegistry.getTargetContext();
 Drawable drawable =
   ResourcesCompat.getDrawable(context.getResources(), resourceId, context.getTheme());
 sameAs(drawable);
}

代码示例来源:origin: bumptech/glide

@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();
}

代码示例来源:origin: JakeWharton/butterknife

@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);
}

代码示例来源:origin: JakeWharton/butterknife

@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);
 }
}

代码示例来源:origin: JakeWharton/butterknife

@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);
}

代码示例来源:origin: bumptech/glide

@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();
}

代码示例来源:origin: JakeWharton/butterknife

@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);
 }
}

代码示例来源:origin: JakeWharton/butterknife

@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);
 }
}

代码示例来源:origin: JakeWharton/butterknife

@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);
}

代码示例来源:origin: JakeWharton/butterknife

@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());
 }
}

代码示例来源:origin: JakeWharton/butterknife

@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));
 }
}

代码示例来源:origin: JakeWharton/butterknife

@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());
 }
}

相关文章

微信公众号

最新文章

更多

Context类方法