private void parseTextAttrs(TypedArray a) { if (a.hasValue(R.styleable.BaselineGridTextView_lineHeightMultiplierHint)) { lineHeightMultiplierHint = a.getFloat(R.styleable.BaselineGridTextView_lineHeightMultiplierHint, 1f); } if (a.hasValue(R.styleable.BaselineGridTextView_lineHeightHint)) { lineHeightHint = a.getDimensionPixelSize( R.styleable.BaselineGridTextView_lineHeightHint, 0); } if (a.hasValue(R.styleable.BaselineGridTextView_android_fontFamily)) { fontResId = a.getResourceId(R.styleable.BaselineGridTextView_android_fontFamily, 0); } }
TypedArray a = context.getTheme().obtainStyledAttributes( attrs, R.styleable.IconView, 0, 0); // Gets you the 'value' number - 0 or 666 in your example if (a.hasValue(R.styleable.IconView_icon)) { int value = a.getInt(R.styleable.IconView_icon, 0)); } a.recycle(); }
public void setCollapsedTextAppearance(int resId) { TypedArray a = mView.getContext().obtainStyledAttributes(resId, R.styleable.TextAppearance); if (a.hasValue(R.styleable.TextAppearance_android_textColor)) { mCollapsedTextColor = a.getColor( R.styleable.TextAppearance_android_textColor, mCollapsedTextColor); } if (a.hasValue(R.styleable.TextAppearance_android_textSize)) { mCollapsedTextSize = a.getDimensionPixelSize( R.styleable.TextAppearance_android_textSize, (int) mCollapsedTextSize); } a.recycle(); recalculate(); }
public void setExpandedTextAppearance(int resId) { TypedArray a = mView.getContext().obtainStyledAttributes(resId, R.styleable.TextAppearance); if (a.hasValue(R.styleable.TextAppearance_android_textColor)) { mExpandedTextColor = a.getColor( R.styleable.TextAppearance_android_textColor, mExpandedTextColor); } if (a.hasValue(R.styleable.TextAppearance_android_textSize)) { mExpandedTextSize = a.getDimensionPixelSize( R.styleable.TextAppearance_android_textSize, (int) mExpandedTextSize); } a.recycle(); recalculate(); }
public LayoutParams(Context context, AttributeSet attrs) { super(context, attrs); TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SmartRefreshLayout_Layout); backgroundColor = ta.getColor(R.styleable.SmartRefreshLayout_Layout_layout_srlBackgroundColor, backgroundColor); if (ta.hasValue(R.styleable.SmartRefreshLayout_Layout_layout_srlSpinnerStyle)) { spinnerStyle = SpinnerStyle.values()[ta.getInt(R.styleable.SmartRefreshLayout_Layout_layout_srlSpinnerStyle, SpinnerStyle.Translate.ordinal())]; } ta.recycle(); }
public void setTextAppearanceForTextColor(int resId, boolean isForced) { boolean isTextColorForced = isForced || mTextColorId == 0; TypedArray appearance = mView.getContext().obtainStyledAttributes(resId, R.styleable.TextAppearance); if (appearance.hasValue(R.styleable.TextAppearance_android_textColor) && isTextColorForced) { setTextColor(appearance.getResourceId(R.styleable.TextAppearance_android_textColor, 0)); } appearance.recycle(); }
static boolean getAttrHasValue(Context context, AttributeSet attrs, int attr) { TypedArray a = obtainAttributes(context.getResources(), context.getTheme(), attrs, new int[]{attr}); final boolean flag = a.hasValue(0); a.recycle(); return flag; }
public static boolean hasThemeAttr(Context context, @AttrRes int attr) { TEMP_ARRAY[0] = attr; TypedArray a = context.obtainStyledAttributes(null, TEMP_ARRAY); try { return a.hasValue(0); } finally { a.recycle(); } }
public MountainSceneView(Context context, AttributeSet attrs) { super(context, attrs); mMountPaint.setAntiAlias(true); mMountPaint.setStyle(Paint.Style.FILL); mTrunkPaint.setAntiAlias(true); mBranchPaint.setAntiAlias(true); mBoarderPaint.setAntiAlias(true); mBoarderPaint.setStyle(Paint.Style.STROKE); mBoarderPaint.setStrokeWidth(2); mBoarderPaint.setStrokeJoin(Paint.Join.ROUND); TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.MountainSceneView); if (ta.hasValue(R.styleable.MountainSceneView_msvPrimaryColor)) { setPrimaryColor(ta.getColor(R.styleable.MountainSceneView_msvPrimaryColor, 0xff000000)); } mViewportHeight = ta.getDimensionPixelOffset(R.styleable.MountainSceneView_msvViewportHeight, 0); ta.recycle(); updateMountainPath(mMoveFactor, HEIGHT); updateTreePath(mMoveFactor, true); }
public TintAppAlertDialogDividingView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); TypedArray a = context.obtainStyledAttributes(attrs, TINT_ATTRS); if (a.hasValue(0)) { if (a.getResourceId(0, 0) == android.R.color.holo_blue_light) { setBackgroundColor(ThemeUtils.getThemeAttrColor(context, R.attr.themeColorSecondary)); } } } }
public static String getString(TypedArray a, @StyleableRes int index, @StyleableRes int defIndex) { if (a.hasValue(index)) { return a.getString(index); } else { return a.getString(defIndex); } }
static ColorStateList getTintColorList(Context context, AttributeSet attrs, int tintAttr) { TypedArray a = obtainAttributes(context.getResources(), context.getTheme(), attrs, new int[]{tintAttr}); if (!a.hasValue(0)) { a.recycle(); return null; } final ColorStateList cls = TintManager.get(context).getColorStateList(a.getResourceId(0, 0)); a.recycle(); return cls; }
@Override public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) { super.onInflate(activity, attrs, savedInstanceState); TypedArray a = activity.obtainStyledAttributes(attrs, R.styleable.picker_place_picker_fragment); setRadiusInMeters(a.getInt(R.styleable.picker_place_picker_fragment_radius_in_meters, radiusInMeters)); setResultsLimit(a.getInt(R.styleable.picker_place_picker_fragment_results_limit, resultsLimit)); if (a.hasValue(R.styleable.picker_place_picker_fragment_results_limit)) { setSearchText(a.getString(R.styleable.picker_place_picker_fragment_search_text)); } showSearchBox = a.getBoolean(R.styleable.picker_place_picker_fragment_show_search_box, showSearchBox); a.recycle(); }
@Test public void hasValue_withoutValue() throws Exception { TypedArray typedArray = context.obtainStyledAttributes( null, new int[]{R.attr.responses}); assertThat(typedArray.hasValue(0)).isFalse(); }
@Test public void shouldFindInheritedAndroidAttributeInTheme() throws Exception { context.setTheme(R.style.Theme_AnotherTheme); Resources.Theme theme1 = context.getTheme(); TypedArray typedArray = theme1.obtainStyledAttributes(new int[] {R.attr.typeface, android.R.attr.buttonStyle}); assertThat(typedArray.hasValue(0)).isTrue(); // animalStyle assertThat(typedArray.hasValue(1)).isTrue(); // layout_height }
@Test public void withEmptyTheme_returnsEmptyAttributes() throws Exception { assertThat(resources.newTheme().obtainStyledAttributes(new int[] {R.attr.string1}).hasValue(0)) .isFalse(); }
@Test public void forStylesWithImplicitParents_shouldInheritValuesNotDefinedInChild() throws Exception { Resources.Theme theme = resources.newTheme(); theme.applyStyle(R.style.Theme_Robolectric_EmptyParent, true); assertThat(theme.obtainStyledAttributes(new int[] {R.attr.string1}).hasValue(0)).isFalse(); }
@Test public void whenAThemeHasExplicitlyEmptyParentAttr_shouldHaveNoParent() throws Exception { Resources.Theme theme = resources.newTheme(); theme.applyStyle(R.style.Theme_Robolectric_EmptyParent, true); assertThat(theme.obtainStyledAttributes(new int[] {R.attr.string1}).hasValue(0)).isFalse(); }
@Test public void hasValue_withNullValue() throws Exception { TypedArray typedArray = context.obtainStyledAttributes( Robolectric.buildAttributeSet() .addAttribute(R.attr.responses, AttributeResource.NULL_VALUE) .build(), new int[]{R.attr.responses}); assertThat(typedArray.hasValue(0)).isFalse(); }
@Test public void hasValue_withValue() throws Exception { TypedArray typedArray = context.obtainStyledAttributes( Robolectric.buildAttributeSet() .addAttribute(R.attr.responses, "@array/greetings") .build(), new int[]{R.attr.responses}); assertThat(typedArray.hasValue(0)).isTrue(); }