/** * Parse the attributes passed to the view from the XML * * @param a the attributes to parse */ private void parseAttributes(TypedArray a) { this.barWidth = (int) a.getDimension(R.styleable.ProgressWheel_barWidth, this.barWidth); this.rimWidth = (int) a.getDimension(R.styleable.ProgressWheel_rimWidth, this.rimWidth); this.spinSpeed = (int) a.getDimension(R.styleable.ProgressWheel_spinSpeed, this.spinSpeed); this.delayMillis = a.getInteger(R.styleable.ProgressWheel_delayMillis, this.delayMillis); if (this.delayMillis < 0) { this.delayMillis = 0; } this.barColor = a.getColor(R.styleable.ProgressWheel_barColor, this.barColor); this.barLength = (int) a.getDimension(R.styleable.ProgressWheel_barLength, this.barLength); this.textSize = (int) a.getDimension(R.styleable.ProgressWheel_textSize, this.textSize); this.textColor = a.getColor(R.styleable.ProgressWheel_textColor, this.textColor); // if the text is empty , so ignore it if (a.hasValue(R.styleable.ProgressWheel_text)) { setText(a.getString(R.styleable.ProgressWheel_text)); } this.rimColor = a.getColor(R.styleable.ProgressWheel_rimColor, this.rimColor); this.circleColor = a.getColor(R.styleable.ProgressWheel_circleColor, this.circleColor); // Recycle a.recycle(); }
/** * 从TypedArray里面抽取需要的resourceID * * @param typedArr */ private void initLayer(TypedArray typedArr) { removeAllViews(); for (int i = 0; i < typedArr.getIndexCount(); i++) { if (typedArr.getIndex(i) == R.styleable.VDVideoView_layerAttrs) { int resID = -1; // 1.layerAttrs中格式一般为@array/sv_videoview_layers之类的格式 // 先读出其resourceID来,准备加载TypedArray resID = typedArr.getResourceId(R.styleable.VDVideoView_layerAttrs, -1); if (resID == -1) { if (typedArr != null) typedArr.recycle(); throw new IllegalArgumentException("resID=-1"); } readLayerAttrs(resID); } else if (typedArr.getIndex(i) == R.styleable.VDVideoView_canPopupWindow) { int popWindowType = typedArr.getInt(R.styleable.VDVideoView_canPopupWindow, -1); if (popWindowType != -1) { mIsCanPopupWindow = true; mPopupWindowType = popWindowType; } } else if (typedArr.getIndex(i) == R.styleable.VDVideoView_popWindowWidth) { float width = typedArr.getDimension(R.styleable.VDVideoView_popWindowWidth, -1); if (width != -1) { mPopupWindowWidth = (int) width; } } else if (typedArr.getIndex(i) == R.styleable.VDVideoView_popWindowHeight) { float height = typedArr.getDimension(R.styleable.VDVideoView_popWindowHeight, -1); if (height != -1) { mPopupWindowHeight = (int) height; } } } }
public ImageTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ImageTextView); mTextGravity = a.getString(R.styleable.ImageTextView_text_gravity); if (mTextGravity == null) { mTextGravity = GRAVITY_CENTER; } mImageGravity = a.getString(R.styleable.ImageTextView_image_gravity); if (mImageGravity == null) { mImageGravity = GRAVITY_CENTER; } mPosition = a.getString(R.styleable.ImageTextView_position); if (mPosition == null) { mPosition = POSITION_RIGHT; } mSpacing = a.getDimension(R.styleable.ImageTextView_spacing, 0f); mImageWidth = a.getDimension(R.styleable.ImageTextView_image_width, 0f); mImageHeight = a.getDimension(R.styleable.ImageTextView_image_height, 0f); a.recycle(); mText = new TextView(context, attrs, defStyle); mImage = new ImageView(context, attrs, defStyle); addView(mImage); addView(mText); }
/** * Parse the attributes passed to the view from the XML * * @param a the attributes to parse */ private void parseAttributes(TypedArray a) { barWidth = (int) a.getDimension(R.styleable.ProgressWheel_pwBarWidth, barWidth); rimWidth = (int) a.getDimension(R.styleable.ProgressWheel_pwRimWidth, rimWidth); spinSpeed = (int) a.getDimension(R.styleable.ProgressWheel_pwSpinSpeed, spinSpeed); barLength = (int) a.getDimension(R.styleable.ProgressWheel_pwBarLength, barLength); delayMillis = a.getInteger(R.styleable.ProgressWheel_pwDelayMillis, delayMillis); if (delayMillis < 0) { delayMillis = 10; } // Only set the text if it is explicitly defined if (a.hasValue(R.styleable.ProgressWheel_pwText)) { setText(a.getString(R.styleable.ProgressWheel_pwText)); } barColor = a.getColor(R.styleable.ProgressWheel_pwBarColor, barColor); textColor = a.getColor(R.styleable.ProgressWheel_pwTextColor, textColor); rimColor = a.getColor(R.styleable.ProgressWheel_pwRimColor, rimColor); circleColor = a.getColor(R.styleable.ProgressWheel_pwCircleColor, circleColor); contourColor = a.getColor(R.styleable.ProgressWheel_pwContourColor, contourColor); textSize = (int) a.getDimension(R.styleable.ProgressWheel_pwTextSize, textSize); contourSize = a.getDimension(R.styleable.ProgressWheel_pwContourSize, contourSize); a.recycle(); }
/** * Parse the attributes passed to the view from the XML * * @param a the attributes to parse */ private void parseAttributes(TypedArray a) { // We transform the default values from DIP to pixels DisplayMetrics metrics = getContext().getResources().getDisplayMetrics(); barWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, barWidth, metrics); rimWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, rimWidth, metrics); circleRadius = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, circleRadius, metrics); circleRadius = (int) a.getDimension(R.styleable.ProgressWheel_matProg_circleRadius, circleRadius); fillRadius = a.getBoolean(R.styleable.ProgressWheel_matProg_fillRadius, false); barWidth = (int) a.getDimension(R.styleable.ProgressWheel_matProg_barWidth, barWidth); rimWidth = (int) a.getDimension(R.styleable.ProgressWheel_matProg_rimWidth, rimWidth); float baseSpinSpeed = a.getFloat(R.styleable.ProgressWheel_matProg_spinSpeed, spinSpeed / 360.0f); spinSpeed = baseSpinSpeed * 360; barSpinCycleTime = a.getInt(R.styleable.ProgressWheel_matProg_barSpinCycleTime, (int) barSpinCycleTime); barColor = a.getColor(R.styleable.ProgressWheel_matProg_barColor, barColor); rimColor = a.getColor(R.styleable.ProgressWheel_matProg_rimColor, rimColor); linearProgress = a.getBoolean(R.styleable.ProgressWheel_matProg_linearProgress, false); if (a.getBoolean(R.styleable.ProgressWheel_matProg_progressIndeterminate, false)) { spin(); } // Recycle a.recycle(); }
/* Reads the attributes from the layout */ private void initAttrs(AttributeSet attrs) { TypedArray typedArray = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.SegmentedGroup, 0, 0); try { mMarginDp = (int) typedArray.getDimension( R.styleable.SegmentedGroup_border_width, getResources().getDimension(R.dimen.radio_button_stroke_border)); mCornerRadius = typedArray.getDimension( R.styleable.SegmentedGroup_corner_radius, getResources().getDimension(R.dimen.radio_button_conner_radius)); mTintColor = typedArray.getColor( R.styleable.SegmentedGroup_tint_color, getResources().getColor(R.color.radio_button_selected_color)); mCheckedTextColor = typedArray.getColor( R.styleable.SegmentedGroup_checked_text_color, getResources().getColor(android.R.color.white)); } finally { typedArray.recycle(); } }
private void initialize(Context context, AttributeSet attrs, int defStyleAttr) { TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.CardView, defStyleAttr, R.style.CardView_Light); int backgroundColor = a.getColor(R.styleable.CardView_cardBackgroundColor, 0); float radius = a.getDimension(R.styleable.CardView_cardCornerRadius, 0); float elevation = a.getDimension(R.styleable.CardView_cardElevation, 0); float maxElevation = a.getDimension(R.styleable.CardView_cardMaxElevation, 0); mCompatPadding = a.getBoolean(R.styleable.CardView_cardUseCompatPadding, false); mPreventCornerOverlap = a.getBoolean(R.styleable.CardView_cardPreventCornerOverlap, true); int defaultPadding = a.getDimensionPixelSize(R.styleable.CardView_contentPadding, 0); mContentPadding.left = a.getDimensionPixelSize(R.styleable.CardView_contentPaddingLeft, defaultPadding); mContentPadding.top = a.getDimensionPixelSize(R.styleable.CardView_contentPaddingTop, defaultPadding); mContentPadding.right = a.getDimensionPixelSize(R.styleable.CardView_contentPaddingRight, defaultPadding); mContentPadding.bottom = a.getDimensionPixelSize(R.styleable.CardView_contentPaddingBottom, defaultPadding); if (elevation > maxElevation) { maxElevation = elevation; } a.recycle(); IMPL.initialize(this, context, backgroundColor, radius, elevation, maxElevation); }
public MultiCardMenu(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mContext = context; ViewConfiguration vc = ViewConfiguration.get(context); mMaxVelocity = vc.getScaledMaximumFlingVelocity(); mMinVelocity = vc.getScaledMinimumFlingVelocity() * 8; mTouchSlop = vc.getScaledTouchSlop(); mDensity = context.getResources().getDisplayMetrics().density; TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MultiCardMenu, defStyleAttr, 0); MAX_CLICK_DISTANCE = mTitleBarHeightNoDisplay = a.getDimension( R.styleable.MultiCardMenu_title_bar_height_no_display, dip2px(DEFAULT_TITLE_BAR_HEIGHT_NO_DISPLAY)); mTitleBarHeightDisplay = a.getDimension( R.styleable.MultiCardMenu_title_bar_height_display, dip2px(DEFAULT_TITLE_BAR_HEIGHT_DISPLAY)); mMarginTop = a.getDimension(R.styleable.MultiCardMenu_margin_top, dip2px(DEFAULT_CARD_MARGIN_TOP)); mMoveDistanceToTrigger = a.getDimension( R.styleable.MultiCardMenu_move_distance_to_trigger, dip2px(DEFAULT_MOVE_DISTANCE_TO_TRIGGER)); mBackgroundRid = a.getResourceId(R.styleable.MultiCardMenu_background_layout, -1); mDuration = a.getInt(R.styleable.MultiCardMenu_animator_duration, DEFAULT_DURATION); isFade = a.getBoolean(R.styleable.MultiCardMenu_fade, true); mBoundary = a.getBoolean(R.styleable.MultiCardMenu_boundary, false); a.recycle(); initBackgroundView(); }
protected void initByAttributes(TypedArray attributes) { finishedStrokeColor = attributes.getColor(R.styleable.ArcProgress_arc_finished_color, default_finished_color); unfinishedStrokeColor = attributes.getColor(R.styleable.ArcProgress_arc_unfinished_color, default_unfinished_color); textColor = attributes.getColor(R.styleable.ArcProgress_arc_text_color, default_text_color); textSize = attributes.getDimension(R.styleable.ArcProgress_arc_text_size, default_text_size); arcAngle = attributes.getFloat(R.styleable.ArcProgress_arc_angle, default_arc_angle); setMax(attributes.getInt(R.styleable.ArcProgress_arc_max, default_max)); setProgress(attributes.getInt(R.styleable.ArcProgress_arc_progress, 0)); strokeWidth = attributes.getDimension(R.styleable.ArcProgress_arc_stroke_width, default_stroke_width); suffixTextSize = attributes.getDimension( R.styleable.ArcProgress_arc_suffix_text_size, default_suffix_text_size); suffixText = TextUtils.isEmpty(attributes.getString(R.styleable.ArcProgress_arc_suffix_text)) ? default_suffix_text : attributes.getString(R.styleable.ArcProgress_arc_suffix_text); suffixTextPadding = attributes.getDimension( R.styleable.ArcProgress_arc_suffix_text_padding, default_suffix_padding); bottomTextSize = attributes.getDimension( R.styleable.ArcProgress_arc_bottom_text_size, default_bottom_text_size); bottomText = attributes.getString(R.styleable.ArcProgress_arc_bottom_text); }
public void init(AttributeSet attrs) { TypedArray array = getContext().obtainStyledAttributes(attrs, R.styleable.SlantedTextView); mTextSize = array.getDimension(R.styleable.SlantedTextView_slantedTextSize, mTextSize); mTextColor = array.getColor(R.styleable.SlantedTextView_slantedTextColor, mTextColor); mSlantedLength = array.getDimension(R.styleable.SlantedTextView_slantedLength, mSlantedLength); mSlantedBackgroundColor = array.getColor(R.styleable.SlantedTextView_slantedBackgroundColor, mSlantedBackgroundColor); if (array.hasValue(R.styleable.SlantedTextView_slantedText)) { mSlantedText = array.getString(R.styleable.SlantedTextView_slantedText); } if (array.hasValue(R.styleable.SlantedTextView_slantedMode)) { mMode = array.getInt(R.styleable.SlantedTextView_slantedMode, 0); } array.recycle(); mPaint = new Paint(); mPaint.setStyle(Paint.Style.FILL); mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER)); mPaint.setAntiAlias(true); mPaint.setColor(mSlantedBackgroundColor); mTextPaint = new TextPaint(); mTextPaint.setAntiAlias(true); mTextPaint.setTextSize(mTextSize); mTextPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.ADD)); mTextPaint.setColor(mTextColor); mTextPaint.setTextAlign(Paint.Align.CENTER); }
private void initAttributes(TypedArray attributes) { finishedColor = attributes.getColor(R.styleable.RingProgress_finished_color, DEFAULT_FINISHED_COLOR); unfinishedColor = attributes.getColor(R.styleable.RingProgress_unfinished_color, DEFAULT_UNFINISHED_COLOR); innerTextColor = attributes.getColor(R.styleable.RingProgress_inner_text_color, DEFAULT_INNER_TEXT_COLOR); innerTextSize = attributes.getDimension( R.styleable.RingProgress_inner_text_size, DimensionUtils.sp2px(getResources(), DEFAULT_INNER_TEXT_SIZE)); max = attributes.getInt(R.styleable.RingProgress_ring_max, DEFAULT_MAX); progress = attributes.getInt(R.styleable.RingProgress_ring_progress, 0); finishedStrokeWidth = attributes.getDimension( R.styleable.RingProgress_finished_stroke_width, DimensionUtils.dp2px(getResources(), DEFAULT_FINISHED_STROKE_WIDTH)); unfinishedStrokeWidth = attributes.getDimension( R.styleable.RingProgress_unfinished_stroke_width, DimensionUtils.dp2px(getResources(), DEFAULT_UNFINISHED_STROKE_WIDTH)); innerText = attributes.getString(R.styleable.RingProgress_inner_text); startingDegree = attributes.getInt(R.styleable.RingProgress_starting_degree, 0); innerBackgroundColor = attributes.getColor(R.styleable.RingProgress_background_color, DEFAULT_BACKGROUND_COLOR); }
/** @param context used to get the configuration for the drawable from */ protected DrawerArrowDrawable(Context context) { final TypedArray typedArray = context .getTheme() .obtainStyledAttributes( null, R.styleable.DrawerArrowToggle, R.attr.drawerArrowStyle, R.style.Base_Widget_AppCompat_DrawerArrowToggle); mPaint.setAntiAlias(true); // mPaint.setColor(typedArray.getColor(R.styleable.DrawerArrowToggle_color, 0)); mPaint.setColor(Color.parseColor("#ffffff")); mSize = typedArray.getDimensionPixelSize(R.styleable.DrawerArrowToggle_drawableSize, 0); mBarSize = typedArray.getDimension(R.styleable.DrawerArrowToggle_barSize, 0); mTopBottomArrowSize = typedArray.getDimension(R.styleable.DrawerArrowToggle_topBottomBarArrowSize, 0); mBarThickness = typedArray.getDimension(R.styleable.DrawerArrowToggle_thickness, 0); mBarGap = typedArray.getDimension(R.styleable.DrawerArrowToggle_gapBetweenBars, 0); mSpin = typedArray.getBoolean(R.styleable.DrawerArrowToggle_spinBars, true); mMiddleArrowSize = typedArray.getDimension(R.styleable.DrawerArrowToggle_middleBarArrowSize, 0); typedArray.recycle(); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.SQUARE); mPaint.setStrokeWidth(mBarThickness); }
private void initAttr(Context context, AttributeSet attrs) { TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.HorizontalProgressBarWithProgress); mTextSize = (int) ta.getDimension( R.styleable.HorizontalProgressBarWithProgress_progress_text_size, mTextSize); mTextColor = ta.getColor(R.styleable.HorizontalProgressBarWithProgress_progress_text_color, mTextColor); mTextOffset = (int) ta.getDimension( R.styleable.HorizontalProgressBarWithProgress_progress_text_offset, mTextOffset); mReachColor = ta.getColor( R.styleable.HorizontalProgressBarWithProgress_progress_reach_color, mReachColor); mUnReachColor = ta.getColor( R.styleable.HorizontalProgressBarWithProgress_progress_unreach_color, mUnReachColor); mReachHeight = (int) ta.getDimension( R.styleable.HorizontalProgressBarWithProgress_progress_height, mReachHeight); mUnReachHeight = (int) ta.getDimension( R.styleable.HorizontalProgressBarWithProgress_progress_unheight, mUnReachHeight); ta.recycle(); }
public AnotherCustomView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // See attrs.xml TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.AnotherCustomView, defStyle, 0); int leftViewId = typedArray.getResourceId(R.styleable.AnotherCustomView_left_view, 0); int mainViewId = typedArray.getResourceId(R.styleable.AnotherCustomView_main_view, 0); int rightViewId = typedArray.getResourceId(R.styleable.AnotherCustomView_right_view, 0); float leftViewPadding = typedArray.getDimension(R.styleable.AnotherCustomView_left_view_padding, 20.0f); float rightViewPadding = typedArray.getDimension(R.styleable.AnotherCustomView_right_view_padding, 20.0f); mLeftViewId = leftViewId; mMainViewId = mainViewId; mRightViewId = rightViewId; mLeftViewRightPadding = leftViewPadding; mRightViewLeftPadding = rightViewPadding; typedArray.recycle(); setAlwaysDrawnWithCacheEnabled(true); }
private void init(AttributeSet attrs) { if (isInEditMode()) { circleCount = 3; } circleRadius = (int) getResources().getDimension(R.dimen.fvp_default_circle_radius); circlePadding = (int) getResources().getDimension(R.dimen.fvp_default_circle_padding); int inactiveColor = ContextCompat.getColor(getContext(), R.color.fpi_default_indicator_inactive_color); int activeColor = ContextCompat.getColor(getContext(), R.color.fpi_default_indicator_active_color); int gravity = Gravity.CENTER; if (attrs != null) { TypedArray a = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.PageIndicator, 0, 0); circleRadius = (int) a.getDimension(R.styleable.PageIndicator_indicatorRadius, circleRadius); circlePadding = (int) a.getDimension(R.styleable.PageIndicator_indicatorPadding, circlePadding); inactiveColor = a.getColor(R.styleable.PageIndicator_indicatorInactiveColor, inactiveColor); activeColor = a.getColor(R.styleable.PageIndicator_indicatorActiveColor, activeColor); mGravity = a.getInt(R.styleable.PageIndicator_android_gravity, gravity); } activePaint = new Paint(Paint.ANTI_ALIAS_FLAG); activePaint.setColor(activeColor); inactivePaint = new Paint(Paint.ANTI_ALIAS_FLAG); inactivePaint.setColor(inactiveColor); }
/** * Parse the attributes passed to the view from the XML * * @param a the attributes to parse */ private void parseAttributes(TypedArray a) { barWidth = (int) a.getDimension(R.styleable.ProgressWheel_barWidth, barWidth); rimWidth = (int) a.getDimension(R.styleable.ProgressWheel_rimWidth, rimWidth); spinSpeed = (int) a.getDimension(R.styleable.ProgressWheel_spinSpeed, spinSpeed); delayMillis = (int) a.getInteger(R.styleable.ProgressWheel_delayMillis, delayMillis); if (delayMillis < 0) { delayMillis = 0; } barColor = a.getColor(R.styleable.ProgressWheel_barColor, barColor); barLength = (int) a.getDimension(R.styleable.ProgressWheel_barLength, barLength); textSize = (int) a.getDimension(R.styleable.ProgressWheel_textSize, textSize); textColor = (int) a.getColor(R.styleable.ProgressWheel_textColor, textColor); setText(a.getString(R.styleable.ProgressWheel_text)); rimColor = (int) a.getColor(R.styleable.ProgressWheel_rimColor, rimColor); circleColor = (int) a.getColor(R.styleable.ProgressWheel_circleColor, circleColor); }
private void initAttrs(Context context, AttributeSet attrs) { TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.DownloadProgressView, 0, 0); try { mRadius = array.getDimension(R.styleable.DownloadProgressView_circleRadius, 0); mStrokeWidth = array.getDimension(R.styleable.DownloadProgressView_strokeWidth, 0); mLineWidth = array.getDimension(R.styleable.DownloadProgressView_lineWidth, 0); mProgressDuration = array.getInteger( R.styleable.DownloadProgressView_progressDuration, DEFAULT_PROGRESS_DURATION); mResultDuration = array.getInteger( R.styleable.DownloadProgressView_resultDuration, DEFAULT_RESULT_DURATION); mProgressBackgroundColor = array.getColor(R.styleable.DownloadProgressView_progressBackgroundColor, 0); mDrawingColor = array.getColor(R.styleable.DownloadProgressView_drawingColor, 0); mProgressColor = array.getColor(R.styleable.DownloadProgressView_progressColor, 0); mCircleBackgroundColor = array.getColor(R.styleable.DownloadProgressView_circleBackgroundColor, 0); mOvershootValue = array.getFloat(R.styleable.DownloadProgressView_overshootValue, DEFAULT_OVERSHOOT_VALUE); } finally { array.recycle(); } }
public RoundProgressBar(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); paint = new Paint(); TypedArray mTypedArray = context.obtainStyledAttributes(attrs, R.styleable.RoundProgressBar); // 获取自定义属性和默认值,第一个参数是从用户属性中得到的设置,如果用户没有设置,那么就用默认的属性,即:第二个参数 // 圆环的颜色 ringColor = mTypedArray.getColor(R.styleable.RoundProgressBar_ringColor, 0xff50c0e9); // 圆环进度条的颜色 ringProgressColor = mTypedArray.getColor(R.styleable.RoundProgressBar_ringProgressColor, 0xffffc641); // 文字的颜色 textColor = mTypedArray.getColor(R.styleable.RoundProgressBar_textColor, 0xffff5f5f); // 文字的大小 textSize = mTypedArray.getDimension(R.styleable.RoundProgressBar_textSize, 25); // 圆环的宽度 ringWidth = mTypedArray.getDimension(R.styleable.RoundProgressBar_ringWidth, 10); // 最大进度 max = mTypedArray.getInteger(R.styleable.RoundProgressBar_max, 100); // 当前进度 progress = mTypedArray.getInt(R.styleable.RoundProgressBar_progress, 30); // 是否显示中间的进度 textIsDisplayable = mTypedArray.getBoolean(R.styleable.RoundProgressBar_textIsDisplayable, true); // 进度的风格,实心或者空心 style = mTypedArray.getInt(R.styleable.RoundProgressBar_style, 0); // 进度开始的角度数 startAngle = mTypedArray.getInt(R.styleable.RoundProgressBar_startAngle, -90); // 圆心的颜色 centreColor = mTypedArray.getColor(R.styleable.RoundProgressBar_centreColor, 0); // 回收资源 mTypedArray.recycle(); }
public CircleFlowIndicator(Context context, AttributeSet attrs) { super(context, attrs); // Retrieve styles attributs TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircleFlowIndicator); // Gets the inactive circle type, defaulting to "fill" int activeType = a.getInt(R.styleable.CircleFlowIndicator_activeType, STYLE_FILL); int activeDefaultColor = 0xFFFFFFFF; // Get a custom inactive color if there is one int activeColor = a.getColor(R.styleable.CircleFlowIndicator_activeColor, activeDefaultColor); // Gets the inactive circle type, defaulting to "stroke" int inactiveType = a.getInt(R.styleable.CircleFlowIndicator_inactiveType, STYLE_STROKE); int inactiveDefaultColor = 0x44FFFFFF; // Get a custom inactive color if there is one int inactiveColor = a.getColor(R.styleable.CircleFlowIndicator_inactiveColor, inactiveDefaultColor); // Retrieve the radius radius = a.getDimension(R.styleable.CircleFlowIndicator_radius, 4.0f); circleSeparation = a.getDimension(R.styleable.CircleFlowIndicator_circleSeparation, 2 * radius + radius); activeRadius = a.getDimension(R.styleable.CircleFlowIndicator_activeRadius, 0.5f); // Retrieve the fade out time fadeOutTime = a.getInt(R.styleable.CircleFlowIndicator_fadeOut, 0); mCentered = a.getBoolean(R.styleable.CircleFlowIndicator_centered, false); initColors(activeColor, inactiveColor, activeType, inactiveType); }
// Set style on component (XML attributes) private void styleable(AttributeSet attrs) { TypedArray t = getContext().obtainStyledAttributes(attrs, com.skullab.chess.R.styleable.Chessboard); boolean enable_notation = t.getBoolean(com.skullab.chess.R.styleable.Chessboard_enableNotation, true); int cells_size = (int) t.getDimension(com.skullab.chess.R.styleable.Chessboard_cellsSize, 35); float text_size = t.getDimension(com.skullab.chess.R.styleable.Chessboard_notationTextSize, 12); int text_color = t.getColor(com.skullab.chess.R.styleable.Chessboard_notationTextColor, Color.WHITE); String text_typeface = t.getString(com.skullab.chess.R.styleable.Chessboard_notationTypeface); if (text_typeface != null) { AssetManager am = this.getResources().getAssets(); Typeface type = Typeface.createFromAsset(am, text_typeface); setNotationTypeface(type); } /*@deprecated int white_cells_color = t.getColor(com.skullab.chess.R.styleable.Chessboard_whiteCellsColor,com.skullab.chess.R.color.white); int black_cells_color = t.getColor(com.skullab.chess.R.styleable.Chessboard_blackCellsColor,com.skullab.chess.R.color.black); setWhiteCellsColor(white_cells_color); setBlackCellsColor(black_cells_color);*/ // white cells background Drawable w_c_b = t.getDrawable(com.skullab.chess.R.styleable.Chessboard_whiteCellsBackground); if (w_c_b != null) { setWhiteCellsBackground(w_c_b); } else { int white_color = t.getColor(com.skullab.chess.R.styleable.Chessboard_whiteCellsBackground, Color.WHITE); setWhiteCellsBackground(white_color); } // black cells background Drawable b_c_b = t.getDrawable(com.skullab.chess.R.styleable.Chessboard_blackCellsBackground); if (b_c_b != null) { setBlackCellsBackground(b_c_b); } else { int black_color = t.getColor(com.skullab.chess.R.styleable.Chessboard_blackCellsBackground, Color.BLACK); setBlackCellsBackground(black_color); } // notation background Drawable notation_drawable = t.getDrawable(com.skullab.chess.R.styleable.Chessboard_notationBackground); if (notation_drawable != null) { setNotationBackground(notation_drawable); } else { int notation_color = t.getColor(com.skullab.chess.R.styleable.Chessboard_notationBackground, Color.BLACK); setNotationBackgroundColor(notation_color); } enableNotation(enable_notation); setCellsSize(cells_size); setNotationTextSize(text_size); setNotationTextColor(text_color); }
private void init(Context context, AttributeSet attrs) { mDisplayMetrics = context.getResources().getDisplayMetrics(); mStrokeWidth = mStrokeWidth * mDisplayMetrics.density; mTextSize = mTextSize * mDisplayMetrics.scaledDensity; final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProgressPieView); final Resources res = getResources(); mMax = a.getInteger(R.styleable.ProgressPieView_max1, mMax); mProgress = a.getInteger(R.styleable.ProgressPieView_progress1, mProgress); mStartAngle = a.getInt(R.styleable.ProgressPieView_startAngle, mStartAngle); mStrokeWidth = a.getDimension(R.styleable.ProgressPieView_strokeWidth, mStrokeWidth); mTypeface = a.getString(R.styleable.ProgressPieView_typeface); mTextSize = a.getDimension(R.styleable.ProgressPieView_android_textSize, mTextSize); mText = a.getString(R.styleable.ProgressPieView_android_text); mShowStroke = a.getBoolean(R.styleable.ProgressPieView_showStroke, mShowStroke); mShowText = a.getBoolean(R.styleable.ProgressPieView_showText, mShowText); mImage = a.getDrawable(R.styleable.ProgressPieView_image); int backgroundColor = res.getColor(R.color.default_background_color); backgroundColor = a.getColor(R.styleable.ProgressPieView_backgroundColor, backgroundColor); int progressColor = res.getColor(R.color.default_progress_color); progressColor = a.getColor(R.styleable.ProgressPieView_progressColor1, progressColor); int strokeColor = res.getColor(R.color.default_stroke_color); strokeColor = a.getColor(R.styleable.ProgressPieView_strokeColor, strokeColor); int textColor = res.getColor(R.color.default_text_color); textColor = a.getColor(R.styleable.ProgressPieView_android_textColor, textColor); mProgressFillType = a.getInteger(R.styleable.ProgressPieView_progressFillType, mProgressFillType); a.recycle(); mBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mBackgroundPaint.setColor(backgroundColor); mBackgroundPaint.setStyle(Paint.Style.FILL); mProgressPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mProgressPaint.setColor(progressColor); mProgressPaint.setStyle(Paint.Style.FILL); mStrokePaint = new Paint(Paint.ANTI_ALIAS_FLAG); mStrokePaint.setColor(strokeColor); mStrokePaint.setStyle(Paint.Style.STROKE); mStrokePaint.setStrokeWidth(mStrokeWidth); mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mTextPaint.setColor(textColor); mTextPaint.setTextSize(mTextSize); mTextPaint.setTextAlign(Paint.Align.CENTER); mInnerRectF = new RectF(); mImageRect = new Rect(); }
public CardSlidePanel(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.card); bottomMarginTop = (int) a.getDimension(R.styleable.card_bottomMarginTop, bottomMarginTop); yOffsetStep = (int) a.getDimension(R.styleable.card_yOffsetStep, yOffsetStep); // 滑动相关类 mDragHelper = ViewDragHelper.create(this, 10f, new DragHelperCallback()); mDragHelper.setEdgeTrackingEnabled(ViewDragHelper.EDGE_LEFT); a.recycle(); }
// 从资源文件获取数据 private void initObtainStyledAttr(Context context, AttributeSet attrs) { TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.SwipeMenu); mType = array.getInteger(R.styleable.SwipeMenu_sm_type, 1111); mDragWipeOffset = (int) array.getDimension(R.styleable.SwipeMenu_sm_dragoffset, SizeUtil.Dp2Px(context, 100)); mMenuOffset = (int) array.getDimension(R.styleable.SwipeMenu_sm_menuoffset, SizeUtil.Dp2Px(context, 50)); mStartScale = array.getFloat(R.styleable.SwipeMenu_sm_startscale, 0.2f); mStartAlpha = array.getFloat(R.styleable.SwipeMenu_sm_startalpha, 0.2f); mStart3DAngle = array.getInteger(R.styleable.SwipeMenu_sm_start3dangle, 60); array.recycle(); }
public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (isInEditMode()) return; // Load defaults from resources final Resources res = getResources(); final int defaultPageColor = res.getColor(R.color.default_circle_indicator_page_color); final int defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color); final int defaultOrientation = res.getInteger(R.integer.default_circle_indicator_orientation); final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color); final float defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width); final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius); final boolean defaultCentered = res.getBoolean(R.bool.default_circle_indicator_centered); final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap); // Retrieve styles attributes TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CirclePageIndicator, defStyle, 0); mCentered = a.getBoolean(R.styleable.CirclePageIndicator_centered, defaultCentered); mOrientation = a.getInt(R.styleable.CirclePageIndicator_android_orientation, defaultOrientation); mPaintPageFill.setStyle(Style.FILL); mPaintPageFill.setColor( a.getColor(R.styleable.CirclePageIndicator_pageColor, defaultPageColor)); mPaintStroke.setStyle(Style.STROKE); mPaintStroke.setColor( a.getColor(R.styleable.CirclePageIndicator_strokeColor, defaultStrokeColor)); mPaintStroke.setStrokeWidth( a.getDimension(R.styleable.CirclePageIndicator_strokeWidth, defaultStrokeWidth)); mPaintFill.setStyle(Style.FILL); mPaintFill.setColor(a.getColor(R.styleable.CirclePageIndicator_fillColor, defaultFillColor)); // custom------ /*mPaintText.setTextAlign(Align.CENTER); mPaintText.setTextSize(15); mPaintText.setColor(Color.WHITE);*/ // ----------- mRadius = a.getDimension(R.styleable.CirclePageIndicator_radius, defaultRadius); mSnap = a.getBoolean(R.styleable.CirclePageIndicator_snap, defaultSnap); Drawable background = a.getDrawable(R.styleable.CirclePageIndicator_android_background); if (background != null) { setBackgroundDrawable(background); } a.recycle(); final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); }
private void init(Context context, AttributeSet attrs) { TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.FamiliarRecyclerView); Drawable divider = ta.getDrawable(R.styleable.FamiliarRecyclerView_frv_divider); int dividerHeight = (int) ta.getDimension(R.styleable.FamiliarRecyclerView_frv_dividerHeight, -1); mVerticalDivider = ta.getDrawable(R.styleable.FamiliarRecyclerView_frv_dividerVertical); mHorizontalDivider = ta.getDrawable(R.styleable.FamiliarRecyclerView_frv_dividerHorizontal); mVerticalDividerHeight = (int) ta.getDimension(R.styleable.FamiliarRecyclerView_frv_dividerVerticalHeight, -1); mHorizontalDividerHeight = (int) ta.getDimension(R.styleable.FamiliarRecyclerView_frv_dividerHorizontalHeight, -1); mItemViewBothSidesMargin = (int) ta.getDimension(R.styleable.FamiliarRecyclerView_frv_itemViewBothSidesMargin, 0); mEmptyViewResId = ta.getResourceId(R.styleable.FamiliarRecyclerView_frv_emptyView, -1); isKeepShowHeadOrFooter = ta.getBoolean(R.styleable.FamiliarRecyclerView_frv_isEmptyViewKeepShowHeadOrFooter, false); isHeaderDividersEnabled = ta.getBoolean(R.styleable.FamiliarRecyclerView_frv_headerDividersEnabled, false); isFooterDividersEnabled = ta.getBoolean(R.styleable.FamiliarRecyclerView_frv_footerDividersEnabled, false); if (ta.hasValue(R.styleable.FamiliarRecyclerView_frv_layoutManager)) { int layoutManagerType = ta.getInt(R.styleable.FamiliarRecyclerView_frv_layoutManager, DEF_LAYOUT_MANAGER_TYPE); int layoutManagerOrientation = ta.getInt( R.styleable.FamiliarRecyclerView_frv_layoutManagerOrientation, DEF_LAYOUT_MANAGER_ORIENTATION); boolean isReverseLayout = ta.getBoolean(R.styleable.FamiliarRecyclerView_frv_isReverseLayout, false); int gridSpanCount = ta.getInt(R.styleable.FamiliarRecyclerView_frv_spanCount, DEF_GRID_SPAN_COUNT); switch (layoutManagerType) { case LAYOUT_MANAGER_TYPE_LINEAR: processGridDivider(divider, dividerHeight, false, layoutManagerOrientation); setLayoutManager( new LinearLayoutManager(context, layoutManagerOrientation, isReverseLayout)); break; case LAYOUT_MANAGER_TYPE_GRID: processGridDivider(divider, dividerHeight, false, layoutManagerOrientation); setLayoutManager( new GridLayoutManager( context, gridSpanCount, layoutManagerOrientation, isReverseLayout)); break; case LAYOUT_MANAGER_TYPE_STAGGERED_GRID: processGridDivider(divider, dividerHeight, false, layoutManagerOrientation); setLayoutManager(new StaggeredGridLayoutManager(gridSpanCount, layoutManagerOrientation)); break; } } ta.recycle(); }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) public CirclePageIndicatorBlack(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (isInEditMode()) return; // Load defaults from resources final Resources res = getResources(); final int defaultPageColor = res.getColor(R.color.text_normal); final int defaultFillColor = res.getColor(R.color.text_bold); final int defaultOrientation = res.getInteger(R.integer.default_circle_indicator_orientation); final int defaultStrokeColor = res.getColor(R.color.text_normal); final float defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width); final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius_black); final boolean defaultCentered = res.getBoolean(R.bool.default_circle_indicator_centered); final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap); // Retrieve styles attributes TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CirclePageIndicator, defStyle, 0); mCentered = a.getBoolean(R.styleable.CirclePageIndicator_centered, defaultCentered); mOrientation = a.getInt(R.styleable.CirclePageIndicator_android_orientation, defaultOrientation); mPaintPageFill.setStyle(Style.FILL); mPaintPageFill.setColor( a.getColor(R.styleable.CirclePageIndicator_pageColor, defaultPageColor)); mPaintStroke.setStyle(Style.STROKE); mPaintStroke.setColor( a.getColor(R.styleable.CirclePageIndicator_strokeColor, defaultStrokeColor)); mPaintStroke.setStrokeWidth( a.getDimension(R.styleable.CirclePageIndicator_strokeWidth, defaultStrokeWidth)); mPaintFill.setStyle(Style.FILL); mPaintFill.setColor(a.getColor(R.styleable.CirclePageIndicator_fillColor, defaultFillColor)); mRadius = a.getDimension(R.styleable.CirclePageIndicator_radius, defaultRadius); mSnap = a.getBoolean(R.styleable.CirclePageIndicator_snap, defaultSnap); Drawable background = a.getDrawable(R.styleable.CirclePageIndicator_android_background); if (background != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { setBackground(background); } else { setBackgroundDrawable(background); } } a.recycle(); final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); }
public SpacingTextView(Context context, AttributeSet attrs) { super(context, attrs); TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.TuZhaospacingtextview, 0, 0); oneMarginLeft = typedArray.getDimension(R.styleable.TuZhaospacingtextview_zMarginLeft, 0); lineSpace = typedArray.getDimensionPixelOffset(R.styleable.TuZhaospacingtextview_zLineSpace, 0); bottomSpace = typedArray.getDimension(R.styleable.TuZhaospacingtextview_zBottomSpace, 10); isGravityCenter = typedArray.getBoolean(R.styleable.TuZhaospacingtextview_zIsGravityCenter, false); Log.i("TAG", "oneMarginLeft--" + oneMarginLeft); Log.i("TAG", "lineSpace--" + lineSpace); }
/** * Does all the functions of the constructor for RangeBar. Called by both RangeBar constructors in * lieu of copying the code for each constructor. * * @param context Context from the constructor. * @param attrs AttributeSet from the constructor. * @return none */ private void rangeBarInit(Context context, AttributeSet attrs) { TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.RangeBar, 0, 0); try { // Sets the values of the user-defined attributes based on the XML // attributes. final Integer tickCount = ta.getInteger(R.styleable.RangeBar_tickCount, DEFAULT_TICK_COUNT); if (isValidTickCount(tickCount)) { // Similar functions performed above in setTickCount; make sure // you know how they interact mTickCount = tickCount; mLeftIndex = 0; mRightIndex = mTickCount - 1; if (mListener != null) { mListener.onIndexChangeListener(this, mLeftIndex, mRightIndex); } } else { Log.e(TAG, "tickCount less than 2; invalid tickCount. XML input ignored."); } mTickHeightDP = ta.getDimension(R.styleable.RangeBar_tickHeight, DEFAULT_TICK_HEIGHT_DP); mBarWeight = ta.getDimension(R.styleable.RangeBar_barWeight, DEFAULT_BAR_WEIGHT_PX); mBarColor = ta.getColor(R.styleable.RangeBar_barColor, DEFAULT_BAR_COLOR); mConnectingLineWeight = ta.getDimension( R.styleable.RangeBar_connectingLineWeight, DEFAULT_CONNECTING_LINE_WEIGHT_PX); mConnectingLineColor = ta.getColor(R.styleable.RangeBar_connectingLineColor, DEFAULT_CONNECTING_LINE_COLOR); mThumbRadiusDP = ta.getDimension(R.styleable.RangeBar_thumbRadius, DEFAULT_THUMB_RADIUS_DP); mThumbImageNormal = ta.getResourceId(R.styleable.RangeBar_thumbImageNormal, DEFAULT_THUMB_IMAGE_NORMAL); mThumbImagePressed = ta.getResourceId(R.styleable.RangeBar_thumbImagePressed, DEFAULT_THUMB_IMAGE_PRESSED); mThumbColorNormal = ta.getColor(R.styleable.RangeBar_thumbColorNormal, DEFAULT_THUMB_COLOR_NORMAL); mThumbColorPressed = ta.getColor(R.styleable.RangeBar_thumbColorPressed, DEFAULT_THUMB_COLOR_PRESSED); } finally { ta.recycle(); } }
private void init(Context context, AttributeSet attrs) { // set scroll mode setOverScrollMode(OVER_SCROLL_NEVER); if (null != attrs) { TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.PullScrollView); if (ta != null) { mHeaderHeight = (int) ta.getDimension(R.styleable.PullScrollView_headerHeight, -1); mHeaderVisibleHeight = (int) ta.getDimension(R.styleable.PullScrollView_headerVisibleHeight, -1); ta.recycle(); } } }
/** * 初始化,获取设置的属性 * * @param context * @param attrs */ private void init(Context context, AttributeSet attrs) { TypedArray attribute = context.obtainStyledAttributes(attrs, R.styleable.NumberPicker); unitHeight = (int) attribute.getDimension(R.styleable.NumberPicker_unitHight, 32); normalFont = attribute.getDimension(R.styleable.NumberPicker_normalTextSize, 14.0f); selectedFont = attribute.getDimension(R.styleable.NumberPicker_selecredTextSize, 22.0f); itemNumber = attribute.getInt(R.styleable.NumberPicker_itemNumber, 7); normalColor = attribute.getColor(R.styleable.NumberPicker_normalTextColor, 0xff000000); selectedColor = attribute.getColor(R.styleable.NumberPicker_selecredTextColor, 0xffff0000); lineColor = attribute.getColor(R.styleable.NumberPicker_lineColor, 0xff000000); maskHight = attribute.getDimension(R.styleable.NumberPicker_maskHight, 48.0f); noEmpty = attribute.getBoolean(R.styleable.NumberPicker_noEmpty, false); isEnable = attribute.getBoolean(R.styleable.NumberPicker_isEnable, true); attribute.recycle(); controlHeight = itemNumber * unitHeight; }