Created
November 19, 2016 15:14
-
-
Save enginebai/6b8596abf88161e624b006b2ebee06fe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void init(Context context, AttributeSet attrs) { | |
float density = getResources().getDisplayMetrics().density; | |
// Defaults, may need to link this into theme settings | |
int arcColor = ContextCompat.getColor(context, R.color.color_arc); | |
int progressColor = ContextCompat.getColor(context, R.color.color_progress); | |
int textColor = ContextCompat.getColor(context, R.color.color_text); | |
mProgressWidth = (int) (mProgressWidth * density); | |
mArcWidth = (int) (mArcWidth * density); | |
mTextSize = (int) (mTextSize * density); | |
mIndicatorIcon = ContextCompat.getDrawable(context, R.drawable.indicator); | |
if (attrs != null) { | |
// Attribute initialization | |
final TypedArray a = context.obtainStyledAttributes(attrs, | |
R.styleable.SwagPoints, 0, 0); | |
Drawable indicatorIcon = a.getDrawable(R.styleable.SwagPoints_indicatorIcon); | |
if (indicatorIcon != null) | |
mIndicatorIcon = indicatorIcon; | |
int indicatorIconHalfWidth = mIndicatorIcon.getIntrinsicWidth() / 2; | |
int indicatorIconHalfHeight = mIndicatorIcon.getIntrinsicHeight() / 2; | |
mIndicatorIcon.setBounds(-indicatorIconHalfWidth, -indicatorIconHalfHeight, indicatorIconHalfWidth, | |
indicatorIconHalfHeight); | |
mPoints = a.getInteger(R.styleable.SwagPoints_points, mPoints); | |
mMin = a.getInteger(R.styleable.SwagPoints_min, mMin); | |
mMax = a.getInteger(R.styleable.SwagPoints_max, mMax); | |
mStep = a.getInteger(R.styleable.SwagPoints_step, mStep); | |
mProgressWidth = (int) a.getDimension(R.styleable.SwagPoints_progressWidth, mProgressWidth); | |
progressColor = a.getColor(R.styleable.SwagPoints_progressColor, progressColor); | |
mArcWidth = (int) a.getDimension(R.styleable.SwagPoints_arcWidth, mArcWidth); | |
arcColor = a.getColor(R.styleable.SwagPoints_arcColor, arcColor); | |
mTextSize = (int) a.getDimension(R.styleable.SwagPoints_textSize, mTextSize); | |
mTextColor = a.getColor(R.styleable.SwagPoints_textColor, mTextColor); | |
mClockwise = a.getBoolean(R.styleable.SwagPoints_clockwise, | |
mClockwise); | |
mEnabled = a.getBoolean(R.styleable.SwagPoints_enabled, mEnabled); | |
a.recycle(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment