Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.40 KB | None | 0 0
  1. public class DrawControlActivity extends Activity {
  2. /**
  3. * Dot diameter
  4. */
  5. final int LINE = 0;
  6. final int CIRCLE = 1;
  7. final int shape[] = {CIRCLE, LINE,};
  8. int mColorIndex = 0;
  9. int mShapeIndex = 0;
  10. Button mButtonSetColor;
  11. Button mButtonSetShape;
  12. Button mButtonDelLastShape;
  13. EditText editTextstartX;
  14. EditText editTextstartY;
  15. EditText editTextstopX;
  16. EditText editTextstopY;
  17. final Lines lines = new Lines();
  18. /**
  19. * The application view
  20. */
  21. LinesView linesView;
  22.  
  23. /**
  24. * Called when the activity is first created.
  25. */
  26. @Override
  27. public void onCreate(Bundle state) {
  28. super.onCreate(state);
  29. mLinesChangeListenerSet();
  30. mViewSetup();
  31. mButtonsSet();
  32. mEditTextSet();
  33. }
  34.  
  35. private void mViewSetup() {
  36. setContentView(R.layout.main);
  37. linesView = new LinesView(this, lines);
  38. ((LinearLayout) findViewById(R.id.root2)).addView(linesView);
  39. }
  40.  
  41. private void mLinesChangeListenerSet() {
  42. lines.setLinesChangeListener(new Lines.LinesChangeListener() {
  43. public void onLinesChange(Lines lines) {
  44. Line localLine = lines.getLastLine();
  45. editTextstartX.setText((null == localLine) ? "" : String.valueOf(localLine.getStartX()));
  46. editTextstartY.setText((null == localLine) ? "" : String.valueOf(localLine.getStartY()));
  47. editTextstopX.setText((null == localLine) ? "" : String.valueOf(localLine.getStopX()));
  48. editTextstopY.setText((null == localLine) ? "" : String.valueOf(localLine.getStopY()));
  49. }
  50. });
  51. }
  52.  
  53. private void mButtonsSet() {
  54. final int mLineColor[] = {Color.GREEN, Color.RED, Color.BLUE, Color.BLACK};
  55. mButtonSetColor = (Button) findViewById(R.id.button_lines_color);
  56. mButtonSetColor.setOnClickListener(
  57. new Button.OnClickListener() {
  58. public void onClick(View v) {
  59. setLinesColor(mLineColor[(mColorIndex) % mLineColor.length]);
  60. mButtonSetColor.setTextColor(mLineColor[(mColorIndex++) % mLineColor.length]);
  61. }
  62. });
  63. ((Button) findViewById(R.id.butoon_clear_screen)).setOnClickListener(
  64. new Button.OnClickListener() {
  65. public void onClick(View v) {
  66. viewScreenClean();
  67. }
  68. });
  69. mButtonSetShape = (Button) findViewById(R.id.button_shape_set);
  70. mButtonSetShape.setOnClickListener(
  71. new Button.OnClickListener() {
  72. public void onClick(View v) {
  73. switch (shape[(mShapeIndex++) % shape.length]) {
  74. case LINE:
  75. mShapeSet(LINE);
  76. mButtonSetShape.setText("Line");
  77. break;
  78. case CIRCLE:
  79. mShapeSet(CIRCLE);
  80. mButtonSetShape.setText("Circle");
  81. break;
  82. }
  83. }
  84. });
  85. mButtonDelLastShape = (Button) findViewById(R.id.button_last_draw_del);
  86. mButtonDelLastShape.setOnClickListener(new Button.OnClickListener() {
  87. public void onClick(View v) {
  88. lastShapeDelete();
  89. }
  90. });
  91. }
  92.  
  93. private void mEditTextSet() {
  94. editTextstartX = (EditText) findViewById(R.id.start_point_x);
  95. editTextstartY = (EditText) findViewById(R.id.start_point_y);
  96. editTextstopX = (EditText) findViewById(R.id.stop_point_x);
  97. editTextstopY = (EditText) findViewById(R.id.stop_point_y);
  98. }
  99.  
  100. /* Callbacks' Service Methods */
  101. private void setLinesColor(int color) {
  102. linesView.mShapeColorSet(color);
  103. }
  104.  
  105. private void viewScreenClean() {
  106. linesView.viewScreenClean();
  107. }
  108.  
  109. private void lastShapeDelete() {
  110. linesView.lastShapeDelete();
  111. }
  112.  
  113. private void mShapeSet(int shape) {
  114. switch (shape) {
  115. case LINE:
  116. linesView.mShapeSetLine();
  117. break;
  118. case CIRCLE:
  119. linesView.mShapeSetCircle();
  120. break;
  121. }
  122. }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement