List of usage examples for android.content.res TypedArray getDimension
public float getDimension(@StyleableRes int index, float defValue)
From source file:com.owen.view.views.PieChart.java
/** * Class constructor taking a context and an attribute set. This constructor * is used by the layout engine to construct a {@link com.owen.view.views.PieChart} from a set of * XML attributes.// www .j a va2 s . com * * @param context * @param attrs An attribute set which can contain attributes from * {@link PieChart} as well as attributes inherited * from {@link android.view.View}. */ public PieChart(Context context, AttributeSet attrs) { super(context, attrs); // attrs contains the raw values for the XML attributes // that were specified in the layout, which don't include // attributes set by styles or themes, and which may have // unresolved references. Call obtainStyledAttributes() // to get the final values for each attribute. // // This call uses R.styleable.PieChart, which is an array of // the custom attributes that were declared in attrs.xml. TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.PieChart, 0, 0); try { // Retrieve the values from the TypedArray and store into // fields of this class. // // The R.styleable.PieChart_* constants represent the index for // each custom attribute in the R.styleable.PieChart array. mShowText = a.getBoolean(R.styleable.PieChart_pie_showText, false); mTextY = a.getDimension(R.styleable.PieChart_pie_labelY, 0.0f); mTextWidth = a.getDimension(R.styleable.PieChart_pie_labelWidth, 0.0f); mTextHeight = a.getDimension(R.styleable.PieChart_pie_labelHeight, 0.0f); mTextPos = a.getInteger(R.styleable.PieChart_pie_labelPosition, 0); mTextColor = a.getColor(R.styleable.PieChart_pie_labelColor, 0xff000000); mHighlightStrength = a.getFloat(R.styleable.PieChart_pie_highlightStrength, 1.0f); mPieRotation = a.getInt(R.styleable.PieChart_pie_pieRotation, 0); mPointerRadius = a.getDimension(R.styleable.PieChart_pie_pointerRadius, 2.0f); mAutoCenterInSlice = a.getBoolean(R.styleable.PieChart_pie_autoCenterPointerInSlice, false); } finally { // release the TypedArray so that it can be reused. a.recycle(); } init(); }
From source file:bhav.swipeaction.SwipeAction.java
private void initStyle(Context context, AttributeSet attrs) { final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SwipeAction); if (a != null) { if (a.hasValue(R.styleable.SwipeAction_src)) { icon = a.getDrawable(R.styleable.SwipeAction_src); } else {/*from w w w. j av a 2s . c o m*/ //default back to available icon icon = getResources().getDrawable(android.R.drawable.ic_delete); } iconPaddingBottom = Math .round(a.getDimension(R.styleable.SwipeAction_iconPaddingBottom, DEF_PADDING_BOTTOM)); iconPaddingTop = Math.round(a.getDimension(R.styleable.SwipeAction_iconPaddingTop, DEF_PADDING_TOP)); iconPaddingLeft = Math .round(a.getDimension(R.styleable.SwipeAction_iconPaddingLeft, DEF_PADDING_START)); iconPaddingRight = Math .round(a.getDimension(R.styleable.SwipeAction_iconPaddingRight, DEF_PADDING_END)); a.recycle(); } }
From source file:io.github.tonyshkurenko.slidinguppanelsetup.behaviors.BottomSheetBehaviorGoogleMapsLike.java
/** * Default constructor for inflating BottomSheetBehaviors from layout. * * @param context The {@link Context}.// w w w .j a v a2 s . c om * @param attrs The {@link AttributeSet}. */ public BottomSheetBehaviorGoogleMapsLike(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, android.support.design.R.styleable.BottomSheetBehavior_Layout); setPeekHeight(a.getDimensionPixelSize( android.support.design.R.styleable.BottomSheetBehavior_Layout_behavior_peekHeight, 0)); setHideable(a.getBoolean(android.support.design.R.styleable.BottomSheetBehavior_Layout_behavior_hideable, false)); a.recycle(); /** * Getting the anchorPoint... */ mAnchorPoint = DEFAULT_ANCHOR_POINT; a = context.obtainStyledAttributes(attrs, R.styleable.CustomBottomSheetBehavior); if (attrs != null) { mAnchorPoint = (int) a.getDimension(R.styleable.CustomBottomSheetBehavior_anchorPoint, 0); } a.recycle(); ViewConfiguration configuration = ViewConfiguration.get(context); mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); }
From source file:com.schemetryme.potrcko.BottomSheet.BottomSheetBehaviorGoogleMapsLike.java
/** * Default constructor for inflating BottomSheetBehaviors from layout. * * @param context The {@link Context}./*from w w w . j a va 2s . c om*/ * @param attrs The {@link AttributeSet}. */ public BottomSheetBehaviorGoogleMapsLike(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, android.support.design.R.styleable.BottomSheetBehavior_Layout); setPeekHeight(a.getDimensionPixelSize( android.support.design.R.styleable.BottomSheetBehavior_Layout_behavior_peekHeight, 0)); setHideable(a.getBoolean(android.support.design.R.styleable.BottomSheetBehavior_Layout_behavior_hideable, true)); a.recycle(); /** * Getting the anchorPoint... */ mAnchorPoint = DEFAULT_ANCHOR_POINT; a = context.obtainStyledAttributes(attrs, R.styleable.CustomBottomSheetBehavior); if (attrs != null) mAnchorPoint = (int) a.getDimension(R.styleable.CustomBottomSheetBehavior_anchorPoint, 0); a.recycle(); ViewConfiguration configuration = ViewConfiguration.get(context); mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); }
From source file:com.devexweb.googlemapsapi.lib.BottomSheetBehaviorGoogleMapsLike.java
/** * Default constructor for inflating BottomSheetBehaviors from layout. * * @param context The {@link Context}./*from w w w. j a v a 2 s. c om*/ * @param attrs The {@link AttributeSet}. */ public BottomSheetBehaviorGoogleMapsLike(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, android.support.design.R.styleable.BottomSheetBehavior_Layout); setPeekHeight(a.getDimensionPixelSize( android.support.design.R.styleable.BottomSheetBehavior_Layout_behavior_peekHeight, 0)); setHideable(a.getBoolean(android.support.design.R.styleable.BottomSheetBehavior_Layout_behavior_hideable, false)); a.recycle(); /** * Getting the anchorPoint... */ mAnchorPoint = DEFAULT_ANCHOR_POINT; a = context.obtainStyledAttributes(attrs, R.styleable.CustomBottomSheetBehavior); if (attrs != null) mAnchorPoint = (int) a.getDimension(R.styleable.CustomBottomSheetBehavior_anchorPoint, 0); a.recycle(); ViewConfiguration configuration = ViewConfiguration.get(context); mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); }
From source file:org.tud.mensaapp.ui.behavior.BottomSheetBehaviorGoogleMapsLike.java
/** * Default constructor for inflating BottomSheetBehaviors from layout. * * @param context The {@link Context}.//from ww w . j av a 2s. c o m * @param attrs The {@link AttributeSet}. */ public BottomSheetBehaviorGoogleMapsLike(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, android.support.design.R.styleable.BottomSheetBehavior_Layout); setPeekHeight(a.getDimensionPixelSize( android.support.design.R.styleable.BottomSheetBehavior_Layout_behavior_peekHeight, 0)); setHideable(a.getBoolean(android.support.design.R.styleable.BottomSheetBehavior_Layout_behavior_hideable, false)); a.recycle(); /** * Getting the anchorPoint... */ mAnchorPoint = DEFAULT_ANCHOR_POINT; a = context.obtainStyledAttributes(attrs, R.styleable.CustomBottomSheetBehavior); if (attrs != null) mAnchorPoint = (int) a.getDimension(R.styleable.CustomBottomSheetBehavior_anchorPoint, 0); a.recycle(); ViewConfiguration configuration = ViewConfiguration.get(context); mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); }
From source file:com.blue.sky.control.CirclePageIndicator.java
@SuppressWarnings("deprecation") public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (isInEditMode()) return;/*from w w w . ja va 2s. co m*/ // 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 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); final float defaultPadding = res.getDimension(R.dimen.default_circle_indicator_padding); defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width); // Retrieve styles attributes TypedArray a = context.obtainStyledAttributes(attrs, Styleable.CirclePageIndicator, defStyle, 0); indicateCircleType = a.getInt(Styleable.CirclePageIndicator_unIndicateCircleType, 0); mCentered = a.getBoolean(Styleable.CirclePageIndicator_centered, defaultCentered); mOrientation = a.getInt(Styleable.CirclePageIndicator_android_orientation, defaultOrientation); mPaintPageFill.setStyle(Style.FILL); mPaintPageFill.setColor(a.getColor(Styleable.CirclePageIndicator_pageColor, defaultPageColor)); if (indicateCircleType == 0) { mPaintStroke.setStyle(Style.STROKE); } else if (indicateCircleType == 1) { mPaintStroke.setStyle(Style.FILL); } mPaintStroke.setColor(a.getColor(Styleable.CirclePageIndicator_strokeColor, defaultStrokeColor)); mPaintStroke.setStrokeWidth(a.getDimension(Styleable.CirclePageIndicator_strokeWidth, defaultStrokeWidth)); mPaintFill.setStyle(Style.FILL); mPaintFill.setColor(a.getColor(Styleable.CirclePageIndicator_fillColor, defaultFillColor)); mRadius = a.getDimension(Styleable.CirclePageIndicator_radius, defaultRadius); padding = a.getDimension(Styleable.CirclePageIndicator_padding, defaultPadding); mSnap = a.getBoolean(Styleable.CirclePageIndicator_snap, defaultSnap); Drawable background = a.getDrawable(Styleable.CirclePageIndicator_android_background); if (background != null) { setBackgroundDrawable(background); } a.recycle(); final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); }
From source file:me.xiaopan.psts.PagerSlidingTabStrip.java
public PagerSlidingTabStrip(Context context, AttributeSet attrs) { super(context, attrs); setHorizontalScrollBarEnabled(false); //?????? removeAllViews();/*from w w w .j a v a 2 s . co m*/ if (attrs != null) { TypedArray attrsTypedArray = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip); if (attrsTypedArray != null) { allowWidthFull = attrsTypedArray.getBoolean(R.styleable.PagerSlidingTabStrip_allowWidthFull, false); slidingBlockDrawable = attrsTypedArray.getDrawable(R.styleable.PagerSlidingTabStrip_slidingBlock); disableViewPager = attrsTypedArray.getBoolean(R.styleable.PagerSlidingTabStrip_disableViewPager, false); disableTensileSlidingBlock = attrsTypedArray .getBoolean(R.styleable.PagerSlidingTabStrip_disableTensileSlidingBlock, false); bottomLineColor = attrsTypedArray.getColor(R.styleable.PagerSlidingTabStrip_bottomLineColor, -1); bottomLineHeight = (int) attrsTypedArray .getDimension(R.styleable.PagerSlidingTabStrip_bottomLineHeight, -1); attrsTypedArray.recycle(); } } tabViewDoubleClickGestureDetector = new DoubleClickGestureDetector(context); getViewTreeObserver().addOnGlobalLayoutListener(setSelectedTabListener); }
From source file:com.bvhloc.numpicker.widget.NumberPicker.java
public NumberPicker(Context context, AttributeSet attrs, int defStyle) { super(context, attrs); mStart = DEFAULT_START;// w ww . j av a 2s . com mEnd = DEFAULT_END; mCurrent = mStart; boolean vertical = true; int displayedValues = 0; if (attrs != null && !isInEditMode()) { // this crashes in edit mode (?!) TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.NumberPicker); mStart = a.getInt(R.styleable.NumberPicker_rangeStart, DEFAULT_START); mEnd = a.getInt(R.styleable.NumberPicker_rangeEnd, DEFAULT_END); mSpeed = a.getInt(R.styleable.NumberPicker_speed, (int) mSpeed); mSpeedUp = mSpeed; mCurrent = a.getInt(R.styleable.NumberPicker_current, mCurrent); mNumColor = a.getColor(R.styleable.NumberPicker_numColor, ContextCompat.getColor(context, android.R.color.primary_text_light)); mNumBackground = a.getDrawable(R.styleable.NumberPicker_numBackground); mNumSize = a.getDimension(R.styleable.NumberPicker_numSize, mNumSize); mNumHorizontalPadding = (int) a.getDimension(R.styleable.NumberPicker_numHorizontalPadding, mNumSize); mNumHorizontalPadding = (int) a.getDimension(R.styleable.NumberPicker_numVeticalPadding, mNumSize); mIncrementDrawable = a.getDrawable(R.styleable.NumberPicker_incrementDrawable); mDecrementDrawable = a.getDrawable(R.styleable.NumberPicker_decrementDrawable); mKeyboardInput = a.getBoolean(R.styleable.NumberPicker_keyboardInput, mKeyboardInput); String orientation = a.getString(R.styleable.NumberPicker_android_orientation); displayedValues = a.getResourceId(R.styleable.NumberPicker_displayedValues, 0); if (orientation != null) { vertical = !"0".equals(orientation); } a.recycle(); } else if (attrs != null && isInEditMode()) { // fix orientation attribute for editor String orientation = attrs.getAttributeValue("http://schemas.android.com/apk/res/android", "orientation"); if (orientation != null) { vertical = !"horizontal".equals(orientation); } } // set a wrong orientation so our own orientation method will perform changes super.setOrientation(!vertical ? VERTICAL : HORIZONTAL); setOrientation(vertical ? VERTICAL : HORIZONTAL); mChangeHandler = new Handler(); InputFilter inputFilter = new NumberPickerInputFilter(); mNumberInputFilter = new NumberRangeKeyListener(); mIncrementButton = (NumberPickerButton) findViewById(R.id.increment); mIncrementButton.setOnClickListener(this); mIncrementButton.setOnLongClickListener(this); mIncrementButton.setNumberPicker(this); mDecrementButton = (NumberPickerButton) findViewById(R.id.decrement); mDecrementButton.setOnClickListener(this); mDecrementButton.setOnLongClickListener(this); mDecrementButton.setNumberPicker(this); mIncrementButton.setBackground(null); mDecrementButton.setBackground(null); mIncrementButton.setScaleType(ImageView.ScaleType.FIT_CENTER); mDecrementButton.setScaleType(ImageView.ScaleType.FIT_CENTER); if (mIncrementDrawable != null) { mIncrementButton.setImageDrawable(mIncrementDrawable); } if (mDecrementDrawable != null) { mDecrementButton.setImageDrawable(mDecrementDrawable); } mText = (EditText) findViewById(R.id.timepicker_input); mText.setOnFocusChangeListener(this); mText.setFilters(new InputFilter[] { inputFilter }); mText.setRawInputType(InputType.TYPE_CLASS_NUMBER); LayoutParams params = (LayoutParams) mText.getLayoutParams(); params.weight = 1; mText.setLayoutParams(params); mText.setPadding(mNumHorizontalPadding, mNumVerticalPadding, mNumHorizontalPadding, mNumVerticalPadding); mText.setTextSize(mNumSize); if (mNumBackground != null) { mText.setBackground(mNumBackground); } else { mText.setBackground(ContextCompat.getDrawable(context, android.R.drawable.edit_text)); } if (!mKeyboardInput) { mText.setEnabled(false); } mText.setTextColor(mNumColor); if (!isEnabled()) { setEnabled(false); } if (displayedValues != 0) { setDisplayedRange(mStart, displayedValues); } else { setRange(mStart, mEnd); } }
From source file:com.geely.testbottomsheets.CustomBottomSheetBehavior.java
/** * Default constructor for inflating BottomSheetBehaviors from layout. * * @param context The {@link Context}.//from ww w. j av a2s. c o m * @param attrs The {@link AttributeSet}. */ public CustomBottomSheetBehavior(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, android.support.design.R.styleable.BottomSheetBehavior_Params); setPeekHeight(a.getDimensionPixelSize( android.support.design.R.styleable.BottomSheetBehavior_Params_behavior_peekHeight, 0)); setHideable(a.getBoolean(android.support.design.R.styleable.BottomSheetBehavior_Params_behavior_hideable, false)); a.recycle(); /** * Getting the anchorPoint... */ mAnchorPoint = DEFAULT_ANCHOR_POINT; a = context.obtainStyledAttributes(attrs, R.styleable.CustomBottomSheetBehavior); if (attrs != null) mAnchorPoint = (int) a.getDimension(R.styleable.CustomBottomSheetBehavior_anchorPoint, 0); a.recycle(); ViewConfiguration configuration = ViewConfiguration.get(context); mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); }