List of usage examples for android.content.res TypedArray recycle
public void recycle()
From source file:Main.java
/** * chooses a random color from array.xml */// w ww. ja va2 s . c o m public static int getRandomMaterialColor(Context context, String typeColor) { int returnColor = Color.GRAY; int arrayId = context.getResources().getIdentifier("mdcolor_" + typeColor, "array", context.getPackageName()); if (arrayId != 0) { TypedArray colors = context.getResources().obtainTypedArray(arrayId); int index = (int) (Math.random() * colors.length()); returnColor = colors.getColor(index, Color.GRAY); colors.recycle(); } return returnColor; }
From source file:Main.java
/** * get toolbar height/* www . jav a 2 s .c o m*/ * * @param context context * @return int */ public static int getToolbarHeight(Context context) { final TypedArray styledAttributes = context.getTheme() .obtainStyledAttributes(new int[] { android.R.attr.actionBarSize }); int toolbarHeight = (int) styledAttributes.getDimension(0, 0); styledAttributes.recycle(); return toolbarHeight; }
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(); return arrayIds; }
From source file:Main.java
public static int[] getColorsFromAttributes(Context context, int... attr) { final TypedArray a = context.obtainStyledAttributes(attr); int[] colors = new int[a.getIndexCount()]; for (int i = 0; i < a.getIndexCount(); i++) { colors[i] = a.getColor(i, 0);/*from www . ja v a2 s . c om*/ } a.recycle(); return colors; }
From source file:Main.java
public static int[] getColorArray(@NonNull Context context, @ArrayRes int array) { if (array == 0) return null; TypedArray ta = context.getResources().obtainTypedArray(array); int[] colors = new int[ta.length()]; for (int i = 0; i < ta.length(); i++) colors[i] = ta.getColor(i, 0);// www .j a v a 2s . c om ta.recycle(); return colors; }
From source file:android.support.v7.internal.widget.ThemeUtils.java
static int getThemeAttrColor(Context context, int attr) { TEMP_ARRAY[0] = attr;/* w ww . j av a 2s. c o m*/ TypedArray a = context.obtainStyledAttributes(null, TEMP_ARRAY); try { return a.getColor(0, 0); } finally { a.recycle(); } }
From source file:android.support.v7.internal.widget.ThemeUtils.java
static ColorStateList getThemeAttrColorStateList(Context context, int attr) { TEMP_ARRAY[0] = attr;/* ww w. j ava2 s. com*/ TypedArray a = context.obtainStyledAttributes(null, TEMP_ARRAY); try { return a.getColorStateList(0); } finally { a.recycle(); } }
From source file:android.support.v7ox.widget.ThemeUtils.java
public static int getThemeAttrColor(Context context, int attr) { TEMP_ARRAY[0] = attr;/*from w w w .j a v a 2 s . com*/ TypedArray a = context.obtainStyledAttributes(null, TEMP_ARRAY); try { return a.getColor(0, 0); } finally { a.recycle(); } }
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)); }//from w w w. ja va2s . co m array.recycle(); return ids; }
From source file:android.support.v7ox.widget.ThemeUtils.java
public static ColorStateList getThemeAttrColorStateList(Context context, int attr) { TEMP_ARRAY[0] = attr;//from ww w .j a va 2 s. c o m TypedArray a = context.obtainStyledAttributes(null, TEMP_ARRAY); try { return a.getColorStateList(0); } finally { a.recycle(); } }