

Then, we override the onDraw method of the View class. To let the users to visualize the changes on the screen, we don’t forget to call the invalidate method to redraw the PaintView. The clear method will let us to clear the PaintView by clearing the list of Finger Paths. The PaintView will expose three methods to switch between the three modes of drawing : normal, emboss and blur. Furthermore, we initialize the Canvas and its underlying Bitmap used to draw paths on the screen. This method will take a DisplayMetrics Object in parameter and will be responsible to define the height and width of the PaintView. Now, we add an init method on the PaintView class.
#Simple paintbrush drawing code#
This gives us the following code for the PaintView at this stage of the tutorial : Finally, we create an EmbossMaskFilter Object for the emboss mode and an BlurMaskFilter for the blur mode. Then, we set the stroke join and stroke cap to ROUND. We need to define the style of the Paint Object as STROKE. In the constructor of the PaintView, we initialize the Paint Object used to draw the paths on the Canvas.

Besides, the PaintView object has a field for the Canvas used to draw the paths represented on the screen to the user. The PaintView will store several FingerPath objects inside an ArrayList field. The PaintView class will have some constants like the size the stroke width for the path also known as brush size or still the color of the path drawn. Obviously, our PaintView class will extend the View object from the standard SDK.

For that, we are going to create a PaintView class. With the possibility to represent a path drawn with the finger of the user on the screen, we need now to define a custom view to draw these paths on the screen.
