List of usage examples for android.content.res TypedArray getDimension
public float getDimension(@StyleableRes int index, float defValue)
From source file:com.baiiu.autoloopviewpager.indicator.LinePageIndicator.java
private void init(Context context, AttributeSet attrs) { if (isInEditMode()) return;//from w w w. j a va 2s . c o m final Resources res = getResources(); //Load defaults from resources final int defaultSelectedColor = Color.parseColor("#FF33B5E5"); final int defaultUnselectedColor = Color.parseColor("#FFBBBBBB"); final float defaultLineWidth = 36; final float defaultGapWidth = 12; final float defaultStrokeWidth = 3; final boolean defaultCentered = true; //Retrieve styles attributes TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LinePageIndicator); mCentered = a.getBoolean(R.styleable.LinePageIndicator_centered, defaultCentered); mLineWidth = a.getDimension(R.styleable.LinePageIndicator_lineWidth, defaultLineWidth); mGapWidth = a.getDimension(R.styleable.LinePageIndicator_gapWidth, 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(); }
From source file:com.lillicoder.demo.carouselview.widget.CarouselView.java
/** * Inflates and initializes this view.//w ww .ja va 2 s . c o m * @param context {@link Context} for this view. * @param attrs {@link AttributeSet} for this view. * @param defStyle Optional default style for this view. */ private void initialize(Context context, AttributeSet attrs, int defStyle) { setOrientation(LinearLayout.VERTICAL); LayoutInflater inflater = LayoutInflater.from(context); inflater.inflate(R.layout.view_carousel, this); mViewPager = (ViewPager) findViewById(R.id.CarouselView_viewPager); mIndicatorContainer = (ViewGroup) findViewById(R.id.CarouselView_indicatorContainer); if (attrs != null) { TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.CarouselView, defStyle, 0); Resources resources = getResources(); mIndicatorDrawableResourceId = attributes.getResourceId(R.styleable.CarouselView_indicator, R.drawable.carousel_indicator); mIndicatorPadding = (int) attributes.getDimension(R.styleable.CarouselView_indicatorPadding, resources.getDimension(R.dimen.indicator_padding)); } mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrollStateChanged(int state) { } @Override public void onPageScrolled(int position, float floatOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { int childCount = mIndicatorContainer.getChildCount(); for (int childPosition = 0; childPosition < childCount; childPosition++) { Checkable child = (Checkable) mIndicatorContainer.getChildAt(childPosition); if (child != null) { child.setChecked(childPosition == position); } } } }); }
From source file:com.fortysevendeg.android.swipelistview.RefreshSwipeListView.java
/** * Init ListView// w ww . ja v a 2 s. com * * @param attrs AttributeSet */ @Override protected void init(AttributeSet attrs) { int swipeMode = SWIPE_MODE_BOTH; boolean swipeOpenOnLongPress = true; boolean swipeCloseAllItemsWhenMoveList = true; long swipeAnimationTime = 0; float swipeOffsetLeft = 0; float swipeOffsetRight = 0; int swipeActionLeft = SWIPE_ACTION_REVEAL; int swipeActionRight = SWIPE_ACTION_REVEAL; if (attrs != null) { TypedArray styled = getContext().obtainStyledAttributes(attrs, R.styleable.SwipeListView); swipeMode = styled.getInt(R.styleable.SwipeListView_swipeMode, SWIPE_MODE_BOTH); swipeActionLeft = styled.getInt(R.styleable.SwipeListView_swipeActionLeft, SWIPE_ACTION_REVEAL); swipeActionRight = styled.getInt(R.styleable.SwipeListView_swipeActionRight, SWIPE_ACTION_REVEAL); swipeOffsetLeft = styled.getDimension(R.styleable.SwipeListView_swipeOffsetLeft, 0); swipeOffsetRight = styled.getDimension(R.styleable.SwipeListView_swipeOffsetRight, 0); swipeOpenOnLongPress = styled.getBoolean(R.styleable.SwipeListView_swipeOpenOnLongPress, true); swipeAnimationTime = styled.getInteger(R.styleable.SwipeListView_swipeAnimationTime, 0); swipeCloseAllItemsWhenMoveList = styled .getBoolean(R.styleable.SwipeListView_swipeCloseAllItemsWhenMoveList, true); mSwipeFrontView = styled.getResourceId(R.styleable.SwipeListView_swipeFrontView, 0); mSwipeBackView = styled.getResourceId(R.styleable.SwipeListView_swipeBackView, 0); } if (mSwipeFrontView == 0 || mSwipeBackView == 0) { mSwipeFrontView = getContext().getResources().getIdentifier(SWIPE_DEFAULT_FRONT_VIEW, "id", getContext().getPackageName()); mSwipeBackView = getContext().getResources().getIdentifier(SWIPE_DEFAULT_BACK_VIEW, "id", getContext().getPackageName()); if (mSwipeFrontView == 0 || mSwipeBackView == 0) { throw new RuntimeException(String.format( "You forgot the attributes swipeFrontView or swipeBackView. You can add this attributes or use '%s' and '%s' identifiers", SWIPE_DEFAULT_FRONT_VIEW, SWIPE_DEFAULT_BACK_VIEW)); } } final ViewConfiguration configuration = ViewConfiguration.get(getContext()); mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); mTouchListener = new SwipeRefreshListViewTouchListener(this, mSwipeFrontView, mSwipeBackView); if (swipeAnimationTime > 0) { mTouchListener.setAnimationTime(swipeAnimationTime); } mTouchListener.setRightOffset(swipeOffsetRight); mTouchListener.setLeftOffset(swipeOffsetLeft); mTouchListener.setSwipeActionLeft(swipeActionLeft); mTouchListener.setSwipeActionRight(swipeActionRight); mTouchListener.setSwipeMode(swipeMode); mTouchListener.setSwipeClosesAllItemsWhenListMoves(swipeCloseAllItemsWhenMoveList); mTouchListener.setSwipeOpenOnLongPress(swipeOpenOnLongPress); setOnTouchListener(mTouchListener); setOnScrollListener(mTouchListener.makeScrollListener()); }
From source file:com.tr4android.support.extension.widget.LabelView.java
public LabelView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); TypedArray attr = context.obtainStyledAttributes(attrs, R.styleable.LabelView, defStyleAttr, 0); // Background values mBackgroundColor = attr.getColor(R.styleable.LabelView_labelBackgroundColor, 0); mRippleColor = attr.getColor(R.styleable.LabelView_labelRippleColor, 0); mCornerRadius = attr.getDimension(R.styleable.LabelView_labelCornerRadius, 0f); mElevation = attr.getDimension(R.styleable.LabelView_labelElevation, 0f); // Padding values int paddingHorizontal = attr.getDimensionPixelSize(R.styleable.LabelView_labelPaddingHorizontal, 0); int paddingVertical = attr.getDimensionPixelSize(R.styleable.LabelView_labelPaddingVertical, 0); attr.recycle();//from www. j av a2 s . c om setFocusable(true); setClickable(true); initBackground(); setCompatPadding(paddingHorizontal, paddingVertical, paddingHorizontal, paddingVertical); }
From source file:android.view.SpringIndicator.java
private void initAttrs(final AttributeSet attrs) { textColorId = R.color.springIndicator_default_text_color; selectedTextColorId = R.color.springIndicator_default_text_color_selected; indicatorColorId = R.color.springIndicator_default_indicator_bg; textSize = getResources().getDimension(R.dimen.springIndicator_default_text_size); radiusMax = getResources().getDimension(R.dimen.springIndicator_default_radius_max); radiusMin = getResources().getDimension(R.dimen.springIndicator_default_radius_min); final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.SpringIndicator); textColorId = a.getResourceId(R.styleable.SpringIndicator_textColor, textColorId); selectedTextColorId = a.getResourceId(R.styleable.SpringIndicator_selectedTextColor, selectedTextColorId); textSize = a.getDimension(R.styleable.SpringIndicator_textSize, textSize); textBgResId = a.getResourceId(R.styleable.SpringIndicator_textBackground, 0); indicatorColorId = a.getResourceId(R.styleable.SpringIndicator_indicatorColor, indicatorColorId); indicatorColorsId = a.getResourceId(R.styleable.SpringIndicator_indicatorColors, 0); radiusMax = a.getDimension(R.styleable.SpringIndicator_maxRadius, radiusMax); radiusMin = a.getDimension(R.styleable.SpringIndicator_minRadius, radiusMin); a.recycle();// w w w. ja v a 2s . c om if (indicatorColorsId != 0) indicatorColorArray = getResources().getIntArray(indicatorColorsId); radiusOffset = radiusMax - radiusMin; }
From source file:com.grarak.kerneladiutor.views.XYGraph.java
public XYGraph(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mPaintLine = new Paint(Paint.ANTI_ALIAS_FLAG); mPaintEdge = new Paint(Paint.ANTI_ALIAS_FLAG); mPaintGraph = new Paint(Paint.ANTI_ALIAS_FLAG); mPaintGraphStroke = new Paint(Paint.ANTI_ALIAS_FLAG); mPathGraph = new Path(); mPaintEdge.setStyle(Paint.Style.STROKE); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.XYGraph, defStyleAttr, 0); int accentColor = ContextCompat.getColor(context, R.color.colorAccent); mPaintLine.setColor(a.getColor(R.styleable.XYGraph_linecolor, accentColor)); mPaintEdge.setColor(a.getColor(R.styleable.XYGraph_edgecolor, accentColor)); mPaintEdge.setStrokeWidth(a.getDimension(R.styleable.XYGraph_edgestrokewidth, getResources().getDimension(R.dimen.xygraph_edge_stroke_width))); int graphColor = a.getColor(R.styleable.XYGraph_graphcolor, accentColor); mPaintGraphStroke.setColor(graphColor); mPaintGraphStroke.setStyle(Paint.Style.STROKE); mPaintGraphStroke.setStrokeWidth(a.getDimension(R.styleable.XYGraph_graphstrokewidth, getResources().getDimension(R.dimen.xygraph_graph_stroke_width))); graphColor = Color.argb(120, Color.red(graphColor), Color.green(graphColor), Color.blue(graphColor)); mPaintGraph.setColor(graphColor);// w w w . j a v a 2 s. c o m mPaintGraph.setStyle(Paint.Style.FILL); mPathGraph.setFillType(Path.FillType.EVEN_ODD); mEdgeVisible = a.getBoolean(R.styleable.XYGraph_edgevisibile, true); a.recycle(); }
From source file:com.birdgang.viewpagerheader.indicator.SpringIndicator.java
private void initAttrs(AttributeSet attrs) { textColorId = R.color.si_default_text_color; selectedTextColorId = R.color.si_default_text_color_selected; indicatorColorId = R.color.si_default_indicator_bg; textSize = getResources().getDimension(R.dimen.si_default_text_size); radiusMax = getResources().getDimension(R.dimen.si_default_radius_max); radiusMin = getResources().getDimension(R.dimen.si_default_radius_min); TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.SpringIndicator); textColorId = a.getResourceId(R.styleable.SpringIndicator_siTextColor, textColorId); selectedTextColorId = a.getResourceId(R.styleable.SpringIndicator_siSelectedTextColor, selectedTextColorId); textSize = a.getDimension(R.styleable.SpringIndicator_siTextSize, textSize); textBgResId = a.getResourceId(R.styleable.SpringIndicator_siTextBg, 0); indicatorColorId = a.getResourceId(R.styleable.SpringIndicator_siIndicatorColor, indicatorColorId); indicatorColorsId = a.getResourceId(R.styleable.SpringIndicator_siIndicatorColors, 0); radiusMax = a.getDimension(R.styleable.SpringIndicator_siRadiusMax, radiusMax); radiusMin = a.getDimension(R.styleable.SpringIndicator_siRadiusMin, radiusMin); a.recycle();// w w w. j a v a 2 s . c om if (indicatorColorsId != 0) { indicatorColorArray = getResources().getIntArray(indicatorColorsId); } radiusOffset = radiusMax - radiusMin; }
From source file:me.uucky.colorpicker.internal.ColorView.java
public ColorView(final Context context, final AttributeSet attrs, final int defStyle) { super(context, attrs, defStyle); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ColorView); mRect = new RectF(); mColorPaint = new Paint(Paint.ANTI_ALIAS_FLAG); final Bitmap bitmap = Utils .getAlphaPatternBitmap(Math.round(getResources().getDisplayMetrics().density * 8)); mAlphaPatternPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mAlphaPatternPaint.setShader(new BitmapShader(bitmap, TileMode.REPEAT, TileMode.REPEAT)); mRadius = a.getDimension(R.styleable.ColorView_cp_cornerRadius, 0); ViewCompat.setElevation(this, a.getDimension(R.styleable.ColorView_cp_elevation, 0)); a.recycle();/* w ww .j a v a 2s . co m*/ if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) { Internal.setOutlineProvider(this); } }
From source file:com.ruesga.rview.widget.MergedStatusChart.java
public MergedStatusChart(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); setLayerType(View.LAYER_TYPE_SOFTWARE, null); final Resources res = getResources(); mHeightBarPadding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, res.getDisplayMetrics()); mMinBarWidth = 0f;/*from ww w . ja va2s .com*/ int openColor = Color.DKGRAY; int mergedColor = Color.DKGRAY; int abandonedColor = Color.DKGRAY; int textColor = Color.WHITE; Resources.Theme theme = context.getTheme(); TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.MergedStatusChart, defStyleAttr, 0); int n = a.getIndexCount(); for (int i = 0; i < n; i++) { int attr = a.getIndex(i); switch (attr) { case R.styleable.MergedStatusChart_heightBarPadding: mHeightBarPadding = a.getDimension(attr, mHeightBarPadding); break; case R.styleable.MergedStatusChart_minBarWidth: mMinBarWidth = a.getDimension(attr, mMinBarWidth); break; case R.styleable.MergedStatusChart_openColor: openColor = a.getColor(attr, openColor); break; case R.styleable.MergedStatusChart_mergedColor: mergedColor = a.getColor(attr, mergedColor); break; case R.styleable.MergedStatusChart_abandonedColor: abandonedColor = a.getColor(attr, abandonedColor); break; case R.styleable.MergedStatusChart_statusLabelTextColor: textColor = a.getColor(attr, textColor); break; } } a.recycle(); mOpenPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mOpenPaint.setStyle(Paint.Style.FILL); mMergedPaint = new Paint(mOpenPaint); mAbandonedPaint = new Paint(mOpenPaint); mOpenPaint.setColor(openColor); mMergedPaint.setColor(mergedColor); mAbandonedPaint.setColor(abandonedColor); mLabelPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.LINEAR_TEXT_FLAG); mLabelPaint.setTextAlign(Paint.Align.LEFT); mLabelPaint.setFakeBoldText(true); mLabelPaint.setColor(textColor); mLabelPaint .setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 10f, res.getDisplayMetrics())); mLabelPadding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 2f, res.getDisplayMetrics()); Rect bounds = new Rect(); mLabelPaint.getTextBounds("0", 0, 1, bounds); mLabelHeight = bounds.height(); if (getBackground() == null) { setBackgroundColor(Color.TRANSPARENT); } }
From source file:com.todddavies.components.progressbar.ProgressWheel.java
/** * Parse the attributes passed to the view from the XML * * @param a the attributes to parse//from ww w .j a v a 2s. co m */ 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 = 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); //if the text is empty , so ignore it if (a.hasValue(R.styleable.ProgressWheel_text)) { 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); contourColor = a.getColor(R.styleable.ProgressWheel_contourColor, contourColor); contourSize = a.getDimension(R.styleable.ProgressWheel_contourSize, contourSize); // Recycle a.recycle(); }