List of usage examples for android.content.res TypedArray getDimension
public float getDimension(@StyleableRes int index, float defValue)
From source file:android.support.v17.leanback.app.BrowseFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TypedArray ta = getActivity().obtainStyledAttributes(R.styleable.LeanbackTheme); mContainerListMarginStart = (int) ta.getDimension(R.styleable.LeanbackTheme_browseRowsMarginStart, getActivity().getResources().getDimensionPixelSize(R.dimen.lb_browse_rows_margin_start)); mContainerListAlignTop = (int) ta.getDimension(R.styleable.LeanbackTheme_browseRowsMarginTop, getActivity().getResources().getDimensionPixelSize(R.dimen.lb_browse_rows_margin_top)); ta.recycle();/*from w w w . j a v a 2s . co m*/ readArguments(getArguments()); if (mCanShowHeaders) { if (mHeadersBackStackEnabled) { mWithHeadersBackStackName = LB_HEADERS_BACKSTACK + this; mBackStackChangedListener = new BackStackListener(); getFragmentManager().addOnBackStackChangedListener(mBackStackChangedListener); mBackStackChangedListener.load(savedInstanceState); } else { if (savedInstanceState != null) { mShowingHeaders = savedInstanceState.getBoolean(HEADER_SHOW); } } } mScaleFactor = getResources().getFraction(R.fraction.lb_browse_rows_scale, 1, 1); }
From source file:cy.studiodemo.view.Marker.java
public Marker(Context context, AttributeSet attrs, int defStyleAttr, String maxValue, int thumbSize, int separation) { super(context, attrs, defStyleAttr); //as we're reading the parent DiscreteSeekBar attributes, it may wrongly set this view's visibility. setVisibility(View.VISIBLE);/* ww w . j a v a2s. c o m*/ DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DiscreteSeekBar, R.attr.discreteSeekBarStyle, R.style.Widget_DiscreteSeekBar); int padding = (int) (PADDING_DP * displayMetrics.density) * 2; int textAppearanceId = a.getResourceId(R.styleable.DiscreteSeekBar_dsb_indicatorTextAppearance, R.style.Widget_DiscreteIndicatorTextAppearance); mNumber = new TextView(context); //Add some padding to this textView so the bubble has some space to breath mNumber.setPadding(padding, 0, padding, 0); mNumber.setTextAppearance(context, textAppearanceId); mNumber.setGravity(Gravity.CENTER); mNumber.setText(maxValue); mNumber.setMaxLines(1); mNumber.setTextColor(context.getResources().getColor(R.color.white)); mNumber.setSingleLine(true); SeekBarCompat.setTextDirection(mNumber, TEXT_DIRECTION_LOCALE); mNumber.setVisibility(View.INVISIBLE); //add some padding for the elevation shadow not to be clipped //I'm sure there are better ways of doing this... setPadding(padding, padding, padding, padding); resetSizes(maxValue); mSeparation = separation; ColorStateList color = a.getColorStateList(R.styleable.DiscreteSeekBar_dsb_indicatorColor); mMarkerDrawable = new MarkerDrawable(color, thumbSize); mMarkerDrawable.setCallback(this); mMarkerDrawable.setMarkerListener(this); mMarkerDrawable.setExternalOffset(padding); //Elevation for anroid 5+ float elevation = a.getDimension(R.styleable.DiscreteSeekBar_dsb_indicatorElevation, ELEVATION_DP * displayMetrics.density); ViewCompat.setElevation(this, elevation); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { SeekBarCompat.setOutlineProvider(this, mMarkerDrawable); } a.recycle(); }
From source file:com.github.omadahealth.slidepager.lib.views.SlideChartView.java
private void loadStyledAttributes(TypedArray attributes) { mAttributes = attributes;//from w w w. java 2 s . c o m if (mAttributes != null) { mOutlineSize = mAttributes.getDimension( R.styleable.SlidePager_slide_progress_not_completed_outline_size, getResources().getDimension(R.dimen.circular_bar_default_outline_width)); mHasToReanimate = mAttributes.getBoolean(R.styleable.SlidePager_slide_pager_reanimate_slide_view, true); mTopTextColor = attributes.getColor(R.styleable.SlidePager_slide_progress_chart_bar_top_text_color, getResources().getColor(R.color.default_progress_chart_bar_top_text)); mSpecialBottomTextColor = attributes.getColor( R.styleable.SlidePager_slide_progress_chart_bar_bottom_special_text_color, getResources().getColor(R.color.default_progress_chart_bar_special_bottom_text)); mBottomTextColor = attributes.getColor( R.styleable.SlidePager_slide_progress_chart_bar_bottom_text_color, getResources().getColor(R.color.default_progress_chart_bar_bottom_text)); mChartBarColor = attributes.getColor(R.styleable.SlidePager_slide_progress_chart_color, getResources().getColor(R.color.default_progress_chart_bar_color)); mChartBarSize = attributes.getDimension(R.styleable.SlidePager_slide_progress_chart_bar_size, getResources().getDimension(R.dimen.default_progress_chart_bar_size)); mShakeIfNotSelectable = attributes.getBoolean(R.styleable.SlidePager_slide_shake_if_not_selectable, true); } }
From source file:com.example.anumbrella.viewpager.CirclePagerIndicator.java
public CirclePagerIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); ///*from ww w . j a va 2 s .co m*/ if (isInEditMode()) { return; } //?? 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); //xml TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.CirclePagerIndicator, defStyle, 0); mCentered = array.getBoolean(R.styleable.CirclePagerIndicator_centered, defaultCentered); mOrientation = array.getInteger(R.styleable.CirclePagerIndicator_android_orientation, defaultOrientation); // mPaintPageFill.setStyle(Paint.Style.FILL); // mPaintPageFill.setColor(array.getColor(R.styleable.CirclePagerIndicator_pageColor, defaultPageColor)); // mPaintFill.setStyle(Paint.Style.FILL); // mPaintFill.setColor(array.getColor(R.styleable.CirclePagerIndicator_fillColor, defaultFillColor)); // mPaintStroke.setColor(array.getColor(R.styleable.CirclePagerIndicator_strokeColor, defaultStrokeColor)); //(??) mPaintStroke.setStyle(Paint.Style.STROKE); // mPaintStroke.setStrokeWidth( array.getDimension(R.styleable.CirclePagerIndicator_strokeWidth, defaultStrokeWidth)); //??? mRadius = array.getDimension(R.styleable.CirclePagerIndicator_radius, defaultRadius); //? mSnap = array.getBoolean(R.styleable.CirclePagerIndicator_snap, defaultSnap); Drawable background = array.getDrawable(R.styleable.CirclePagerIndicator_android_background); if (background != null) { setBackgroundDrawable(background); } array.recycle(); final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); }
From source file:bk.vinhdo.taxiads.utils.view.SlidingLayer.java
/** * Constructor for the sliding layer.<br> * By default this panel will/*from w w w. j a v a2s. c o m*/ * <ol> * <li>{@link #setStickTo(int)} with param {@link #STICK_TO_AUTO}</li> * <li>Use no shadow drawable. (i.e. with width of 0)</li> * <li>Close when the panel is tapped</li> * <li>Open when the offset is tapped, but will have an offset of 0</li> * </ol> * * @param context * a reference to an existing context * @param attrs * attribute set constructed from attributes set in android .xml * file * @param defStyle * style res id */ public SlidingLayer(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // Style final TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlidingLayer); // Set the side of the screen setStickTo(ta.getInt(R.styleable.SlidingLayer_stickTo, STICK_TO_AUTO)); // Sets the shadow drawable int shadowRes = ta.getResourceId(R.styleable.SlidingLayer_shadowDrawableSliding, -1); if (shadowRes != -1) { setShadowDrawable(shadowRes); } // Sets the shadow width setShadowWidth((int) ta.getDimension(R.styleable.SlidingLayer_shadowWidthSliding, 0)); // Sets the ability to close the layer by tapping in any empty space closeOnTapEnabled = ta.getBoolean(R.styleable.SlidingLayer_closeOnTapEnabled, true); // Sets the ability to open the layout by tapping on any of the exposed // closed layer openOnTapEnabled = ta.getBoolean(R.styleable.SlidingLayer_openOnTapEnabled, true); // How much of the view sticks out when closed setOffsetWidth(ta.getDimensionPixelOffset(R.styleable.SlidingLayer_offsetWidth, 0)); ta.recycle(); init(); }
From source file:de.vanita5.twittnuker.view.ShapedImageView.java
public ShapedImageView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ShapedImageView, defStyle, 0); mMatrix = new Matrix(); mSource = new RectF(); mDestination = new RectF(); mTempDestination = new RectF(); mBitmapPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mBitmapPaint.setFilterBitmap(true);//from ww w. j a v a 2s . c om mBitmapPaint.setDither(true); mSolidColorPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mBorderPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mBorderPaint.setStyle(Paint.Style.STROKE); mBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG); if (a.hasValue(R.styleable.ShapedImageView_sivBorder)) { setBorderEnabled(a.getBoolean(R.styleable.ShapedImageView_sivBorder, false)); } else if (a.hasValue(R.styleable.ShapedImageView_sivBorderColor) || a.hasValue(R.styleable.ShapedImageView_sivBorderWidth)) { setBorderEnabled(true); } setBorderColor(a.getColor(R.styleable.ShapedImageView_sivBorderColor, Color.TRANSPARENT)); setBorderWidth(a.getDimensionPixelSize(R.styleable.ShapedImageView_sivBorderWidth, 0)); @ShapeStyle final int shapeStyle = a.getInt(R.styleable.ShapedImageView_sivShape, SHAPE_RECTANGLE); setStyle(shapeStyle); setCornerRadius(a.getDimension(R.styleable.ShapedImageView_sivCornerRadius, 0)); setCornerRadiusRatio(a.getFraction(R.styleable.ShapedImageView_sivCornerRadiusRatio, 1, 1, -1)); if (USE_OUTLINE) { if (a.hasValue(R.styleable.ShapedImageView_sivElevation)) { ViewCompat.setElevation(this, a.getDimensionPixelSize(R.styleable.ShapedImageView_sivElevation, 0)); } } else { mShadowRadius = a.getDimensionPixelSize(R.styleable.ShapedImageView_sivElevation, 0); } setBackgroundColor(a.getColor(R.styleable.ShapedImageView_sivBackgroundColor, 0)); a.recycle(); if (USE_OUTLINE) { initOutlineProvider(); } }
From source file:com.acious.android.paginationseekbar.internal.Marker.java
public Marker(Context context, AttributeSet attrs, int defStyleAttr, String maxValue) { super(context, attrs, defStyleAttr); DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PaginationSeekBar, R.attr.paginationSeekBarStyle, R.style.DefaultSeekBar); int padding = (int) (PADDING_DP * displayMetrics.density) * 2; int textAppearanceId = a.getResourceId(R.styleable.PaginationSeekBar_psb_indicatorTextAppearance, R.style.DefaultIndicatorTextAppearance); mNumber = new TextView(context); //Add some padding to this textView so the bubble has some space to breath mNumber.setPadding(padding, 0, padding, 0); mNumber.setTextAppearance(context, textAppearanceId); mNumber.setGravity(Gravity.CENTER);//from w w w. java2 s.c om mNumber.setText(maxValue); mNumber.setMaxLines(1); mNumber.setSingleLine(true); SeekBarCompat.setTextDirection(mNumber, TEXT_DIRECTION_LOCALE); mNumber.setVisibility(View.INVISIBLE); //add some padding for the elevation shadow not to be clipped //I'm sure there are better ways of doing this... setPadding(padding, padding, padding, padding); resetSizes(maxValue); mSeparation = (int) (SEPARATION_DP * displayMetrics.density); int thumbSize = (int) (ThumbDrawable.DEFAULT_SIZE_DP * displayMetrics.density); ColorStateList color = a.getColorStateList(R.styleable.PaginationSeekBar_psb_indicatorColor); mMarkerDrawable = new MarkerDrawable(color, thumbSize); mMarkerDrawable.setCallback(this); mMarkerDrawable.setMarkerListener(this); mMarkerDrawable.setExternalOffset(padding); //Elevation for anroid 5+ float elevation = a.getDimension(R.styleable.PaginationSeekBar_psb_indicatorElevation, ELEVATION_DP * displayMetrics.density); ViewCompat.setElevation(this, elevation); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { SeekBarCompat.setOutlineProvider(this, mMarkerDrawable); } a.recycle(); }
From source file:ru.phplego.core.etc.viewpagerindicator.CirclePageIndicator.java
public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); //Load defaults from resources final Resources res = getResources(); final int defaultPageColor = res.getColor(Res.getId(Application.getContext().getPackageName(), "color", "default_circle_indicator_page_color")); final int defaultFillColor = res.getColor(Res.getId(Application.getContext().getPackageName(), "color", "default_circle_indicator_fill_color")); final int defaultOrientation = res.getInteger(Res.getId(Application.getContext().getPackageName(), "integer", "default_circle_indicator_orientation")); final int defaultStrokeColor = res.getColor(Res.getId(Application.getContext().getPackageName(), "color", "default_circle_indicator_stroke_color")); final float defaultStrokeWidth = res.getDimension(Res.getId(Application.getContext().getPackageName(), "dimen", "default_circle_indicator_stroke_width")); final float defaultRadius = res.getDimension( Res.getId(Application.getContext().getPackageName(), "dimen", "default_circle_indicator_radius")); final boolean defaultCentered = res.getBoolean( Res.getId(Application.getContext().getPackageName(), "bool", "default_circle_indicator_centered")); final boolean defaultSnap = res.getBoolean( Res.getId(Application.getContext().getPackageName(), "bool", "default_circle_indicator_snap")); //Retrieve styles attributes TypedArray a = context.obtainStyledAttributes(attrs, Res.getIds(Application.getContext().getPackageName(), "styleable", "CirclePageIndicator"), defStyle, Res.getId(Application.getContext().getPackageName(), "style", "Widget_CirclePageIndicator")); mCentered = a.getBoolean(//from w w w . j av a 2 s . co m Res.getId(Application.getContext().getPackageName(), "styleable", "CirclePageIndicator_centered"), defaultCentered); mOrientation = a.getInt(Res.getId(Application.getContext().getPackageName(), "styleable", "CirclePageIndicator_orientation"), defaultOrientation); mPaintPageFill = new Paint(Paint.ANTI_ALIAS_FLAG); mPaintPageFill.setStyle(Style.FILL); mPaintPageFill.setColor(a.getColor( Res.getId(Application.getContext().getPackageName(), "styleable", "CirclePageIndicator_pageColor"), defaultPageColor)); mPaintStroke = new Paint(Paint.ANTI_ALIAS_FLAG); mPaintStroke.setStyle(Style.STROKE); mPaintStroke.setColor(a.getColor(Res.getId(Application.getContext().getPackageName(), "styleable", "CirclePageIndicator_strokeColor"), defaultStrokeColor)); mPaintStroke.setStrokeWidth(a.getDimension(Res.getId(Application.getContext().getPackageName(), "styleable", "CirclePageIndicator_strokeWidth"), defaultStrokeWidth)); mPaintFill = new Paint(Paint.ANTI_ALIAS_FLAG); mPaintFill.setStyle(Style.FILL); mPaintFill.setColor(a.getColor( Res.getId(Application.getContext().getPackageName(), "styleable", "CirclePageIndicator_fillColor"), defaultFillColor)); mRadius = a.getDimension( Res.getId(Application.getContext().getPackageName(), "styleable", "CirclePageIndicator_radius"), defaultRadius); mSnap = a.getBoolean( Res.getId(Application.getContext().getPackageName(), "styleable", "CirclePageIndicator_snap"), defaultSnap); a.recycle(); final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); }
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;// w w w . j a v a 2s. 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:org.mariotaku.twidere.view.ShapedImageView.java
public ShapedImageView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ShapedImageView, defStyle, 0); mMatrix = new Matrix(); mSource = new RectF(); mDestination = new RectF(); mTempDestination = new RectF(); mBitmapPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mBitmapPaint.setFilterBitmap(true);/*from www .ja va 2 s . com*/ mBitmapPaint.setDither(true); mSolidColorPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mBorderPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mBorderPaint.setStyle(Paint.Style.STROKE); mBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG); if (a.hasValue(R.styleable.ShapedImageView_sivBorder)) { setBorderEnabled(a.getBoolean(R.styleable.ShapedImageView_sivBorder, false)); } else if (a.hasValue(R.styleable.ShapedImageView_sivBorderColor) || a.hasValue(R.styleable.ShapedImageView_sivBorderWidth)) { setBorderEnabled(true); } setBorderColor(a.getColor(R.styleable.ShapedImageView_sivBorderColor, Color.TRANSPARENT)); setBorderWidth(a.getDimensionPixelSize(R.styleable.ShapedImageView_sivBorderWidth, 0)); @ShapeStyle final int shapeStyle = a.getInt(R.styleable.ShapedImageView_sivShape, SHAPE_RECTANGLE); setStyle(shapeStyle); setCornerRadius(a.getDimension(R.styleable.ShapedImageView_sivCornerRadius, 0)); setCornerRadiusRatio(a.getFraction(R.styleable.ShapedImageView_sivCornerRadiusRatio, 1, 1, -1)); if (useOutline()) { if (a.hasValue(R.styleable.ShapedImageView_sivElevation)) { ViewCompat.setElevation(this, a.getDimensionPixelSize(R.styleable.ShapedImageView_sivElevation, 0)); } } else { mShadowRadius = a.getDimensionPixelSize(R.styleable.ShapedImageView_sivElevation, 0); } setBackgroundColor(a.getColor(R.styleable.ShapedImageView_sivBackgroundColor, 0)); a.recycle(); initOutlineProvider(); }