List of usage examples for android.content Context obtainStyledAttributes
public final TypedArray obtainStyledAttributes(AttributeSet set, @StyleableRes int[] attrs)
From source file:android.support.v7.internal.widget.ThemeUtils.java
static ColorStateList getThemeAttrColorStateList(Context context, int attr) { TEMP_ARRAY[0] = attr;/*from ww w.java 2s. co m*/ 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;//ww w.j a va2s . com TypedArray a = context.obtainStyledAttributes(null, TEMP_ARRAY); try { return a.getColor(0, 0); } finally { a.recycle(); } }
From source file:android.support.v7ox.widget.ThemeUtils.java
public static ColorStateList getThemeAttrColorStateList(Context context, int attr) { TEMP_ARRAY[0] = attr;//from w w w . ja v a 2s .c om TypedArray a = context.obtainStyledAttributes(null, TEMP_ARRAY); try { return a.getColorStateList(0); } finally { a.recycle(); } }
From source file:Main.java
/** * Tries to pull the Font Path from the View Style as this is the next decendent after being * defined in the View's xml.//from w w w. j a va2 s .c om * * @param context Activity Activity Context * @param attrs View Attributes * @param attributeId if -1 returns null. * @return null if attribute is not defined or found in the Style */ static String pullFontPathFromStyle(Context context, AttributeSet attrs, int attributeId) { if (attributeId == -1) return null; final TypedArray typedArray = context.obtainStyledAttributes(attrs, new int[] { attributeId }); if (typedArray != null) { try { // First defined attribute String fontFromAttribute = typedArray.getString(0); if (!TextUtils.isEmpty(fontFromAttribute)) { return fontFromAttribute; } } catch (Exception ignore) { // Failed for some reason. } finally { typedArray.recycle(); } } return null; }
From source file:Main.java
public static Drawable getActionBarBackground(Context context) { TypedValue outValue = new TypedValue(); context.getTheme().resolveAttribute(android.R.attr.actionBarStyle, outValue, true); TypedArray typedArray = context.obtainStyledAttributes(outValue.resourceId, new int[] { android.R.attr.background }); Drawable background = typedArray.getDrawable(0); typedArray.recycle();//from ww w. jav a 2s . c om return background; }
From source file:Main.java
public static Drawable getSplitActionBarBackground(Context context) { TypedValue outValue = new TypedValue(); context.getTheme().resolveAttribute(android.R.attr.actionBarStyle, outValue, true); TypedArray typedArray = context.obtainStyledAttributes(outValue.resourceId, new int[] { android.R.attr.backgroundSplit }); Drawable background = typedArray.getDrawable(0); typedArray.recycle();/*from w w w . ja v a2s . c o m*/ return background; }
From source file:Main.java
/** * Tries to pull the Font Path from the View Style as this is the next decendent after being * defined in the View's xml./*from www. j av a 2 s. c o m*/ * * @param context Activity Activity Context * @param attrs View Attributes * @param attributeId if -1 returns null. * @return null if attribute is not defined or found in the Style */ static String pullFontPathFromStyle(Context context, AttributeSet attrs, int attributeId) { if (attributeId == -1 || attrs == null) return null; final TypedArray typedArray = context.obtainStyledAttributes(attrs, new int[] { attributeId }); if (typedArray != null) { try { // First defined attribute String fontFromAttribute = typedArray.getString(0); if (!TextUtils.isEmpty(fontFromAttribute)) { return fontFromAttribute; } } catch (Exception ignore) { // Failed for some reason. } finally { typedArray.recycle(); } } return null; }
From source file:Main.java
/** * Tries to pull the Font Path from the View Style as this is the next decendent after being * defined in the View's xml./* w ww.ja v a 2s. c o m*/ * * @param context Activity Activity Context * @param attrs View Attributes * @param attributeId if -1 returns null. * @return null if attribute is not defined or found in the Style */ static String pullFontPathFromStyle(Context context, AttributeSet attrs, int attributeId) { if (attributeId == -1 || attrs == null) return null; final TypedArray typedArray = context.obtainStyledAttributes(attrs, getAttributeArray(attributeId)); if (typedArray != null) { try { // First defined attribute String fontFromAttribute = typedArray.getString(0); if (!TextUtils.isEmpty(fontFromAttribute)) { return fontFromAttribute; } } catch (Exception ignore) { // Failed for some reason. } finally { typedArray.recycle(); } } return null; }
From source file:Main.java
public static int getThemeColorPrimaryDark(Context ctx) { TypedValue typedValue = new TypedValue(); ctx.getTheme().resolveAttribute(android.R.attr.theme, typedValue, true); int[] attribute = new int[] { android.R.attr.colorPrimaryDark }; TypedArray array = ctx.obtainStyledAttributes(typedValue.resourceId, attribute); int color = array.getColor(0, -1); array.recycle();// w ww . ja va 2 s. c o m return color; }
From source file:Main.java
/** * Tries to pull the Font Path from the Text Appearance. * * @param context Activity Context//from w ww . ja va2 s . co m * @param attrs View Attributes * @param attributeId if -1 returns null. * @return returns null if attribute is not defined or if no TextAppearance is found. */ static String pullFontPathFromTextAppearance(final Context context, AttributeSet attrs, int attributeId) { if (attributeId == -1) { return null; } int textAppearanceId = -1; final TypedArray typedArrayAttr = context.obtainStyledAttributes(attrs, new int[] { android.R.attr.textAppearance }); if (typedArrayAttr != null) { try { textAppearanceId = typedArrayAttr.getResourceId(0, -1); } catch (Exception ignored) { // Failed for some reason return null; } finally { typedArrayAttr.recycle(); } } final TypedArray textAppearanceAttrs = context.obtainStyledAttributes(textAppearanceId, new int[] { attributeId }); if (textAppearanceAttrs != null) { try { return textAppearanceAttrs.getString(0); } catch (Exception ignore) { // Failed for some reason. return null; } finally { textAppearanceAttrs.recycle(); } } return null; }