List of usage examples for android.content.res TypedArray getResourceId
@AnyRes public int getResourceId(@StyleableRes int index, int defValue)
From source file:Main.java
public static Integer getInteger(TypedArray a, int attr) { int value = a.getResourceId(attr, Integer.MAX_VALUE); return value == Integer.MAX_VALUE ? null : Integer.valueOf(value); }
From source file:Main.java
public static int resolveResource(Context context, int attr) { int[] attribute = new int[] { attr }; TypedArray array = context.obtainStyledAttributes(attribute); int reference = array.getResourceId(0, 0); array.recycle();//from w w w .j a v a 2 s .c o m return reference; }
From source file:com.anysoftkeyboard.keyboards.views.DrawableBuilder.java
public static DrawableBuilder build(KeyboardTheme theme, TypedArray a, final int index) { int resId = a.getResourceId(index, 0); if (resId == 0) throw new IllegalArgumentException("No resource ID was found at index " + index); return new DrawableBuilder(theme, resId); }
From source file:Main.java
public static int getAttributeId(Context context, int style, int attr) { TypedArray a = context.getTheme().obtainStyledAttributes(style, new int[] { attr }); return a.getResourceId(0, 0); }
From source file:Main.java
public static int getResourceId(Context context, int attr, int defaultValue) { TypedArray ta = context.obtainStyledAttributes(new int[] { attr }); int resourceId = ta.getResourceId(0, defaultValue); ta.recycle();//w w w. j a v a 2 s .c om return resourceId; }
From source file:Main.java
@AnyRes public static int getResourceId(TypedArray a, @StyleableRes int index, @StyleableRes int fallbackIndex, @AnyRes int defaultValue) { return a.getResourceId(index, a.getResourceId(fallbackIndex, defaultValue)); }
From source file:Main.java
/** * Get a resource id from an attribute id. * @param context/*from ww w.j a va2 s. co m*/ * @param attrId * @return the resource id */ public static int getResourceFromAttribute(Context context, int attrId) { TypedArray a = context.getTheme().obtainStyledAttributes(new int[] { attrId }); int resId = a.getResourceId(0, 0); a.recycle(); return resId; }
From source file:Main.java
/** * //from w ww .ja v a2s .c o m * @param context * @param view * @param resid * @return */ public static View addBackgroundIndicator(Context context, View view, int resid) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { TypedArray attributes = context.obtainStyledAttributes(new int[] { resid }); int resource = attributes.getResourceId(0, 0); attributes.recycle(); // setBackgroundResource resets padding int paddingLeft = view.getPaddingLeft(); int paddingTop = view.getPaddingTop(); int paddingRight = view.getPaddingRight(); int paddingBottom = view.getPaddingBottom(); view.setBackgroundResource(resource); view.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); } return view; }
From source file:Main.java
public static int[] getIdsArray(Context context, int idArray) { TypedArray ar = context.getResources().obtainTypedArray(idArray); int len = ar.length(); int[] arrayIds = new int[len]; for (int i = 0; i < len; i++) arrayIds[i] = ar.getResourceId(i, 0); ar.recycle();/*from w ww . ja va2 s . co m*/ return arrayIds; }
From source file:Main.java
public static String[] getItemStrings(Resources res, int iconsRes) { if (iconsRes == 0) return null; TypedArray array = res.obtainTypedArray(iconsRes); int n = array.length(); String ids[] = new String[n]; for (int i = 0; i < n; ++i) { ids[i] = res.getString(array.getResourceId(i, 0)); }/* w ww . j a v a 2 s . c o m*/ array.recycle(); return ids; }