Skip to content

Instantly share code, notes, and snippets.

@enginebai
Created November 19, 2016 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enginebai/6b8596abf88161e624b006b2ebee06fe to your computer and use it in GitHub Desktop.
Save enginebai/6b8596abf88161e624b006b2ebee06fe to your computer and use it in GitHub Desktop.
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