本文整理了Java中android.content.res.Resources.obtainTypedArray
方法的一些代码示例,展示了Resources.obtainTypedArray
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Resources.obtainTypedArray
方法的具体详情如下:
包路径:android.content.res.Resources
类名称:Resources
方法名:obtainTypedArray
暂无
代码示例来源:origin: stackoverflow.com
Resources res = getResources();
TypedArray ta = res.obtainTypedArray(R.array.array0);
int n = ta.length();
String[][] array = new String[n][];
for (int i = 0; i < n; ++i) {
int id = ta.getResourceId(i, 0);
if (id > 0) {
array[i] = res.getStringArray(id);
} else {
// something wrong with the XML
}
}
ta.recycle(); // Important!
代码示例来源:origin: hidroh/materialistic
@SuppressLint("Recycle")
@Provides @Singleton
public ResourcesProvider provideResourcesProvider(Context context) {
return resId -> context.getResources().obtainTypedArray(resId);
}
}
代码示例来源:origin: rey5137/material
private int[] loadStyleList(Context context, int resId){
if(context == null)
return null;
TypedArray array = context.getResources().obtainTypedArray(resId);
int[] result = new int[array.length()];
for(int i = 0; i < result.length; i++)
result[i] = array.getResourceId(i, 0);
array.recycle();
return result;
}
代码示例来源:origin: bluelinelabs/Conductor
public static int getMaterialColor(Resources resources, int index) {
TypedArray colors = resources.obtainTypedArray(R.array.mdcolor_300);
final int returnColor = colors.getColor(index % colors.length(), Color.BLACK);
colors.recycle();
return returnColor;
}
代码示例来源:origin: alexvasilkov/GestureViews
public static Painting[] list(Resources res) {
final String[] authors = res.getStringArray(R.array.paintings_authors);
final String[] titles = res.getStringArray(R.array.paintings_titles);
final String[] links = res.getStringArray(R.array.paintings_links);
final TypedArray images = res.obtainTypedArray(R.array.paintings_images);
final TypedArray thumbs = res.obtainTypedArray(R.array.paintings_thumbs);
final int size = titles.length;
final Painting[] paintings = new Painting[size];
for (int i = 0; i < size; i++) {
final int imageId = images.getResourceId(i, -1);
final int thumbId = thumbs.getResourceId(i, -1);
paintings[i] = new Painting(imageId, thumbId, authors[i], titles[i], links[i]);
}
images.recycle();
thumbs.recycle();
return paintings;
}
代码示例来源:origin: hidroh/materialistic
public CommentItemDecoration(Context context) {
mPaint = new Paint();
mPaint.setStrokeWidth(context.getResources().getDimensionPixelSize(R.dimen.divider));
mHorizontalMargin = context.getResources()
.getDimensionPixelSize(R.dimen.cardview_horizontal_margin);
mLevelIndicatorWidth = AppUtils.getDimensionInDp(context, R.dimen.level_indicator_width);
mColors = context.getResources().obtainTypedArray(R.array.color_codes);
mColorCodeEnabled = Preferences.colorCodeEnabled(context);
mThreadIndicatorEnabled = Preferences.threadIndicatorEnabled(context);
}
代码示例来源:origin: JakeWharton/butterknife
private static @Nullable Unbinder parseBindArray(Object target, Field field, View source) {
BindArray bindArray = field.getAnnotation(BindArray.class);
if (bindArray == null) {
return null;
}
validateMember(field);
int id = bindArray.value();
Resources resources = source.getContext().getResources();
Object value;
Class<?> fieldType = field.getType();
if (fieldType == TypedArray.class) {
value = resources.obtainTypedArray(id);
} else if (fieldType.isArray()) {
Class<?> componentType = fieldType.getComponentType();
if (componentType == String.class) {
value = resources.getStringArray(id);
} else if (componentType == int.class) {
value = resources.getIntArray(id);
} else if (componentType == CharSequence.class) {
value = resources.getTextArray(id);
} else {
throw new IllegalStateException(); // TODO
}
} else {
throw new IllegalStateException(); // TODO
}
trySet(field, target, value);
return Unbinder.EMPTY;
}
代码示例来源:origin: yarolegovich/SlidingRootNav
private Drawable[] loadScreenIcons() {
TypedArray ta = getResources().obtainTypedArray(R.array.ld_activityScreenIcons);
Drawable[] icons = new Drawable[ta.length()];
for (int i = 0; i < ta.length(); i++) {
int id = ta.getResourceId(i, 0);
if (id != 0) {
icons[i] = ContextCompat.getDrawable(this, id);
}
}
ta.recycle();
return icons;
}
代码示例来源:origin: commonsguy/cw-omnibus
int[] getLayoutsArray(int arrayResourceId) {
TypedArray typedArray=
getResources().obtainTypedArray(arrayResourceId);
int[] result=new int[typedArray.length()];
for (int i=0;i<typedArray.length();i++) {
result[i]=typedArray.getResourceId(i, -1);
}
return(result);
}
}
代码示例来源:origin: qiujuer/Genius-Android
/**
* Get color array values form array resource
*
* @param resources Resources
* @param resId Resources id
* @return color array
*/
public static int[] getColorsFromArrayRes(Resources resources, int resId) {
try {
@SuppressLint("Recycle")
TypedArray array = resources.obtainTypedArray(resId);
if (array.length() > 0) {
final int len = array.length();
final int[] colors = new int[len];
for (int i = 0; i < len; i++) {
colors[i] = array.getColor(i, 0);
}
return colors;
}
} catch (Resources.NotFoundException ignored) {
}
return null;
}
代码示例来源:origin: LaiFeng-Android/SopCastComponent
/**
* Override the image ids of this button.
*/
public void overrideImageIds(int resId) {
TypedArray ids = null;
try {
ids = getResources().obtainTypedArray(resId);
mImageIds = new int[ids.length()];
for (int i = 0; i < ids.length(); i++) {
mImageIds[i] = ids.getResourceId(i, 0);
}
} finally {
if (ids != null) {
ids.recycle();
}
}
}
代码示例来源:origin: pchmn/MaterialChipsInput
/**
* Constructor for <code>LetterTileProvider</code>
*
* @param context The {@link Context} to use
*/
public LetterTileProvider(Context context) {
final Resources res = context.getResources();
mPaint.setTypeface(Typeface.create("sans-serif-light", Typeface.NORMAL));
mPaint.setColor(Color.WHITE);
mPaint.setTextAlign(Paint.Align.CENTER);
mPaint.setAntiAlias(true);
mColors = res.obtainTypedArray(R.array.letter_tile_colors);
mTileLetterFontSize = res.getDimensionPixelSize(R.dimen.tile_letter_font_size);
//mDefaultBitmap = BitmapFactory.decodeResource(res, android.R.drawable.);
mDefaultBitmap = drawableToBitmap(ContextCompat.getDrawable(context, R.drawable.ic_person_white_24dp));
mWidth = res.getDimensionPixelSize(R.dimen.letter_tile_size);
mHeight = res.getDimensionPixelSize(R.dimen.letter_tile_size);
}
代码示例来源:origin: rey5137/material
TypedArray ta = context.getResources().obtainTypedArray(a.getResourceId(attr, 0));
strokeColors = new int[ta.length()];
for(int j = 0; j < ta.length(); j++)
mInAnimationDuration = a.getInteger(attr, 0);
else if(attr == R.styleable.CircularProgressDrawable_cpd_inStepColors){
TypedArray ta = context.getResources().obtainTypedArray(a.getResourceId(attr, 0));
mInColors = new int[ta.length()];
for(int j = 0; j < ta.length(); j++)
代码示例来源:origin: rey5137/material
strokeColors(a.getColor(R.styleable.CircularProgressDrawable_cpd_strokeColor, ThemeUtil.colorPrimary(context, 0xFF000000)));
if((resId = a.getResourceId(R.styleable.CircularProgressDrawable_cpd_strokeColors, 0)) != 0){
TypedArray ta = context.getResources().obtainTypedArray(resId);
int[] colors = new int[ta.length()];
for(int j = 0; j < ta.length(); j++)
inAnimDuration(a.getInteger(R.styleable.CircularProgressDrawable_cpd_inAnimDuration, context.getResources().getInteger(android.R.integer.config_mediumAnimTime)));
if((resId = a.getResourceId(R.styleable.CircularProgressDrawable_cpd_inStepColors, 0)) != 0){
TypedArray ta = context.getResources().obtainTypedArray(resId);
int[] colors = new int[ta.length()];
for(int j = 0; j < ta.length(); j++)
代码示例来源:origin: tumblr/Backboard
mRootView = (RelativeLayout) inflater.inflate(R.layout.fragment_bloom, container, false);
mCircles = getResources().obtainTypedArray(R.array.circles);
mRunnable = new CircleSpawn();
代码示例来源:origin: robolectric/robolectric
@Implementation
protected TypedArray obtainTypedArray(int id) throws Resources.NotFoundException {
if (isLegacyAssetManager()) {
ShadowLegacyAssetManager shadowAssetManager = legacyShadowOf(realResources.getAssets());
TypedArray typedArray = shadowAssetManager.getTypedArrayResource(realResources, id);
if (typedArray != null) {
return typedArray;
} else {
throw newNotFoundException(id);
}
} else {
return directlyOn(realResources, Resources.class).obtainTypedArray(id);
}
}
代码示例来源:origin: rey5137/material
strokeColors(a.getColor(R.styleable.LinearProgressDrawable_lpd_strokeColor, ThemeUtil.colorPrimary(context, 0xFF000000)));
if((resId = a.getResourceId(R.styleable.LinearProgressDrawable_lpd_strokeColors, 0)) != 0){
TypedArray ta = context.getResources().obtainTypedArray(resId);
int[] colors = new int[ta.length()];
for(int j = 0; j < ta.length(); j++)
代码示例来源:origin: robolectric/robolectric
@Test
public void withIdReferenceEntry_obtainTypedArray() {
TypedArray typedArray = resources.obtainTypedArray(R.array.typed_array_with_resource_id);
assertThat(typedArray.length()).isEqualTo(2);
assertThat(typedArray.getResourceId(0, 0)).isEqualTo(R.id.id_declared_in_item_tag);
assertThat(typedArray.getResourceId(1, 0)).isEqualTo(R.id.id_declared_in_layout);
}
代码示例来源:origin: tumblr/Backboard
getResources().getDisplayMetrics());
final TypedArray circles = getResources().obtainTypedArray(R.array.circles);
代码示例来源:origin: robolectric/robolectric
@Test
public void obtainTypedArray() throws Exception {
final TypedArray valuesTypedArray = resources.obtainTypedArray(R.array.typed_array_values);
assertThat(valuesTypedArray.getString(0)).isEqualTo("abcdefg");
assertThat(valuesTypedArray.getInt(1, 0)).isEqualTo(3875);
.isEqualTo(applyDimension(COMPLEX_UNIT_PT, 18, resources.getDisplayMetrics()));
final TypedArray refsTypedArray = resources.obtainTypedArray(R.array.typed_array_references);
assertThat(refsTypedArray.getString(0)).isEqualTo("apple");
assertThat(refsTypedArray.getString(1)).isEqualTo("banana");
内容来源于网络,如有侵权,请联系作者删除!