List of usage examples for android.content Context obtainStyledAttributes
public final TypedArray obtainStyledAttributes(AttributeSet set, @StyleableRes int[] attrs)
From source file:android.percent.support.PercentLayoutHelper.java
/** * Constructs a PercentLayoutInfo from attributes associated with a View. Call this method from * {@code LayoutParams(Context c, AttributeSet attrs)} constructor. *///from w ww . ja v a2 s . c o m public static PercentLayoutInfo getPercentLayoutInfo(Context context, AttributeSet attrs) { PercentLayoutInfo info = null; TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.PercentLayout_Layout); info = setWidthAndHeightVal(array, info); info = setMarginRelatedVal(array, info); info = setTextSizeSupportVal(array, info); info = setMinMaxWidthHeightRelatedVal(array, info); info = setPaddingRelatedVal(array, info); array.recycle(); if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "constructed: " + info); } return info; }
From source file:Main.java
/** * Last but not least, try to pull the Font Path from the Theme, which is defined. * * @param context Activity Context * @param styleAttrId Theme style id//from ww w . j a v a 2 s .c o m * @param subStyleAttrId the sub style from the theme to look up after the first style * @param attributeId if -1 returns null. * @return null if no theme or attribute defined. */ static String pullFontPathFromTheme(Context context, int styleAttrId, int subStyleAttrId, int attributeId) { if (styleAttrId == -1 || attributeId == -1) return null; final Resources.Theme theme = context.getTheme(); final TypedValue value = new TypedValue(); theme.resolveAttribute(styleAttrId, value, true); int subStyleResId = -1; final TypedArray parentTypedArray = theme.obtainStyledAttributes(value.resourceId, new int[] { subStyleAttrId }); try { subStyleResId = parentTypedArray.getResourceId(0, -1); } catch (Exception ignore) { // Failed for some reason. return null; } finally { parentTypedArray.recycle(); } if (subStyleResId == -1) return null; final TypedArray subTypedArray = context.obtainStyledAttributes(subStyleResId, new int[] { attributeId }); if (subTypedArray != null) { try { return subTypedArray.getString(0); } catch (Exception ignore) { // Failed for some reason. return null; } finally { subTypedArray.recycle(); } } return null; }
From source file:Main.java
/** * Last but not least, try to pull the Font Path from the Theme, which is defined. * * @param context Activity Context * @param styleAttrId Theme style id//from w ww .j av a2 s .c o m * @param subStyleAttrId the sub style from the theme to look up after the first style * @param attributeId if -1 returns null. * @return null if no theme or attribute defined. */ static String pullFontPathFromTheme(Context context, int styleAttrId, int subStyleAttrId, int[] attributeId) { if (styleAttrId == -1 || attributeId == null) return null; final Resources.Theme theme = context.getTheme(); final TypedValue value = new TypedValue(); theme.resolveAttribute(styleAttrId, value, true); int subStyleResId = -1; final TypedArray parentTypedArray = theme.obtainStyledAttributes(value.resourceId, new int[] { subStyleAttrId }); try { subStyleResId = parentTypedArray.getResourceId(0, -1); } catch (Exception ignore) { // Failed for some reason. return null; } finally { parentTypedArray.recycle(); } if (subStyleResId == -1) return null; final TypedArray subTypedArray = context.obtainStyledAttributes(subStyleResId, attributeId); if (subTypedArray != null) { try { return subTypedArray.getString(0); } catch (Exception ignore) { // Failed for some reason. return null; } finally { subTypedArray.recycle(); } } return null; }
From source file:Main.java
/** * Last but not least, try to pull the Font Path from the Theme, which is defined. * * @param context Activity Context * @param styleAttrId Theme style id/* w w w. j av a 2 s.co m*/ * @param subStyleAttrId the sub style from the theme to look up after the first style * @param attributeId if -1 returns null. * @return null if no theme or attribute defined. */ static String pullFontPathFromTheme(Context context, int styleAttrId, int subStyleAttrId, int attributeId) { if (styleAttrId == -1 || attributeId == -1) return null; final Resources.Theme theme = context.getTheme(); final TypedValue value = new TypedValue(); theme.resolveAttribute(styleAttrId, value, true); int subStyleResId = -1; final TypedArray parentTypedArray = theme.obtainStyledAttributes(value.resourceId, getAttributeArray(subStyleAttrId)); try { subStyleResId = parentTypedArray.getResourceId(0, -1); } catch (Exception ignore) { // Failed for some reason. return null; } finally { parentTypedArray.recycle(); } if (subStyleResId == -1) return null; final TypedArray subTypedArray = context.obtainStyledAttributes(subStyleResId, getAttributeArray(attributeId)); if (subTypedArray != null) { try { return subTypedArray.getString(0); } catch (Exception ignore) { // Failed for some reason. return null; } finally { subTypedArray.recycle(); } } return null; }
From source file:cn.ieclipse.af.view.ViewPagerV4.java
private void init(Context context, AttributeSet attrs) { if (attrs != null) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ViewPagerV4); disableWipe = a.getBoolean(R.styleable.ViewPagerV4_disableWipe, false); a.recycle();//from w ww .ja v a2s. c o m } }
From source file:com.actionbarsherlock.internal.widget.CapitalizingButton.java
public CapitalizingButton(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, R_styleable_Button); mAllCaps = a.getBoolean(R_styleable_Button_textAllCaps, true); a.recycle();/*w w w .j a v a2 s .co m*/ }
From source file:com.actionbarsherlock.internal.widget.FakeDialogPhoneWindow.java
public FakeDialogPhoneWindow(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SherlockTheme); a.getValue(R.styleable.SherlockTheme_windowMinWidthMajor, mMinWidthMajor); a.getValue(R.styleable.SherlockTheme_windowMinWidthMinor, mMinWidthMinor); a.recycle();/*w w w . j a va 2 s . c o m*/ }
From source file:android.support.transition.PatternPathMotion.java
public PatternPathMotion(Context context, AttributeSet attrs) { TypedArray a = context.obtainStyledAttributes(attrs, Styleable.PATTERN_PATH_MOTION); try {/*w w w .jav a 2 s.c om*/ String pathData = TypedArrayUtils.getNamedString(a, (XmlPullParser) attrs, "patternPathData", Styleable.PatternPathMotion.PATTERN_PATH_DATA); if (pathData == null) { throw new RuntimeException("pathData must be supplied for patternPathMotion"); } Path pattern = PathParser.createPathFromPathData(pathData); setPatternPath(pattern); } finally { a.recycle(); } }
From source file:android.support.v7ox.widget.ButtonBarLayout.java
public ButtonBarLayout(Context context, AttributeSet attrs) { super(context, attrs); final TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.ButtonBarLayout); mAllowStacking = ta.getBoolean(R.styleable.ButtonBarLayout_allowStacking, false); ta.recycle();// w w w . jav a2s . c o m }
From source file:android.support.design.internal.SnackbarContentLayout.java
public SnackbarContentLayout(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SnackbarLayout); mMaxWidth = a.getDimensionPixelSize(R.styleable.SnackbarLayout_android_maxWidth, -1); mMaxInlineActionWidth = a.getDimensionPixelSize(R.styleable.SnackbarLayout_maxActionInlineWidth, -1); a.recycle();//from w w w . j a va2 s . c o m }