Skip to content

Instantly share code, notes, and snippets.

@enginebai

enginebai/init.java

Created Nov 19, 2016
Embed
What would you like to do?
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
You can’t perform that action at this time.