List of usage examples for android.content.res TypedArray getInt
public int getInt(@StyleableRes int index, int defValue)
From source file:com.bettervectordrawable.lib.graphics.drawable.VectorDrawable.java
private void updateStateFromTypedArray(TypedArray a) throws XmlPullParserException { final VectorDrawableState state = mVectorState; final VPathRenderer pathRenderer = state.mVPathRenderer; // Account for any configuration changes. state.mChangingConfigurations |= TypedArrayExtension.getChangingConfigurations(a); // Extract the theme attributes, if any. state.mThemeAttrs = extractThemeAttrs(a); final int tintMode = a.getInt(R.styleable.VectorDrawable_tintMode, -1); if (tintMode != -1) { state.mTintMode = parseTintMode(tintMode, Mode.SRC_IN); }//ww w . j a va 2 s . c o m final ColorStateList tint = a.getColorStateList(R.styleable.VectorDrawable_tint); if (tint != null) { state.mTint = tint; } state.mAutoMirrored = a.getBoolean(R.styleable.VectorDrawable_autoMirrored, state.mAutoMirrored); pathRenderer.mViewportWidth = a.getFloat(R.styleable.VectorDrawable_viewportWidth, pathRenderer.mViewportWidth); pathRenderer.mViewportHeight = a.getFloat(R.styleable.VectorDrawable_viewportHeight, pathRenderer.mViewportHeight); if (pathRenderer.mViewportWidth <= 0) { throw new XmlPullParserException( a.getPositionDescription() + "<vector> tag requires viewportWidth > 0"); } else if (pathRenderer.mViewportHeight <= 0) { throw new XmlPullParserException( a.getPositionDescription() + "<vector> tag requires viewportHeight > 0"); } pathRenderer.mBaseWidth = a.getDimension(R.styleable.VectorDrawable_android_width, pathRenderer.mBaseWidth); pathRenderer.mBaseHeight = a.getDimension(R.styleable.VectorDrawable_android_height, pathRenderer.mBaseHeight); if (pathRenderer.mBaseWidth <= 0) { throw new XmlPullParserException(a.getPositionDescription() + "<vector> tag requires width > 0"); } else if (pathRenderer.mBaseHeight <= 0) { throw new XmlPullParserException(a.getPositionDescription() + "<vector> tag requires height > 0"); } final int insetLeft = a.getDimensionPixelSize(R.styleable.VectorDrawable_opticalInsetLeft, pathRenderer.mOpticalInsets.left); final int insetTop = a.getDimensionPixelSize(R.styleable.VectorDrawable_opticalInsetTop, pathRenderer.mOpticalInsets.top); final int insetRight = a.getDimensionPixelSize(R.styleable.VectorDrawable_opticalInsetRight, pathRenderer.mOpticalInsets.right); final int insetBottom = a.getDimensionPixelSize(R.styleable.VectorDrawable_opticalInsetBottom, pathRenderer.mOpticalInsets.bottom); pathRenderer.mOpticalInsets = Insets.of(insetLeft, insetTop, insetRight, insetBottom); final float alphaInFloat = a.getFloat(R.styleable.VectorDrawable_android_alpha, pathRenderer.getAlpha()); pathRenderer.setAlpha(alphaInFloat); final String name = a.getString(R.styleable.VectorDrawable_android_name); if (name != null) { pathRenderer.mRootName = name; pathRenderer.mVGTargetsMap.put(name, pathRenderer); } }
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;//from ww w . j a va 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:com.albedinsky.android.ui.widget.BaseProgressBar.java
/** * Called from one of constructors of this view to perform its initialization. * <p>/* ww w . j a va 2 s .com*/ * Initialization is done via parsing of the specified <var>attrs</var> set and obtaining for * this view specific data from it that can be used to configure this new view instance. The * specified <var>defStyleAttr</var> and <var>defStyleRes</var> are used to obtain default data * from the current theme provided by the specified <var>context</var>. */ @SuppressLint("NewApi") private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { this.mUiThreadId = Thread.currentThread().getId(); // Use software layer that is required for proper drawing work of progress drawables. if (ProgressDrawable.REQUIRES_SOFTWARE_LAYER) { setLayerType(View.LAYER_TYPE_SOFTWARE, null); } onAttachDrawable(); if (mDrawable == null) { throw new IllegalArgumentException("No progress drawable has been attached."); } /** * Process attributes. */ final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Ui_ProgressBar, defStyleAttr, defStyleRes); if (typedArray != null) { this.processTintValues(context, typedArray); final int n = typedArray.getIndexCount(); for (int i = 0; i < n; i++) { final int index = typedArray.getIndex(i); if (index == R.styleable.Ui_ProgressBar_android_max) { setMax(typedArray.getInt(index, getMax())); } else if (index == R.styleable.Ui_ProgressBar_android_progress) { setProgress(typedArray.getInt(index, mProgress)); } else if (index == R.styleable.Ui_ProgressBar_uiColorProgress) { mDrawable.setColor(typedArray.getColor(index, mDrawable.getColor())); } else if (index == R.styleable.Ui_ProgressBar_uiColorsProgress) { final int colorsResId = typedArray.getResourceId(index, -1); if (colorsResId > 0 && !isInEditMode()) { mDrawable.setColors(context.getResources().getIntArray(colorsResId)); } } else if (index == R.styleable.Ui_ProgressBar_uiMultiColored) { mDrawable.setMultiColored(typedArray.getBoolean(index, mDrawable.isMultiColored())); } else if (index == R.styleable.Ui_ProgressBar_uiColorProgressBackground) { mDrawable.setBackgroundColor(typedArray.getInt(index, Color.TRANSPARENT)); } else if (index == R.styleable.Ui_ProgressBar_android_thickness) { mDrawable.setThickness(typedArray.getDimensionPixelSize(index, 0)); } else if (index == R.styleable.Ui_ProgressBar_uiRounded) { mDrawable.setRounded(!isInEditMode() && typedArray.getBoolean(index, mDrawable.isRounded())); } else if (index == R.styleable.Ui_ProgressBar_uiIndeterminateSpeed) { mDrawable.setIndeterminateSpeed(typedArray.getFloat(index, 1)); } } } mDrawable.setInEditMode(isInEditMode()); this.applyProgressTint(); this.applyIndeterminateTint(); this.applyProgressBackgroundTint(); }
From source file:com.devabit.takestock.ui.widget.FlexboxLayout.java
public FlexboxLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FlexboxLayout, defStyleAttr, 0); mFlexDirection = a.getInt(R.styleable.FlexboxLayout_flexDirection, FLEX_DIRECTION_ROW); mFlexWrap = a.getInt(R.styleable.FlexboxLayout_flexWrap, FLEX_WRAP_NOWRAP); mJustifyContent = a.getInt(R.styleable.FlexboxLayout_justifyContent, JUSTIFY_CONTENT_FLEX_START); mAlignItems = a.getInt(R.styleable.FlexboxLayout_alignItems, ALIGN_ITEMS_STRETCH); mAlignContent = a.getInt(R.styleable.FlexboxLayout_alignContent, ALIGN_CONTENT_STRETCH); a.recycle();//w w w . ja v a 2 s. c om }
From source file:com.aretha.slidemenu.SlideMenu.java
public SlideMenu(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // we want to draw drop shadow of content mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); mVelocityTracker = VelocityTracker.obtain(); mScroller = new Scroller(context, mInterpolator); mContentHitRect = new Rect(); STATUS_BAR_HEIGHT = (int) getStatusBarHeight(context); setWillNotDraw(false);// w w w .j a va 2s . c o m TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SlideMenu, defStyle, 0); // Set the shadow attributes setPrimaryShadowWidth(a.getDimension(R.styleable.SlideMenu_primaryShadowWidth, 30)); setSecondaryShadowWidth(a.getDimension(R.styleable.SlideMenu_secondaryShadowWidth, 30)); Drawable primaryShadowDrawable = a.getDrawable(R.styleable.SlideMenu_primaryShadowDrawable); if (null == primaryShadowDrawable) { primaryShadowDrawable = new GradientDrawable(Orientation.LEFT_RIGHT, new int[] { Color.TRANSPARENT, Color.argb(99, 0, 0, 0) }); } setPrimaryShadowDrawable(primaryShadowDrawable); Drawable secondaryShadowDrawable = a.getDrawable(R.styleable.SlideMenu_primaryShadowDrawable); if (null == secondaryShadowDrawable) { secondaryShadowDrawable = new GradientDrawable(Orientation.LEFT_RIGHT, new int[] { Color.argb(99, 0, 0, 0), Color.TRANSPARENT }); } setSecondaryShadowDrawable(secondaryShadowDrawable); mSlideDirectionFlag = a.getInt(R.styleable.SlideMenu_slideDirection, FLAG_DIRECTION_LEFT | FLAG_DIRECTION_RIGHT); setFocusable(true); setFocusableInTouchMode(true); a.recycle(); }
From source file:android.support.designox.widget.TextInputLayout.java
public TextInputLayout(Context context, AttributeSet attrs, int defStyleAttr) { // Can't call through to super(Context, AttributeSet, int) since it doesn't exist on API 10 super(context, attrs); ThemeUtils.checkAppCompatTheme(context); setOrientation(VERTICAL);//from ww w. j a va 2 s . c o m setWillNotDraw(false); setAddStatesFromChildren(true); mCollapsingTextHelper.setTextSizeInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR); mCollapsingTextHelper.setPositionInterpolator(new AccelerateInterpolator()); mCollapsingTextHelper.setCollapsedTextGravity(Gravity.TOP | GravityCompat.START); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TextInputLayout, defStyleAttr, R.style.Widget_Design_TextInputLayout); mHintEnabled = a.getBoolean(R.styleable.TextInputLayout_hintEnabled, true); setHint(a.getText(R.styleable.TextInputLayout_android_hint)); mHintAnimationEnabled = a.getBoolean(R.styleable.TextInputLayout_hintAnimationEnabled, true); if (a.hasValue(R.styleable.TextInputLayout_android_textColorHint)) { mDefaultTextColor = mFocusedTextColor = a .getColorStateList(R.styleable.TextInputLayout_android_textColorHint); } final int hintAppearance = a.getResourceId(R.styleable.TextInputLayout_hintTextAppearance, -1); if (hintAppearance != -1) { setHintTextAppearance(a.getResourceId(R.styleable.TextInputLayout_hintTextAppearance, 0)); } mErrorTextAppearance = a.getResourceId(R.styleable.TextInputLayout_errorTextAppearance, 0); final boolean errorEnabled = a.getBoolean(R.styleable.TextInputLayout_errorEnabled, false); final boolean counterEnabled = a.getBoolean(R.styleable.TextInputLayout_counterEnabled, false); setCounterMaxLength(a.getInt(R.styleable.TextInputLayout_counterMaxLength, INVALID_MAX_LENGTH)); mCounterTextAppearance = a.getResourceId(R.styleable.TextInputLayout_counterTextAppearance, 0); mCounterOverflowTextAppearance = a.getResourceId(R.styleable.TextInputLayout_counterOverflowTextAppearance, 0); a.recycle(); setErrorEnabled(errorEnabled); setCounterEnabled(counterEnabled); if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) { // Make sure we're important for accessibility if we haven't been explicitly not ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); } ViewCompat.setAccessibilityDelegate(this, new TextInputAccessibilityDelegate()); }
From source file:com.cs.widget.tab.PagerSlidingTabStrip1.java
public PagerSlidingTabStrip1(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setFillViewport(true);//w w w . j av a 2 s . co m setWillNotDraw(false); tabsContainer = new RadioGroup(context); tabsContainer.setOrientation(RadioGroup.HORIZONTAL); tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); tabsContainer.setPadding(0, 20, 0, 10); addView(tabsContainer); DisplayMetrics dm = getResources().getDisplayMetrics(); scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm); indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm); underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm); dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm); tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm); dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm); tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm); // get system attrs (android:textSize and android:textColor) TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip); tabTextSize = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_android_textSize, tabTextSize); tabTextColor = a.getColor(R.styleable.PagerSlidingTabStrip_android_textColor, tabTextColor); indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor); underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor); dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor); indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight, indicatorHeight); underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight, underlineHeight); dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding, dividerPadding); tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding); tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground, tabBackgroundResId); shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand); scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset); textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps); lineGravity = a.getInt(R.styleable.PagerSlidingTabStrip_pstsLineGravity, lineGravity); a.recycle(); rectPaint = new Paint(); rectPaint.setAntiAlias(true); rectPaint.setStyle(Style.FILL); dividerPaint = new Paint(); dividerPaint.setAntiAlias(true); dividerPaint.setStrokeWidth(dividerWidth); defaultTabLayoutParams = new RadioGroup.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); expandedTabLayoutParams = new RadioGroup.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f); if (locale == null) { locale = getResources().getConfiguration().locale; } }
From source file:com.cs.widget.tab.PagerSlidingTabStrip.java
public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setFillViewport(true);/* ww w.ja v a 2 s. co m*/ setWillNotDraw(false); tabsContainer = new LinearLayout(context); tabsContainer.setOrientation(LinearLayout.HORIZONTAL); tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); addView(tabsContainer); DisplayMetrics dm = getResources().getDisplayMetrics(); scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm); indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm); underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm); dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm); tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm); dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm); tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm); // get system attrs (android:textSize and android:textColor) TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip); tabTextSize = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_android_textSize, tabTextSize); tabTextColor = a.getColor(R.styleable.PagerSlidingTabStrip_android_textColor, tabTextColor); indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor); underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor); dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor); indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight, indicatorHeight); underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight, underlineHeight); dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding, dividerPadding); tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding); tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground, tabBackgroundResId); shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand); scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset); textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps); lineGravity = a.getInt(R.styleable.PagerSlidingTabStrip_pstsLineGravity, lineGravity); a.recycle(); rectPaint = new Paint(); rectPaint.setAntiAlias(true); rectPaint.setStyle(Style.FILL); dividerPaint = new Paint(); dividerPaint.setAntiAlias(true); dividerPaint.setStrokeWidth(dividerWidth); defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f); if (locale == null) { locale = getResources().getConfiguration().locale; } }
From source file:com.base.indicator.PagerIndicator.java
public PagerIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setFillViewport(true);//from w w w . j av a2 s .co m setWillNotDraw(false); tabsContainer = new LinearLayout(context); tabsContainer.setOrientation(LinearLayout.HORIZONTAL); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); tabsContainer.setLayoutParams(lp); addView(tabsContainer); DisplayMetrics dm = getResources().getDisplayMetrics(); scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm); indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm); underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm); dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm); tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm); dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm); tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm); // get system attrs (android:textSize and android:textColor) TypedArray a = context.obtainStyledAttributes(attrs, ATTRS); tabTextSize = a.getDimensionPixelSize(0, tabTextSize); tabTextColor = a.getColor(1, tabTextColor); a.recycle(); // get custom attrs a = context.obtainStyledAttributes(attrs, R.styleable.PagerIndicator); indicatorColor = a.getColor(R.styleable.PagerIndicator_pstsIndicatorColor, indicatorColor); underlineColor = a.getColor(R.styleable.PagerIndicator_pstsUnderlineColor, underlineColor); dividerColor = a.getColor(R.styleable.PagerIndicator_pstsDividerColor, dividerColor); indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerIndicator_pstsIndicatorHeight, indicatorHeight); underlineHeight = a.getDimensionPixelSize(R.styleable.PagerIndicator_pstsUnderlineHeight, underlineHeight); dividerPadding = a.getDimensionPixelSize(R.styleable.PagerIndicator_pstsDividerPadding, dividerPadding); tabPadding = a.getDimensionPixelSize(R.styleable.PagerIndicator_pstsTabPaddingLeftRight, tabPadding); tabBackgroundResId = a.getResourceId(R.styleable.PagerIndicator_pstsTabBackground, tabBackgroundResId); shouldExpand = a.getBoolean(R.styleable.PagerIndicator_pstsShouldExpand, shouldExpand); scrollOffset = a.getDimensionPixelSize(R.styleable.PagerIndicator_pstsScrollOffset, scrollOffset); textAllCaps = a.getBoolean(R.styleable.PagerIndicator_pstsTextAllCaps, textAllCaps); shouldSameWidth = a.getBoolean(R.styleable.PagerIndicator_shouldSameWidth, shouldSameWidth); scrollMode = a.getInt(R.styleable.PagerIndicator_scrollMode, SCROLL_MODE_LEFT); a.recycle(); rectPaint = new Paint(); rectPaint.setAntiAlias(true); rectPaint.setStyle(Style.FILL); dividerPaint = new Paint(); dividerPaint.setAntiAlias(true); dividerPaint.setStrokeWidth(dividerWidth); defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f); if (locale == null) { locale = getResources().getConfiguration().locale; } mScreenWidth = this.getResources().getDisplayMetrics().widthPixels; }
From source file:com.magicwindow.deeplink.ui.CircleProgressBar.java
private void init(Context context, AttributeSet attrs, int defStyleAttr) { final TypedArray a = context.obtainStyledAttributes(attrs, com.magicwindow.deeplink.R.styleable.CircleProgressBar, defStyleAttr, 0); final float density = getContext().getResources().getDisplayMetrics().density; mBackGroundColor = a.getColor(com.magicwindow.deeplink.R.styleable.CircleProgressBar_mlpb_background_color, DEFAULT_CIRCLE_BG_LIGHT);// ww w .j a v a 2s . c o m mProgressColor = a.getColor(com.magicwindow.deeplink.R.styleable.CircleProgressBar_mlpb_progress_color, DEFAULT_CIRCLE_BG_LIGHT);//ToDO mInnerRadius = a.getDimensionPixelOffset( com.magicwindow.deeplink.R.styleable.CircleProgressBar_mlpb_inner_radius, -1); mProgressStokeWidth = a.getDimensionPixelOffset( com.magicwindow.deeplink.R.styleable.CircleProgressBar_mlpb_progress_stoke_width, (int) (STROKE_WIDTH_LARGE * density)); mArrowWidth = a.getDimensionPixelOffset( com.magicwindow.deeplink.R.styleable.CircleProgressBar_mlpb_arrow_width, -1); mArrowHeight = a.getDimensionPixelOffset( com.magicwindow.deeplink.R.styleable.CircleProgressBar_mlpb_arrow_height, -1); mTextSize = a.getDimensionPixelOffset( com.magicwindow.deeplink.R.styleable.CircleProgressBar_mlpb_progress_text_size, (int) (DEFAULT_TEXT_SIZE * density)); mTextColor = a.getColor(com.magicwindow.deeplink.R.styleable.CircleProgressBar_mlpb_progress_text_color, Color.BLACK); mShowArrow = a.getBoolean(com.magicwindow.deeplink.R.styleable.CircleProgressBar_mlpb_show_arrow, false); mCircleBackgroundEnabled = a.getBoolean( com.magicwindow.deeplink.R.styleable.CircleProgressBar_mlpb_enable_circle_background, true); mProgress = a.getInt(com.magicwindow.deeplink.R.styleable.CircleProgressBar_mlpb_progress, 0); mMax = a.getInt(com.magicwindow.deeplink.R.styleable.CircleProgressBar_mlpb_max, 100); int textVisible = a .getInt(com.magicwindow.deeplink.R.styleable.CircleProgressBar_mlpb_progress_text_visibility, 1); if (textVisible != 1) { mIfDrawText = true; } mTextPaint = new Paint(); mTextPaint.setStyle(Paint.Style.FILL); mTextPaint.setColor(mTextColor); mTextPaint.setTextSize(mTextSize); mTextPaint.setAntiAlias(true); a.recycle(); mProgressDrawable = new MaterialProgressDrawable(getContext(), this); super.setImageDrawable(mProgressDrawable); }