int[] textSizeAttr = new int[] { android.R.attr.textSize }; int indexOfAttrTextSize = 0; TypedArray a = context.obtainStyledAttributes(typedValue.data, textSizeAttr); int textSize = a.getDimensionPixelSize(indexOfAttrTextSize, -1); a.recycle();
private void obtainAttributes(Context context, AttributeSet attrs) { TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.MsgView); backgroundColor = ta.getColor(R.styleable.MsgView_mv_backgroundColor, Color.TRANSPARENT); cornerRadius = ta.getDimensionPixelSize(R.styleable.MsgView_mv_cornerRadius, 0); strokeWidth = ta.getDimensionPixelSize(R.styleable.MsgView_mv_strokeWidth, 0); strokeColor = ta.getColor(R.styleable.MsgView_mv_strokeColor, Color.TRANSPARENT); isRadiusHalfHeight = ta.getBoolean(R.styleable.MsgView_mv_isRadiusHalfHeight, false); isWidthHeightEqual = ta.getBoolean(R.styleable.MsgView_mv_isWidthHeightEqual, false); ta.recycle(); }
public ReflowText(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ReflowText); velocity = a.getDimensionPixelSize(R.styleable.ReflowText_velocity, velocity); minDuration = a.getInt(R.styleable.ReflowText_minDuration, (int) minDuration); maxDuration = a.getInt(R.styleable.ReflowText_maxDuration, (int) maxDuration); staggerDelay = a.getInt(R.styleable.ReflowText_staggerDelay, (int) staggerDelay); freezeFrame = a.getBoolean(R.styleable.ReflowText_freezeFrame, false); a.recycle(); }
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); } }
final TypedArray ta = c.obtainStyledAttributes(attrs, R.styleable.ButteryProgressBar); try { mBarColor = ta.getColor(R.styleable.ButteryProgressBar_barColor, c.getResources().getColor(android.R.color.holo_blue_light)); mSolidBarHeight = ta.getDimensionPixelSize( R.styleable.ButteryProgressBar_barHeight, Math.round(DEFAULT_BAR_HEIGHT_DP * mDensity)); mSolidBarDetentWidth = ta.getDimensionPixelSize( R.styleable.ButteryProgressBar_detentWidth, Math.round(DEFAULT_DETENT_WIDTH_DP * mDensity)); } finally { ta.recycle(); }
public CircleImageView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircleImageView, defStyle, 0); mBorderWidth = a.getDimensionPixelSize(R.styleable.CircleImageView_civ_border_width, DEFAULT_BORDER_WIDTH); mBorderColor = a.getColor(R.styleable.CircleImageView_civ_border_color, DEFAULT_BORDER_COLOR); mBorderOverlay = a.getBoolean(R.styleable.CircleImageView_civ_border_overlay, DEFAULT_BORDER_OVERLAY); mCircleBackgroundColor = a.getColor(R.styleable.CircleImageView_civ_circle_background_color, DEFAULT_CIRCLE_BACKGROUND_COLOR); a.recycle(); init(); }
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 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 CircleImageView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircleImageView, defStyle, 0); mBorderWidth = a.getDimensionPixelSize(R.styleable.CircleImageView_border_width, DEFAULT_BORDER_WIDTH); mBorderColor = a.getColor(R.styleable.CircleImageView_border_color, DEFAULT_BORDER_COLOR); mBorderOverlay = a.getBoolean(R.styleable.CircleImageView_border_overlay, DEFAULT_BORDER_OVERLAY); a.recycle(); init(); }
static int getAttrDimensionPixelSize(Context context, AttributeSet attrs, int attr, int defaultValue) { TypedArray a = obtainAttributes(context.getResources(), context.getTheme(), attrs, new int[]{attr}); final int value = a.getDimensionPixelSize(0, defaultValue); a.recycle(); return value; }
public static int getThemeAttrDimensionPixelSize(Context context, @AttrRes int attr) { TEMP_ARRAY[0] = attr; TypedArray a = context.obtainStyledAttributes(null, TEMP_ARRAY); try { return a.getDimensionPixelSize(0, 0); } finally { a.recycle(); } }
public CircleImageView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircleImageView, defStyle, 0); mBorderWidth = a.getDimensionPixelSize(R.styleable.CircleImageView_border_width, DEFAULT_BORDER_WIDTH); mBorderColor = a.getColor(R.styleable.CircleImageView_border_color, DEFAULT_BORDER_COLOR); mBorderOverlay = a.getBoolean(R.styleable.CircleImageView_border_overlay, DEFAULT_BORDER_OVERLAY); a.recycle(); init(); }
/** * This method setups Paint object for the crop guidelines. */ @SuppressWarnings("deprecation") private void initCropGridStyle(@NonNull TypedArray a) { int cropGridStrokeSize = a.getDimensionPixelSize(R.styleable.ucrop_UCropView_ucrop_grid_stroke_size, getResources().getDimensionPixelSize(R.dimen.ucrop_default_crop_grid_stoke_width)); int cropGridColor = a.getColor(R.styleable.ucrop_UCropView_ucrop_grid_color, getResources().getColor(R.color.ucrop_color_default_crop_grid)); mCropGridPaint.setStrokeWidth(cropGridStrokeSize); mCropGridPaint.setColor(cropGridColor); mCropGridRowCount = a.getInt(R.styleable.ucrop_UCropView_ucrop_grid_row_count, DEFAULT_CROP_GRID_ROW_COUNT); mCropGridColumnCount = a.getInt(R.styleable.ucrop_UCropView_ucrop_grid_column_count, DEFAULT_CROP_GRID_COLUMN_COUNT); }
public EpoxyRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); if (attrs != null) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.EpoxyRecyclerView, defStyleAttr, 0); setItemSpacingPx(a.getDimensionPixelSize(R.styleable.EpoxyRecyclerView_itemSpacing, 0)); a.recycle(); } init(); }
private void init(Context context, AttributeSet attrs) { if (attrs != null) { int[] attrsArray = { android.R.attr.columnWidth }; TypedArray array = context.obtainStyledAttributes(attrs, attrsArray); mColumnWidth = array.getDimensionPixelSize(0, -1); array.recycle(); } mGridLayoutManager = new GridLayoutManager(getContext(), 1); setLayoutManager(mGridLayoutManager); }
private void init(Context context, AttributeSet attrs) { setClipChildren(false); TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.MultiViewPager); setMaxWidth(ta.getDimensionPixelSize(R.styleable.MultiViewPager_android_maxWidth, -1)); setMaxHeight(ta.getDimensionPixelSize(R.styleable.MultiViewPager_android_maxHeight, -1)); setMatchChildWidth(ta.getResourceId(R.styleable.MultiViewPager_matchChildWidth, 0)); ta.recycle(); }
public int resolveDimenSizeAttr(@AttrRes int attrResId, @DimenRes int defResId) { mAttrs[0] = attrResId; TypedArray a = mTheme.obtainStyledAttributes(mAttrs); try { return a.getDimensionPixelSize(0, resolveDimenSizeRes(defResId)); } finally { a.recycle(); } }
private int getActionBarSize() { TypedValue typedValue = new TypedValue(); int[] textSizeAttr = new int[]{R.attr.actionBarSize}; int indexOfAttrTextSize = 0; TypedArray a = obtainStyledAttributes(typedValue.data, textSizeAttr); int actionBarSize = a.getDimensionPixelSize(indexOfAttrTextSize, -1); a.recycle(); return actionBarSize; }
@Test public void dimenRefRef() throws Exception { AttributeSet attributeSet = Robolectric.buildAttributeSet() .addAttribute(android.R.attr.layout_height, "@dimen/ref_to_px_dimen") .build(); TypedArray typedArray = resources.newTheme().obtainStyledAttributes( attributeSet, new int[]{android.R.attr.layout_height}, 0, 0); assertThat(typedArray.getDimensionPixelSize(0, -1)).isEqualTo(15); }
@Test public void dimenRef() throws Exception { AttributeSet attributeSet = Robolectric.buildAttributeSet() .addAttribute(android.R.attr.layout_height, "@dimen/test_px_dimen") .build(); TypedArray typedArray = resources.newTheme().obtainStyledAttributes( attributeSet, new int[]{android.R.attr.layout_height}, 0, 0); assertThat(typedArray.getDimensionPixelSize(0, -1)).isEqualTo(15); }