Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DrawControlActivity extends Activity {
- /**
- * Dot diameter
- */
- final int LINE = 0;
- final int CIRCLE = 1;
- final int shape[] = {CIRCLE, LINE,};
- int mColorIndex = 0;
- int mShapeIndex = 0;
- Button mButtonSetColor;
- Button mButtonSetShape;
- Button mButtonDelLastShape;
- EditText editTextstartX;
- EditText editTextstartY;
- EditText editTextstopX;
- EditText editTextstopY;
- final Lines lines = new Lines();
- /**
- * The application view
- */
- LinesView linesView;
- /**
- * Called when the activity is first created.
- */
- @Override
- public void onCreate(Bundle state) {
- super.onCreate(state);
- mLinesChangeListenerSet();
- mViewSetup();
- mButtonsSet();
- mEditTextSet();
- }
- private void mViewSetup() {
- setContentView(R.layout.main);
- linesView = new LinesView(this, lines);
- ((LinearLayout) findViewById(R.id.root2)).addView(linesView);
- }
- private void mLinesChangeListenerSet() {
- lines.setLinesChangeListener(new Lines.LinesChangeListener() {
- public void onLinesChange(Lines lines) {
- Line localLine = lines.getLastLine();
- editTextstartX.setText((null == localLine) ? "" : String.valueOf(localLine.getStartX()));
- editTextstartY.setText((null == localLine) ? "" : String.valueOf(localLine.getStartY()));
- editTextstopX.setText((null == localLine) ? "" : String.valueOf(localLine.getStopX()));
- editTextstopY.setText((null == localLine) ? "" : String.valueOf(localLine.getStopY()));
- }
- });
- }
- private void mButtonsSet() {
- final int mLineColor[] = {Color.GREEN, Color.RED, Color.BLUE, Color.BLACK};
- mButtonSetColor = (Button) findViewById(R.id.button_lines_color);
- mButtonSetColor.setOnClickListener(
- new Button.OnClickListener() {
- public void onClick(View v) {
- setLinesColor(mLineColor[(mColorIndex) % mLineColor.length]);
- mButtonSetColor.setTextColor(mLineColor[(mColorIndex++) % mLineColor.length]);
- }
- });
- ((Button) findViewById(R.id.butoon_clear_screen)).setOnClickListener(
- new Button.OnClickListener() {
- public void onClick(View v) {
- viewScreenClean();
- }
- });
- mButtonSetShape = (Button) findViewById(R.id.button_shape_set);
- mButtonSetShape.setOnClickListener(
- new Button.OnClickListener() {
- public void onClick(View v) {
- switch (shape[(mShapeIndex++) % shape.length]) {
- case LINE:
- mShapeSet(LINE);
- mButtonSetShape.setText("Line");
- break;
- case CIRCLE:
- mShapeSet(CIRCLE);
- mButtonSetShape.setText("Circle");
- break;
- }
- }
- });
- mButtonDelLastShape = (Button) findViewById(R.id.button_last_draw_del);
- mButtonDelLastShape.setOnClickListener(new Button.OnClickListener() {
- public void onClick(View v) {
- lastShapeDelete();
- }
- });
- }
- private void mEditTextSet() {
- editTextstartX = (EditText) findViewById(R.id.start_point_x);
- editTextstartY = (EditText) findViewById(R.id.start_point_y);
- editTextstopX = (EditText) findViewById(R.id.stop_point_x);
- editTextstopY = (EditText) findViewById(R.id.stop_point_y);
- }
- /* Callbacks' Service Methods */
- private void setLinesColor(int color) {
- linesView.mShapeColorSet(color);
- }
- private void viewScreenClean() {
- linesView.viewScreenClean();
- }
- private void lastShapeDelete() {
- linesView.lastShapeDelete();
- }
- private void mShapeSet(int shape) {
- switch (shape) {
- case LINE:
- linesView.mShapeSetLine();
- break;
- case CIRCLE:
- linesView.mShapeSetCircle();
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement