We are going to create a simple drawing app. Your teacher will show the class the screencast video for creating the user interface. You can watch this again yourself at any time:
Create a similar screen for your own FingerPaint app.
An algorithm is a design for a program. Algorithms show the steps taken by the program as it runs. For the apps we create with App Inventor we will need to write short algorithms for each event that can happen when the app is run.
Here are the events and algorithms for the FingerPaint app:
When a colour button is clicked
When canvas is touched
When wipe button is clicked
When small button is clicked
When large button is clicked
When canvas is dragged over
Your teacher will show the class the screencast video for creating the program. You can watch this again yourself at any time:
Now make your own FingerPaint app. Your code should look similar to the picture below:
Using either the Android emulator or live testing using a mobile phone, try out your app. Does it work the way you expect it to?
There are two bugs that you should have noticed when you were testing the FingerPaint app:
A variable is a space in a computer’s memory where we can hold information used by our program. It’s just like storing something in a box.
To create a variable, we need to give it variable a sensible name that indicates the kind of information that’s been stored there…just like putting a label on the box to tell us what’s inside. In App Inventor, the built-in initialize block can be used to create a variable.
We could use a variable to keep track of the brush size.
Now alter your app so that every time the user clicks on ButtonBigBrush or ButtonSmallBrush, the size of the brush is increased or decreased by 1 pixel. The code for making the brush size bigger is below, but you will have to work out the code for making the brush size smaller yourself:
Add another horizontal row of colour buttons below the current ones. Hint: by setting width to Fill parent…, you can also fit more colour buttons in a row – especially if you remove the Text property in the button.
Let’s add another feature: a camera button.
This will take the user to the camera app on the phone. After taking a photo, it will become the background of the drawing canvas. The user can then paint on the photo!
Hint: Add a camera button to the bottom row on the screen (a camera icon is provided with this lesson’s graphics). You will also need a camera component (Media→Camera).
Let’s consider the events and algorithms that we would use to make this happen:
when camera button is clicked
after picture is taken
The code to implement this is below:
Okay – one last feature: a save button.
This will let users save their masterpieces to the image gallery on their phone!
Hint: add a save button to the bottom row on the screen (located with the other downloads on the I Heart My Smartphone page). You will also need a TinyDB component – this is used to store data permanently on the phone (Storage→TinyDB).
Note that this feature only works when the app is downloaded to the phone. It will not work under live testing or on an emulator.
The event and algorithm for the code you will need is below
when Save button is clicked