Skip to content

Instantly share code, notes, and snippets.

@enginebai
Created November 20, 2016 06:37
Show Gist options
  • Save enginebai/1a5e5b78a17d90bebb465c31c9accc21 to your computer and use it in GitHub Desktop.
Save enginebai/1a5e5b78a17d90bebb465c31c9accc21 to your computer and use it in GitHub Desktop.
@Override
protected void onDraw(Canvas canvas) {
if (!mClockwise) {
canvas.scale(-1, 1, mArcRect.centerX(), mArcRect.centerY());
}
// draw the text
String textPoint = String.valueOf(mPoints);
mTextPaint.getTextBounds(textPoint, 0, textPoint.length(), mTextRect);
// center the text
int xPos = canvas.getWidth() / 2 - mTextRect.width() / 2;
int yPos = (int)((mArcRect.centerY()) - ((mTextPaint.descent() + mTextPaint.ascent()) / 2));
canvas.drawText(String.valueOf(mPoints), xPos, yPos, mTextPaint);
// draw the arc and progress
canvas.drawArc(mArcRect, ANGLE_OFFSET, 360, false, mArcPaint);
canvas.drawArc(mArcRect, ANGLE_OFFSET, mProgressSweep, false, mProgressPaint);
if (mEnabled) {
// draw the indicator icon
canvas.translate(mTranslateX - mIndicatorIconX, mTranslateY - mIndicatorIconY);
mIndicatorIcon.draw(canvas);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment