final TypedArray styledAttributes = getContext().getTheme().obtainStyledAttributes( new int[] { android.R.attr.actionBarSize }); mActionBarSize = (int) styledAttributes.getDimension(0, 0); styledAttributes.recycle();
public LiftOff(Context context, AttributeSet attrs) { super(context, attrs); final TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.LiftOff); initialElevation = ta.getDimension(R.styleable.LiftOff_initialElevation, 0f); finalElevation = ta.getDimension(R.styleable.LiftOff_finalElevation, 0f); ta.recycle(); }
public MyCustomElement(Context context, AttributeSet attrs) { super(context, attrs); TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.MyCustomElement, 0, 0); try { distanceExample = ta.getDimension(R.styleable.MyCustomElement_distanceExample, 100.0f); } finally { ta.recycle(); } // ... }
/** * get toolbar height * * @param context * @return */ 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; } }
public static int getToolbarHeight(Context context) { final TypedArray styledAttributes = context.getTheme().obtainStyledAttributes( new int[]{R.attr.actionBarSize}); int toolbarHeight = (int) styledAttributes.getDimension(0, 0); styledAttributes.recycle(); return toolbarHeight; } }
static float getAttrDimension(Context context, AttributeSet attrs, int attr, int defaultValue) { TypedArray a = obtainAttributes(context.getResources(), context.getTheme(), attrs, new int[]{attr}); final float value = a.getDimension(0, defaultValue); a.recycle(); return value; }
public XLHRatingBar(Context context, AttributeSet attrs) { super(context, attrs); TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.XlHRatingBar); countNum = typedArray.getInt(R.styleable.XlHRatingBar_starCount, 5); countSelected = typedArray.getInt(R.styleable.XlHRatingBar_countSelected, 0); canEdit = typedArray.getBoolean(R.styleable.XlHRatingBar_canEdit, false); differentSize = typedArray.getBoolean(R.styleable.XlHRatingBar_differentSize, false); widthAndHeight = typedArray.getDimension(R.styleable.XlHRatingBar_widthAndHeight, ScreenUtils.dpToPxInt(0)); dividerWidth = typedArray.getDimension(R.styleable.XlHRatingBar_dividerWidth, ScreenUtils.dpToPxInt(0)); stateResId = typedArray.getResourceId(R.styleable.XlHRatingBar_stateResId, -1); initView(); }
private void init(AttributeSet attrs, int defStyleAttr) { TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.RainbowTextView); colorSpace = typedArray.getDimension(R.styleable.RainbowTextView_colorSpace, DisplayUtils.dp2px(150)); colorSpeed = typedArray.getDimension(R.styleable.RainbowTextView_colorSpeed, DisplayUtils.dp2px(5)); typedArray.recycle(); mMatrix = new Matrix(); initPaint(); }
@Override public void init(HTextView hTextView, AttributeSet attrs, int defStyle) { super.init(hTextView, attrs, defStyle); TypedArray typedArray = hTextView.getContext().obtainStyledAttributes(attrs, R.styleable.LineTextView); animationDuration = typedArray.getInt(R.styleable.LineTextView_animationDuration, DEFAULT_DURATION); lineColor = typedArray.getColor(R.styleable.LineTextView_lineColor, hTextView.getCurrentTextColor()); lineWidth = typedArray.getDimension(R.styleable.LineTextView_lineWidth, DEFAULT_LINE_WIDTH); typedArray.recycle(); }
public static void initAutoSizeText(AutoSizeTextView view, TypedArray a, int[] ids) { int carbon_autoSizeText = ids[0]; int carbon_autoSizeMinTextSize = ids[1]; int carbon_autoSizeMaxTextSize = ids[2]; int carbon_autoSizeStepGranularity = ids[3]; view.setAutoSizeText(AutoSizeTextMode.values()[a.getInt(carbon_autoSizeText, 0)]); view.setMinTextSize(a.getDimension(carbon_autoSizeMinTextSize, 0)); view.setMaxTextSize(a.getDimension(carbon_autoSizeMaxTextSize, 0)); view.setAutoSizeStepGranularity(a.getDimension(carbon_autoSizeStepGranularity, 1)); }
public float resolveFloatAttr(@AttrRes int attrResId, @DimenRes int defResId) { mAttrs[0] = attrResId; TypedArray a = mTheme.obtainStyledAttributes(mAttrs); try { return a.getDimension(0, resolveFloatRes(defResId)); } finally { a.recycle(); } }
private void init(AttributeSet attrs) { TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.Emojicon); mEmojiconSize = (int) a.getDimension(R.styleable.Emojicon_emojiconSize, getTextSize()); mEmojiconAlignment = a.getInt(R.styleable.Emojicon_emojiconAlignment, DynamicDrawableSpan.ALIGN_BASELINE); mUseSystemDefault = a.getBoolean(R.styleable.Emojicon_emojiconUseSystemDefault, false); a.recycle(); mEmojiconTextSize = (int) getTextSize(); setText(getText()); }
private void init(AttributeSet attrs) { TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.Emojicon); mEmojiconSize = (int) a.getDimension(R.styleable.Emojicon_emojiconSize, getTextSize()); mEmojiconAlignment = a.getInt(R.styleable.Emojicon_emojiconAlignment, DynamicDrawableSpan.ALIGN_BASELINE); mUseSystemDefault = a.getBoolean(R.styleable.Emojicon_emojiconUseSystemDefault, false); a.recycle(); mEmojiconTextSize = (int) getTextSize(); setText(getText()); }
private void init(AttributeSet attrs) { if (attrs == null) { mEmojiconSize = getLineHeight(); } else { TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.Emojicon); mEmojiconSize = (int) a.getDimension(R.styleable.Emojicon_emojiconSize, getLineHeight()); mTextStart = a.getInteger(R.styleable.Emojicon_emojiconTextStart, 0); mTextLength = a.getInteger(R.styleable.Emojicon_emojiconTextLength, -1); a.recycle(); } setText(getText()); }
@Test public void getFraction_shouldReturnDefaultValue() throws Exception { assertThat(context.obtainStyledAttributes(new int[]{android.R.attr.width}).getDimension(0, -1f)) .isEqualTo(-1f); }
@Test public void getDimension_shouldReturnDefaultValue() throws Exception { assertThat(context.obtainStyledAttributes(new int[]{android.R.attr.width}).getDimension(0, -1f)).isEqualTo(-1f); }
private void initPagerTabStrip(AttributeSet attrs, int defStyleAttr) { TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.PagerTabStrip, defStyleAttr, R.style.carbon_PagerTabStrip); setIndicatorHeight(a.getDimension(R.styleable.PagerTabStrip_carbon_indicatorWidth, 2)); setFixed(a.getBoolean(R.styleable.PagerTabStrip_carbon_fixedTabs, true)); Carbon.initTint(this, a, tintIds); a.recycle(); setHorizontalFadingEdgeEnabled(false); setHorizontalScrollBarEnabled(false); content = new LinearLayout(getContext()); addView(content, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); initTabs(); }
@Test public void getDimension_shouldReturnGivenValue() throws Exception { TypedArray typedArray = context.obtainStyledAttributes( Robolectric.buildAttributeSet() .addAttribute(android.R.attr.width, "50dp") .build(), new int[]{android.R.attr.width}); assertThat(typedArray.getDimension(0, -1)).isEqualTo(50f); }
@Test public void obtainAttributes_shouldReturnValuesFromAttributeSet() throws Exception { AttributeSet attributes = Robolectric.buildAttributeSet() .addAttribute(android.R.attr.title, "A title!") .addAttribute(android.R.attr.width, "12px") .addAttribute(android.R.attr.height, "1in") .build(); TypedArray typedArray = resources .obtainAttributes(attributes, new int[]{android.R.attr.height, android.R.attr.width, android.R.attr.title}); assertThat(typedArray.getDimension(0, 0)).isEqualTo(160f); assertThat(typedArray.getDimension(1, 0)).isEqualTo(12f); assertThat(typedArray.getString(2)).isEqualTo("A title!"); typedArray.recycle(); }
public static void initStroke(StrokeView strokeView, TypedArray a, int[] ids) { int carbon_stroke = ids[0]; int carbon_strokeWidth = ids[1]; View view = (View) strokeView; ColorStateList color = getDefaultColorStateList(view, a, carbon_stroke); if (color == null) color = a.getColorStateList(carbon_stroke); if (color != null) strokeView.setStroke(AnimatedColorStateList.fromList(color, animation -> view.postInvalidate())); strokeView.setStrokeWidth(a.getDimension(carbon_strokeWidth, 0)); }