Guest User

Untitled

a guest
Sep 29th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. @Override
  2. protected synchronized void onDraw(Canvas canvas) {
  3. canvas.rotate(-90);
  4. canvas.translate(-getHeight(), 0);
  5.  
  6. super.onDraw(canvas);
  7. String progressText = String.valueOf(getProgress());
  8. Rect bounds = new Rect();
  9. mTextPaint.getTextBounds(progressText, 0, progressText.length(), bounds);
  10.  
  11. int leftPadding = getPaddingLeft() - getThumbOffset();
  12. int rightPadding = getPaddingRight() - getThumbOffset();
  13. int width = getWidth() - leftPadding - rightPadding;
  14. float progressRatio = (float) getProgress() / getMax();
  15. float thumbOffset = mThumbSize * (.5f - progressRatio);
  16. float thumbX = progressRatio * width + leftPadding + thumbOffset;
  17. float thumbY = getHeight() / 2f + bounds.height() / 2f;
  18. canvas.drawText(progressText, thumbX, thumbY, mTextPaint);
  19. canvas.rotate(90);
  20. }
Add Comment
Please, Sign In to add comment