@SuppressLint("ShowToast") @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.free) { MyCanvas.shapeType = "free"; Toast.makeText(getApplicationContext(), "Free Drawing", Toast.LENGTH_LONG).show(); } else if (id == R.id.line) { MyCanvas.shapeType = "line"; Toast.makeText(getApplicationContext(), "Line", Toast.LENGTH_LONG).show(); } else if (id == R.id.rectangle) { MyCanvas.shapeType = "rectangle"; Toast.makeText(getApplicationContext(), "Rectangle", Toast.LENGTH_LONG).show(); } else if (id == R.id.ellipse) { MyCanvas.shapeType = "ellipse"; Toast.makeText(getApplicationContext(), "Ellipse", Toast.LENGTH_LONG).show(); } else if (id == R.id.circle) { MyCanvas.shapeType = "circle"; Toast.makeText(getApplicationContext(), "Circle", Toast.LENGTH_LONG).show(); } else if (id == R.id.square) { MyCanvas.shapeType = "square"; Toast.makeText(getApplicationContext(), "Square", Toast.LENGTH_LONG).show(); } else if (id == R.id.background_color) { AmbilWarnaDialog colorDialog = new AmbilWarnaDialog( this, Color.WHITE, new OnAmbilWarnaListener() { @Override public void onOk(AmbilWarnaDialog dialog, int color) { drawingArea.setBackgroundColor(color); drawingArea.backgroundColor = color; } @Override public void onCancel(AmbilWarnaDialog dialog) { // cancel was selected by the user } }); colorDialog.show(); } else if (id == R.id.pen_color) { AmbilWarnaDialog colorDialog = new AmbilWarnaDialog( this, Color.WHITE, new OnAmbilWarnaListener() { @Override public void onOk(AmbilWarnaDialog dialog, int color) { drawingArea.paint.setColor(color); drawingArea.penColor = color; } @Override public void onCancel(AmbilWarnaDialog dialog) { // cancel was selected by the user } }); colorDialog.show(); } else if (id == R.id.pen_width) { final EditText input = new EditText(MainActivity.this); new AlertDialog.Builder(MainActivity.this) .setTitle("Stroke Width") .setMessage("Enter an integer") .setView(input) .setPositiveButton( "Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String width = input.getText().toString(); if (isInteger(width)) { Toast.makeText( getApplicationContext(), "Stroke Width = " + width, Toast.LENGTH_LONG) .show(); strokeWidth = Integer.parseInt(width); drawingArea.strokeWidth = strokeWidth; drawingArea.paint.setStrokeWidth(strokeWidth); } else { Toast.makeText( getApplicationContext(), "Invalid input for stroke width", Toast.LENGTH_LONG) .show(); } } }) .setNegativeButton( "Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Do nothing. } }) .show(); } else if (id == R.id.clear) { backgroundColor = drawingArea.backgroundColor; penColor = drawingArea.penColor; strokeWidth = drawingArea.strokeWidth; drawingArea = new MyCanvas(this); drawingArea.backgroundColor = backgroundColor; drawingArea.penColor = penColor; drawingArea.strokeWidth = strokeWidth; drawingArea.setBackgroundColor(backgroundColor); drawingArea.paint.setColor(penColor); drawingArea.paint.setStrokeWidth(strokeWidth); setContentView(drawingArea); } else if (id == R.id.save) { startService(new Intent(getBaseContext(), MyIntentService.class)); MyIntentService.counter++; } else if (id == R.id.load) { Intent choosePictureIntent = new Intent( Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(choosePictureIntent, 0); } else if (id == R.id.triangle) { MyCanvas.shapeType = "triangle"; Toast.makeText(getApplicationContext(), "Triangle", Toast.LENGTH_LONG).show(); } else if (id == R.id.filled) { drawingArea.paint.setStyle(Paint.Style.FILL_AND_STROKE); drawingArea.filled = true; Toast.makeText(getApplicationContext(), "Filled Shapes", Toast.LENGTH_LONG).show(); } else if (id == R.id.not_filled) { drawingArea.paint.setStyle(Paint.Style.STROKE); drawingArea.filled = false; Toast.makeText(getApplicationContext(), "Unfilled Shapes", Toast.LENGTH_LONG).show(); } return super.onOptionsItemSelected(item); }