Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. public class CircleView2 extends LinearLayout {
  2.  
  3. private int centerX, centerY;
  4. private float fixedRadius = 30;
  5. private Paint paint;
  6. private Logger logger;
  7. private Context context;
  8. TextView textView;
  9.  
  10. public CircleView2(Context context) {
  11. super(context);
  12. setWillNotDraw(false);
  13. doInit(context);
  14.  
  15. }
  16.  
  17. public CircleView2(Context context, AttributeSet attrs) {
  18. super(context, attrs);
  19. setWillNotDraw(false);
  20. doInit(context);
  21. }
  22.  
  23. private void doInit(Context context) {
  24. this.context = context;
  25. logger = new Logger(context);
  26.  
  27. fixedRadius = 30;
  28.  
  29. paint = new Paint(Paint.ANTI_ALIAS_FLAG);
  30. paint.setStyle(Paint.Style.STROKE);
  31. paint.setStrokeWidth(5);
  32. paint.setColor(Color.rgb(227, 73, 90));
  33.  
  34. textView = new TextView(context);
  35. }
  36.  
  37. @Override
  38. protected void onSizeChanged(int w, int h, int oldw, int oldh) {
  39. super.onSizeChanged(w, h, oldw, oldh);
  40. centerX = w / 2;
  41. centerY = h / 2;
  42. }
  43.  
  44. @Override
  45. protected void onDraw(Canvas canvas) {
  46. canvas.drawCircle(centerX, centerY, fixedRadius + 160, paint);
  47.  
  48.  
  49. double x = centerX + (fixedRadius + 160) * Math.cos(Math.toDegrees(45.0));
  50. double y = centerY + (fixedRadius + 160) * Math.sin(Math.toDegrees(45.0));
  51.  
  52. logger.debug(x + "");
  53. logger.debug(y + "");
  54.  
  55. textView.setTextColor(Color.BLACK);
  56. textView.setText("AAA");
  57. textView.draw(canvas);
  58.  
  59. super.onDraw(canvas);
  60.  
  61. }
  62.  
  63.  
  64. @Override
  65. protected void onLayout(boolean changed, int l, int t, int r, int b) {
  66.  
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement