SHARE
TWEET

Untitled

a guest Jan 12th, 2017 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) {
  2.     super.onSizeChanged(w, h, oldw, oldh);
  3.     halfWidth = w/2;
  4.     int radius = Math.min(halfWidth, h);
  5.     outerRadius = (int) (radius * OUTER_RADIUS_PERCENT);
  6.     innerRadius = outerRadius - blockHeight;
  7.   }
  8.  
  9.   @Override protected void onDraw(Canvas canvas) {
  10.     super.onDraw(canvas);
  11.     canvas.rotate(2.5f, halfWidth, getHeight());
  12.     for (int i=0; i<BLOCKS; i++) {
  13.       canvas.drawRect(halfWidth - outerRadius, getHeight() - blockWidth,
  14.           halfWidth - innerRadius, getHeight(),
  15.           i > activeBlocks ? blockPaint : activeBlockPaint);
  16.       canvas.rotate(ROTATE_ANGLE, halfWidth, getHeight());
  17.     }
  18.   }
  19.  
  20.   public void setAngle(float angle) {
  21.     int oldActiveBlocks = activeBlocks;
  22.     activeBlocks = (int) (angle / ROTATE_ANGLE);
  23.     currentAngle = angle;
  24.     if (oldActiveBlocks != activeBlocks) postInvalidate();
  25.   }
RAW Paste Data
Top