List of usage examples for android.content.res TypedArray getDrawable
@Nullable public Drawable getDrawable(@StyleableRes int index)
From source file:com.skumar.flexibleciruclarseekbar.CircularSeekBar.java
private void init(Context context, AttributeSet attrs, int defStyle) { Log.d(TAG, "Initialising CircularSeekBar ..."); float density = context.getResources().getDisplayMetrics().density; // Defaults, may need to link this into theme settings int arcColor = Color.GREEN; int progressColor = Color.BLUE; int needleColor = Color.BLACK; int thumbHalfHeight = 0; int thumbHalfWidth = 0; mThumb = ContextCompat.getDrawable(getContext(), R.drawable.circular_slider_drawable); // Convert progress width to pixels for current density mProgressWidth = (int) (mProgressWidth * density); if (attrs != null) { // Attribute initialization final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircularSeekBar, defStyle, 0); Drawable thumb = a.getDrawable(R.styleable.CircularSeekBar_thumb); if (thumb != null) { mThumb = thumb;// www . jav a2 s . c o m } thumbHalfHeight = mThumb.getIntrinsicHeight() / 2; thumbHalfWidth = mThumb.getIntrinsicWidth() / 2; mThumb.setBounds(-thumbHalfWidth, -thumbHalfHeight, thumbHalfWidth, thumbHalfHeight); mMax = a.getInteger(R.styleable.CircularSeekBar_max, mMax); mProgress = a.getFloat(R.styleable.CircularSeekBar_progress, mProgress); mProgressWidth = (int) a.getDimension(R.styleable.CircularSeekBar_progressWidth, mProgressWidth); mArcWidth = (int) a.getDimension(R.styleable.CircularSeekBar_arcWidth, mArcWidth); mStartAngle = a.getInt(R.styleable.CircularSeekBar_startAngle, mStartAngle); mSweepAngle = a.getInt(R.styleable.CircularSeekBar_sweepAngle, mSweepAngle); mRotation = a.getInt(R.styleable.CircularSeekBar_rotation, mRotation); mRoundedEdges = a.getBoolean(R.styleable.CircularSeekBar_roundEdges, mRoundedEdges); mTouchInside = a.getBoolean(R.styleable.CircularSeekBar_touchInside, mTouchInside); mClockwise = a.getBoolean(R.styleable.CircularSeekBar_clockwise, mClockwise); mEnabled = a.getBoolean(R.styleable.CircularSeekBar_enabled, mEnabled); arcColor = a.getColor(R.styleable.CircularSeekBar_arcColor, arcColor); progressColor = a.getColor(R.styleable.CircularSeekBar_progressColor, progressColor); a.recycle(); } mProgress = (mProgress > mMax) ? mMax : mProgress; mProgress = (mProgress < 0) ? 0 : mProgress; mSweepAngle = (mSweepAngle > 360) ? 360 : mSweepAngle; mSweepAngle = (mSweepAngle < 0) ? 0 : mSweepAngle; mProgressSweep = mProgress / mMax * mSweepAngle; mStartAngle = (mStartAngle > 360) ? 0 : mStartAngle; mStartAngle = (mStartAngle < 0) ? 0 : mStartAngle; mArcPaint = new Paint(); mArcPaint.setColor(arcColor); mArcPaint.setAntiAlias(true); mArcPaint.setStyle(Paint.Style.STROKE); mArcPaint.setStrokeWidth(mArcWidth); mProgressPaint = new Paint(); mProgressPaint.setColor(progressColor); mProgressPaint.setAntiAlias(true); mProgressPaint.setStyle(Paint.Style.STROKE); mProgressPaint.setStrokeWidth(mProgressWidth); mNeedleScalePaint = new Paint(); mNeedleScalePaint.setColor(needleColor); mNeedleScalePaint.setAntiAlias(true); mNeedleScalePaint.setStrokeWidth(mNeedleThickness); mNeedleDistance = 30; mNeedleDP = 10; mMinimumNeedleScale = 0; isIncreaseCenter = false; mIncreaseCenterNeedle = 0; hasDotMarkers = false; mDotSize = 2; mHeightForPopup = 0; mDrawNeedleScaleUp = false; mProgressIncrement = 1; hasGradientColor = true; mMin = 0; mFraction = 1; drawMarkings = false; hasPopup = false; hasPopupIn = false; mPopup = new PopupBox(context); if (mRoundedEdges) { mArcPaint.setStrokeCap(Paint.Cap.ROUND); mProgressPaint.setStrokeCap(Paint.Cap.ROUND); } }
From source file:com.audiokernel.euphonyrmt.fragments.NowPlayingFragment.java
/** * Sets a buttons attributes.// ww w .jav a2 s . com * * @param attribute The attribute resource to set the button to. * @param button The button with which to set the attribute resource. */ private void setButtonAttribute(@AttrRes final int attribute, final ImageButton button) { final int[] attrs = { attribute }; final TypedArray ta = mActivity.obtainStyledAttributes(attrs); final Drawable drawableFromTheme = ta.getDrawable(0); button.setImageDrawable(drawableFromTheme); button.invalidate(); ta.recycle(); }
From source file:com.roselism.bottomsheet.BottomSheet.java
@SuppressWarnings("WeakerAccess") BottomSheet(Context context, int theme) { super(context, theme); TypedArray a = getContext().obtainStyledAttributes(null, R.styleable.BottomSheet, R.attr.bottomSheetStyle, 0);/*from w w w . j a v a 2 s .co m*/ mHasContent = builder.hasContent; try { more = a.getDrawable(R.styleable.BottomSheet_bs_moreDrawable); close = a.getDrawable(R.styleable.BottomSheet_bs_closeDrawable); moreText = a.getString(R.styleable.BottomSheet_bs_moreText); collapseListIcons = a.getBoolean(R.styleable.BottomSheet_bs_collapseListIcons, true); mHeaderLayoutId = a.getResourceId(R.styleable.BottomSheet_bs_headerLayout, mHasContent ? R.layout.bs_header_center : R.layout.bs_header); if (theme == R.style.BottomSheet_DialogHorizontalContent) { mListItemLayoutId = a.getResourceId(R.styleable.BottomSheet_bs_listItemLayout, mHasContent ? R.layout.bs_list_entry_hor_two : R.layout.bs_list_entry_hor_one); } else if (theme == R.style.BottomSheet_Dialog) { mListItemLayoutId = a.getResourceId(R.styleable.BottomSheet_bs_listItemLayout, R.layout.bs_list_entry_normal); } else { mListItemLayoutId = a.getResourceId(R.styleable.BottomSheet_bs_listItemLayout, R.layout.bs_list_entry_normal); } mGridItemLayoutId = a.getResourceId(R.styleable.BottomSheet_bs_gridItemLayout, R.layout.bs_grid_entry); } finally { a.recycle(); } // https://github.com/jgilfelt/SystemBarTint/blob/master/library/src/com/readystatesoftware/systembartint/SystemBarTintManager.java if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { helper = new TranslucentHelper(this, context); } }
From source file:com.roselism.bottomsheet.BottomSheet.java
@SuppressWarnings("WeakerAccess") BottomSheet(Context context, int theme, Builder builder) { super(context, theme); TypedArray a = getContext().obtainStyledAttributes(null, R.styleable.BottomSheet, R.attr.bottomSheetStyle, 0);// w ww.j av a 2 s. com mHasContent = builder.hasContent; try { more = a.getDrawable(R.styleable.BottomSheet_bs_moreDrawable); close = a.getDrawable(R.styleable.BottomSheet_bs_closeDrawable); moreText = a.getString(R.styleable.BottomSheet_bs_moreText); collapseListIcons = a.getBoolean(R.styleable.BottomSheet_bs_collapseListIcons, true); mHeaderLayoutId = a.getResourceId(R.styleable.BottomSheet_bs_headerLayout, mHasContent ? R.layout.bs_header_center : R.layout.bs_header); if (theme == R.style.BottomSheet_DialogHorizontalContent) { mListItemLayoutId = a.getResourceId(R.styleable.BottomSheet_bs_listItemLayout, mHasContent ? R.layout.bs_list_entry_hor_two : R.layout.bs_list_entry_hor_one); } else if (theme == R.style.BottomSheet_Dialog) { mListItemLayoutId = a.getResourceId(R.styleable.BottomSheet_bs_listItemLayout, R.layout.bs_list_entry_normal); } else { mListItemLayoutId = a.getResourceId(R.styleable.BottomSheet_bs_listItemLayout, R.layout.bs_list_entry_normal); } mGridItemLayoutId = a.getResourceId(R.styleable.BottomSheet_bs_gridItemLayout, R.layout.bs_grid_entry); } finally { a.recycle(); } // https://github.com/jgilfelt/SystemBarTint/blob/master/library/src/com/readystatesoftware/systembartint/SystemBarTintManager.java if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { helper = new TranslucentHelper(this, context); } }
From source file:com.jungkai.slidingtabs.SlidingTabLayout.java
private void applyStyle(Context context, int styleResId) { TypedArray a = context.obtainStyledAttributes(styleResId, R.styleable.SlidingTabLayout); final float density = getResources().getDisplayMetrics().density; if (a != null) { int n = a.getIndexCount(); for (int i = 0; i < n; i++) { int attr = a.getIndex(i); switch (attr) { case R.styleable.SlidingTabLayout_tabBottomBorderHeight: setBottomBorderThickness(a.getDimensionPixelSize(attr, (int) (SlidingTabStrip.DEFAULT_BOTTOM_BORDER_THICKNESS_DIPS * density))); break; case R.styleable.SlidingTabLayout_tabIndicatorThickness: setIndicatorThickness(a.getDimensionPixelSize(attr, (int) (SlidingTabStrip.DEFAULT_INDICATOR_THICKNESS_DIPS * density))); break; case R.styleable.SlidingTabLayout_tabIndicatorDrawable: setIndicatorDrawable(a.getDrawable(attr)); break; case R.styleable.SlidingTabLayout_tabDividerThickness: setDividerThickness(a.getDimensionPixelSize(attr, (int) (SlidingTabStrip.DEFAULT_DIVIDER_THICKNESS_DIPS * density))); break; default: break; }//from w ww. j a va2s. c o m } } }
From source file:com.aksalj.viewpagerslideshow.LinePageIndicator.java
public LinePageIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (isInEditMode()) return;// w w w. jav a2s. com final Resources res = getResources(); //Load defaults from resources final int defaultLineStyle = res.getInteger(R.integer.default_line_style); final int defaultSelectedColor = res.getColor(R.color.default_line_indicator_selected_color); final int defaultUnselectedColor = res.getColor(R.color.default_line_indicator_unselected_color); final float defaultLineWidth = res.getDimension(R.dimen.default_line_indicator_line_width); final float defaultGapWidth = res.getDimension(R.dimen.default_line_indicator_gap_width); final float defaultStrokeWidth = res.getDimension(R.dimen.default_line_indicator_stroke_width); final boolean defaultCentered = res.getBoolean(R.bool.default_line_indicator_centered); //Retrieve styles attributes TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LinePageIndicator, defStyle, 0); mBoxStyle = a.getInt(R.styleable.LinePageIndicator_lineStyle, defaultLineStyle) == 1; mCentered = a.getBoolean(R.styleable.LinePageIndicator_centered, mBoxStyle ? false : defaultCentered); mLineWidth = a.getDimension(R.styleable.LinePageIndicator_lineWidth, defaultLineWidth); mGapWidth = a.getDimension(R.styleable.LinePageIndicator_gapWidth, mBoxStyle ? 0.0f : defaultGapWidth); setStrokeWidth(a.getDimension(R.styleable.LinePageIndicator_strokeWidth, defaultStrokeWidth)); mPaintUnselected .setColor(a.getColor(R.styleable.LinePageIndicator_unselectedColor, defaultUnselectedColor)); mPaintSelected.setColor(a.getColor(R.styleable.LinePageIndicator_selectedColor, defaultSelectedColor)); Drawable background = a.getDrawable(R.styleable.LinePageIndicator_android_background); if (background != null) { setBackgroundDrawable(background); } a.recycle(); final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); }
From source file:com.mozhuowen.widget.autoscrollviewpager.indicator.LinePageIndicator.java
public LinePageIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (isInEditMode()) return;// ww w. j a va 2s . c o m final Resources res = getResources(); //Load defaults from resources final int defaultSelectedColor = res.getColor(R.color.default_line_indicator_selected_color); final int defaultUnselectedColor = res.getColor(R.color.default_line_indicator_unselected_color); final float defaultLineWidth = res.getDimension(R.dimen.default_line_indicator_line_width); final float defaultGapWidth = res.getDimension(R.dimen.default_line_indicator_gap_width); final float defaultStrokeWidth = res.getDimension(R.dimen.default_line_indicator_stroke_width); final boolean defaultCentered = res.getBoolean(R.bool.default_line_indicator_centered); //Retrieve styles attributes TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LinePageIndicator, defStyle, 0); // mCentered = a.getBoolean(R.styleable.LinePageIndicator_centered, defaultCentered); // mLineWidth = a.getDimension(R.styleable.LinePageIndicator_lineWidth, defaultLineWidth); // mGapWidth = a.getDimension(R.styleable.LinePageIndicator_gapWidth, defaultGapWidth); mCentered = defaultCentered; mLineWidth = defaultLineWidth; mGapWidth = defaultGapWidth; setStrokeWidth(a.getDimension(R.styleable.LinePageIndicator_strokeWidth, defaultStrokeWidth)); mPaintUnselected .setColor(a.getColor(R.styleable.LinePageIndicator_unselectedColor, defaultUnselectedColor)); mPaintSelected.setColor(a.getColor(R.styleable.LinePageIndicator_selectedColor, defaultSelectedColor)); Drawable background = a.getDrawable(R.styleable.LinePageIndicator_android_background); if (background != null) { setBackgroundDrawable(background); } a.recycle(); final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); }
From source file:com.actionbarsherlock.internal.widget.IcsProgressBar.java
/** * @hide// w w w . j a v a 2 s . c om */ public IcsProgressBar(Context context, AttributeSet attrs, int defStyle, int styleRes) { super(context, attrs, defStyle); mUiThreadId = Thread.currentThread().getId(); initProgressBar(); TypedArray a = context.obtainStyledAttributes(attrs, /*R.styleable.*/ProgressBar, defStyle, styleRes); mNoInvalidate = true; Drawable drawable = a.getDrawable(/*R.styleable.*/ProgressBar_progressDrawable); if (drawable != null) { drawable = tileify(drawable, false); // Calling this method can set mMaxHeight, make sure the corresponding // XML attribute for mMaxHeight is read after calling this method setProgressDrawable(drawable); } mDuration = a.getInt(/*R.styleable.*/ProgressBar_indeterminateDuration, mDuration); mMinWidth = a.getDimensionPixelSize(/*R.styleable.*/ProgressBar_minWidth, mMinWidth); mMaxWidth = a.getDimensionPixelSize(/*R.styleable.*/ProgressBar_maxWidth, mMaxWidth); mMinHeight = a.getDimensionPixelSize(/*R.styleable.*/ProgressBar_minHeight, mMinHeight); mMaxHeight = a.getDimensionPixelSize(/*R.styleable.*/ProgressBar_maxHeight, mMaxHeight); mBehavior = a.getInt(/*R.styleable.*/ProgressBar_indeterminateBehavior, mBehavior); final int resID = a.getResourceId(/*com.android.internal.R.styleable.*/ProgressBar_interpolator, android.R.anim.linear_interpolator); // default to linear interpolator if (resID > 0) { setInterpolator(context, resID); } setMax(a.getInt(/*R.styleable.*/ProgressBar_max, mMax)); setProgress(a.getInt(/*R.styleable.*/ProgressBar_progress, mProgress)); setSecondaryProgress(a.getInt(/*R.styleable.*/ProgressBar_secondaryProgress, mSecondaryProgress)); drawable = a.getDrawable(/*R.styleable.*/ProgressBar_indeterminateDrawable); if (drawable != null) { drawable = tileifyIndeterminate(drawable); setIndeterminateDrawable(drawable); } mOnlyIndeterminate = a.getBoolean(/*R.styleable.*/ProgressBar_indeterminateOnly, mOnlyIndeterminate); mNoInvalidate = false; setIndeterminate( mOnlyIndeterminate || a.getBoolean(/*R.styleable.*/ProgressBar_indeterminate, mIndeterminate)); mAnimationResolution = a.getInteger(/*R.styleable.*/ProgressBar_animationResolution, ANIMATION_RESOLUTION); a.recycle(); mAccessibilityManager = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE); }
From source file:com.justplay1.shoppist.features.search.widget.FloatingSearchView.java
private void applyXmlAttributes(AttributeSet attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) { final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.FloatingSearchView, defStyleAttr, defStyleRes);/* ww w . j a va 2 s. c o m*/ // Search bar width View suggestionsContainer = findViewById(R.id.fsv_suggestions_container); int searchBarWidth = a.getDimensionPixelSize(R.styleable.FloatingSearchView_fsv_searchBarWidth, searchContainer.getLayoutParams().width); searchContainer.getLayoutParams().width = searchBarWidth; suggestionsContainer.getLayoutParams().width = searchBarWidth; // Divider ViewUtils.setBackground(divider, a.getDrawable(R.styleable.FloatingSearchView_android_divider)); int dividerHeight = a.getDimensionPixelSize(R.styleable.FloatingSearchView_android_dividerHeight, -1); MarginLayoutParams dividerLP = (MarginLayoutParams) divider.getLayoutParams(); if (divider.getBackground() != null && dividerHeight != -1) dividerLP.height = dividerHeight; float maxShadowSize = searchBackground.getMaxShadowSize(); float cornerRadius = searchBackground.getCornerRadius(); int horizontalPadding = (int) (RoundRectDrawableWithShadow.calculateHorizontalPadding(maxShadowSize, cornerRadius, false) + .5f); dividerLP.setMargins(horizontalPadding, dividerLP.topMargin, horizontalPadding, dividerLP.bottomMargin); divider.setLayoutParams(dividerLP); // Content inset MarginLayoutParams searchParams = (MarginLayoutParams) searchInput.getLayoutParams(); int contentInsetStart = a.getDimensionPixelSize(R.styleable.FloatingSearchView_contentInsetStart, MarginLayoutParamsCompat.getMarginStart(searchParams)); int contentInsetEnd = a.getDimensionPixelSize(R.styleable.FloatingSearchView_contentInsetEnd, MarginLayoutParamsCompat.getMarginEnd(searchParams)); MarginLayoutParamsCompat.setMarginStart(searchParams, contentInsetStart); MarginLayoutParamsCompat.setMarginEnd(searchParams, contentInsetEnd); // anything else setLogo(a.getDrawable(R.styleable.FloatingSearchView_logo)); setContentBackgroundColor( a.getColor(R.styleable.FloatingSearchView_fsv_contentBackgroundColor, DEFAULT_CONTENT_COLOR)); setRadius(a.getDimensionPixelSize(R.styleable.FloatingSearchView_fsv_cornerRadius, ViewUtils.dpToPx(DEFAULT_RADIUS))); inflateMenu(a.getResourceId(R.styleable.FloatingSearchView_fsv_menu, 0)); setPopupTheme(a.getResourceId(R.styleable.FloatingSearchView_popupTheme, 0)); setHint(a.getString(R.styleable.FloatingSearchView_android_hint)); setIcon(a.getDrawable(R.styleable.FloatingSearchView_fsv_icon)); a.recycle(); }
From source file:com.easemob.easeui.widget.viewpagerindicator.CirclePageIndicator.java
public CirclePageIndicator(Context context, AttributeSet attrs) { super(context, attrs); if (isInEditMode()) return;// www.j ava 2 s .c o m TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircleIndicator); mCentered = a.getBoolean(R.styleable.CircleIndicator_mCentered, true); mOrientation = a.getInt(R.styleable.CircleIndicator_android_orientation, 0); mPaintPageFill.setStyle(Style.FILL); mPaintPageFill.setColor(a.getColor(R.styleable.CircleIndicator_mPageColor, 0xa0000000)); mPaintStroke.setStyle(Style.STROKE); mPaintStroke.setColor(a.getColor(R.styleable.CircleIndicator_mStrokeColor, 0xFFDDDDDD)); mPaintStroke.setStrokeWidth(0); // 1dip mPaintFill.setStyle(Style.FILL); mPaintFill.setColor(a.getColor(R.styleable.CircleIndicator_mFillColor, 0xFFff5f19)); // 0xFFFFFFFF mRadius = a.getDimension(R.styleable.CircleIndicator_mRadius, 20); //3dip mSnap = a.getBoolean(R.styleable.CircleIndicator_mSnap, true); Drawable background = a.getDrawable(R.styleable.CircleIndicator_android_background); if (background != null) { setBackgroundDrawable(background); } a.recycle(); final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); }