Esempio n. 1
0
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_main);
   drawView = (DrawingView) findViewById(R.id.drawing);
   smallBrush = getResources().getInteger(R.integer.small_size);
   mediumBrush = getResources().getInteger(R.integer.medium_size);
   largeBrush = getResources().getInteger(R.integer.large_size);
   drawBtn = (ImageButton) findViewById(R.id.draw_btn);
   drawBtn.setOnClickListener(this);
   drawView.setBrushSize(mediumBrush);
   eraseBtn = (ImageButton) findViewById(R.id.erase_btn);
   eraseBtn.setOnClickListener(this);
   newBtn = (ImageButton) findViewById(R.id.new_btn);
   newBtn.setOnClickListener(this);
   equalsBtn = (ImageButton) findViewById(R.id.equals_btn);
   equalsBtn.setOnClickListener(this);
 }
Esempio n. 2
0
 @Override
 public void onClick(View view) {
   if (view.getId() == R.id.draw_btn) {
     if (!drawView.getErase()) {
       final Dialog brushDialog = new Dialog(this);
       brushDialog.setTitle("Brush size:");
       brushDialog.setContentView(R.layout.brush_chooser);
       ImageButton smallBtn = (ImageButton) brushDialog.findViewById(R.id.small_brush);
       smallBtn.setOnClickListener(
           new OnClickListener() {
             @Override
             public void onClick(View v) {
               drawView.setBrushSize(smallBrush);
               drawView.setLastBrushSize(smallBrush);
               brushDialog.dismiss();
             }
           });
       ImageButton mediumBtn = (ImageButton) brushDialog.findViewById(R.id.medium_brush);
       mediumBtn.setOnClickListener(
           new OnClickListener() {
             @Override
             public void onClick(View v) {
               drawView.setBrushSize(mediumBrush);
               drawView.setLastBrushSize(mediumBrush);
               brushDialog.dismiss();
             }
           });
       ImageButton largeBtn = (ImageButton) brushDialog.findViewById(R.id.large_brush);
       largeBtn.setOnClickListener(
           new OnClickListener() {
             @Override
             public void onClick(View v) {
               drawView.setBrushSize(largeBrush);
               drawView.setLastBrushSize(largeBrush);
               brushDialog.dismiss();
             }
           });
       brushDialog.show();
     }
     drawView.setErase(false);
   } else if (view.getId() == R.id.erase_btn) {
     if (drawView.getErase()) {
       final Dialog brushDialog = new Dialog(this);
       brushDialog.setTitle("Eraser size:");
       brushDialog.setContentView(R.layout.brush_chooser);
       ImageButton smallBtn = (ImageButton) brushDialog.findViewById(R.id.small_brush);
       smallBtn.setOnClickListener(
           new OnClickListener() {
             @Override
             public void onClick(View v) {
               drawView.setBrushSize(smallBrush);
               brushDialog.dismiss();
             }
           });
       ImageButton mediumBtn = (ImageButton) brushDialog.findViewById(R.id.medium_brush);
       mediumBtn.setOnClickListener(
           new OnClickListener() {
             @Override
             public void onClick(View v) {
               drawView.setBrushSize(mediumBrush);
               brushDialog.dismiss();
             }
           });
       ImageButton largeBtn = (ImageButton) brushDialog.findViewById(R.id.large_brush);
       largeBtn.setOnClickListener(
           new OnClickListener() {
             @Override
             public void onClick(View v) {
               drawView.setBrushSize(largeBrush);
               brushDialog.dismiss();
             }
           });
       brushDialog.show();
     }
     drawView.setErase(true);
   } else if (view.getId() == R.id.new_btn) {
     AlertDialog.Builder newDialog = new AlertDialog.Builder(this);
     newDialog.setTitle("New equation");
     newDialog.setMessage("Start new equation?");
     newDialog.setPositiveButton(
         "Yes",
         new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int which) {
             drawView.startNew();
             dialog.dismiss();
           }
         });
     newDialog.setNegativeButton(
         "Cancel",
         new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int which) {
             dialog.cancel();
           }
         });
     newDialog.show();
   } else if (view.getId() == R.id.equals_btn) {
     // save drawing
   }
 }