Professional Documents
Culture Documents
2.
3.
4.
5.
6.
7.
8.
9.
Application
Talk
to
Me
Ball
Bounce
Digital
Doodle
I
have
a
dream
Hello
Zombie
Paint
Pot
Android
Mash
Magic
8
ball
Weather
App
Learn about
Expertise
Text
to
speech
Ball
object.
Animation.
Canvas
drawing.
Display
photos.
Play
sounds.
Button
controls
First
Apps
First
Apps
First
Apps
Basic
Basic
Basic
Basic
Basic
Basic
Intermediate
Build
the
classic
game
Pong
and
learn
how
to
animate
image
sprites,
deal
with
collisions,
keep
score,
and
define
procedures
to
make
your
code
better.
Use
clock
components
and
Timers,
using
Animation
components
such
as
Image
Sprites
and
the
Canvas,
setting
visibility,
and
detecting
collisions
Multiple
objects
on
the
screen.
Collisions
The
Stock
Market
app
displays
the
current
price
of
any
stock
you
enter.
You'll
learn
how
to
web-enable
your
app
and
communicate
with
Web
APIs,
in
this
case
Yahoo
Finance
Program
the
Android
Logo
to
create
shapes
and
learn
about
algorithms,
procedures,
and
parameters
Beat
Box
App.
Use
the
Android
SoundRecorder,
Player,
take
another
look
at
using
list,
logic
and
incremental
programming.
Using
Lists,
List
Pickers,
TinyDB,
TinyWebDB,
Fusion
Tables,
and
Texting.
Intermediate
Intermediate
20. Contact
Database
Send
and
store
messages
in
an
online
database
using
TinyWebDB
21. Chat
App
Fusion
Tables
to
share
data
among
several
users
of
a
single
app.
22. Pizza
Party
Display
the
weather
forecast
for
any
US
city.
Forecast
data
comes
23. Advanced
from
the
US
Governments
weather
broadcast
service.
Weather
App
24. Wheres
my
Use
GPS
data
to
find
where
you
parked
your
car.
car?
25. Map
Locations
Use
GPS
data
to
mark
locations
on
a
Google
map.
26. Friend
Locator
Design
and
create
an
app
that
shows
your
friends
location
Items
in
BLUE
do
not
have
video
tutorials
but
use
text
directions
only.
Basic
Intermediate
Intermediate
Intermediate
Intermediate
Intermediate
Intermediate
Advanced
Advanced
Advanced
Advanced
Advanced
Advanced
Advanced
Page 1
Table
of
Contents
First
apps
(1)
Talk
to
Me,
(2)
Ball
Bounce
and
(3)
Digital
Doodle.
.................................................
4
4
I
have
a
dream
............................................................................................................................................
5
5
Hello
Zombie
..................................................................................................................................................
6
6
-
Paint
Pot
...........................................................................................................................................................
7
7
-
Android
Mash
.................................................................................................................................................
9
8
Magic
8
Ball
..................................................................................................................................................
10
9
-
Weather
App
................................................................................................................................................
16
10
Camera
App
...............................................................................................................................................
17
11
-
Presidents
Quiz
.......................................................................................................................................
18
12
-
No
Texting
While
Driving
......................................................................................................................
20
13
Get
the
Gold
...............................................................................................................................................
22
14
Pong
.............................................................................................................................................................
28
15
Space
Invaders
.........................................................................................................................................
30
16
-
Mini
Golf
......................................................................................................................................................
34
17
Stock
Market
.............................................................................................................................................
45
18
The
Logo
Challenge
................................................................................................................................
46
19
Voice
Recorder
.........................................................................................................................................
47
20
Contact
Database
....................................................................................................................................
48
21
-
Chat
App
......................................................................................................................................................
50
22
-
Pizza
Order
App
.......................................................................................................................................
52
23
-
Advanced
Weather
App
.........................................................................................................................
63
24
-
Wheres
My
Car?
.......................................................................................................................................
68
25
-
Map
Locations
...........................................................................................................................................
72
26
-
Friend
Locator
..........................................................................................................................................
77
Page 2
(1) Follow
the
online
tutorial
video
for
each
lesson.
Pause
the
video
as
necessary.
Open
two
tabs
on
your
web
browser
first
the
App
Inventor
page
and
the
second
tab
for
the
video.
If
you
have
a
second
computer
or
tablet,
you
can
watch
both
screens
at
the
same
time.
(2) (2)
Use
the
programming
blocks
printed
in
this
book
for
reference.
(3)
When
finished
with
the
app,
add
at
least
one
improvement
to
the
program.
(4)
Use
the
following
form
to
write
about
your
assignment.
(5)
Turn
in
the
form
(below)
and
the
AIA
source
code
file
using
MyBigCampus.com
1.
Name
2.
Assignment
Number
and
Name
3.
Things
that
I
learned
while
doing
this
assignment.
What
were
the
main
components
that
this
app
used?
What
new
methods
of
programming
did
you
see?
4
Enhancements
that
I
made
to
the
program.
Code
Blocks.
Shad
Sluiter
#1
Talk
to
me
I
created
my
first
application
with
App
Inventor.
I
had
to
create
a
APK
file
and
transfer
it
to
my
phone
to
test
it
out.
This
program
uses
the
text
to
speech
abilities
of
Android.
I
added
a
second
field
and
button
to
allow
the
program
to
speak
more
than
one
sentence.
Page 3
Part
2
Block
code
for
Ball
Bounce
Page 4
4 I have a dream
"I
Have
a
Dream!"
is
an
educational
"soundboard"
app
that
plays
the
famous
speech
of
Martin
Luther
King.
Its
a
great
way
to
get
started
with
App
Inventor
and
programming.
step
1:
Introduction
Check
out
the
two
apps
you'll
build
step
2:
Build
your
first
app:
clicking
on
MLK
plays
"I
Have
a
Dream"
Download
the
starter
app,
setup
the
UI,
then
code
it
so
that
tapping
the
picture
plays
the
speech
step
3:
Add
complexity
to
the
app
in
a
big
way:
Malcolm
X
speaks!
Add
a
second
image
and
Player
component,
then
code
it
so
that
you
can
pause
the
speeches.
Page 5
5 Hello Zombie
This
application
tries
to
include
as
many
different
controls
in
one
application
as
possible.
This
tutorial
is
in
two
videos.
In
part
1,
Ill
cover
how
to
install
App
Inventor
and
then
use
it
to
make
an
app
that
uses
GPS,
Opens
Dialog
Boxes,
Opens
other
apps,
vibrates
devices,
plays
sounds,
converts
text
to
speech,
uses
the
accelerometer,
adapts
to
screen
orientation
and
more.
In
part
2,
I
cover
Location
Sensor,
global
variables,
changing
label
text,
working
with
strings,
Sound,
Buttons,
Event
Handling,
Text
to
Speech,
Vibration,
Accelerometers,
Orientation
changes,
Dialog
boxes
and
executing
activities.
Download
the
images
and
sounds
here.
http://www.newthinktank.com/2014/01/android-
development-beginners-2/
Page 6
6 - Paint Pot
Paintpot
allows
you
to
draw
circles
and
lines
on
a
picture
you
take
with
your
camera.
You'll
learn
about
Step
2:
Build
the
user
interface
Drag
out
a
canvas
and
sets
its
width
to
"fill
parent".
Then
add
the
color
buttons
within
a
horizontal
arrangement.
Page 7
step
3:
Draw
Line
and
Circle
In
the
blocks
editor,
drag
out
a
Canvas.touched
event
and
then
place
a
Canvas.DrawCircle
within
it.
step
4:
Add
code
so
that
the
user
can
draw
in
different
colors.
Drag
out
a
Canvas.Dragged
event
then
place
a
Canvas.DrawLine
within
it.
step
5:
Add
code
so
the
user
can
draw
circles
of
different
sizes..
Change
the
size
of
the
circle
step
6:
Add
Camera
Code
the
color
button
Click
events
to
set
the
Canvas.PaintColor
property.
Step
7:
Add
Slider
Page 8
7 - Android Mash
Android
Mash
is
a
game
in
which
an
Android
dude
jumps
randomly
around
the
screen
and
you
try
to
mash
it.
You'll
learn
about
timer
events,
randomness,
and
be
introduced
to
animation.
Build
It
Follow
the
video
steps
below
to
build
the
app
yourself.
step
1:
Professor
Wolber
introduces
the
AndroidMash
app
Check
out
the
app
and
see
what
you'll
learn.
step
2:
Build
the
basic
game
Add
a
Canvas
and
image
sprite,
then
add
blocks
so
that
the
mole
moves
randomly
and
touching
it
causes
the
phone
to
vibrate
step
3:
Professor
Wolber
introduces
a
challenge
Add
blocks
so
that
touching
the
mole
increments
the
score,
the
game
ends
at
a
certain
score,
and
you
can
restart
the
game.
step
4:
Add
scoring,
end
game
and
restart
to
the
game
Add
blocks
so
that
the
score
is
incremented,
the
game
ends
at
a
certain
score,
and
the
game
can
be
restarted
(solution
to
challenge)
Page 9
8 Magic 8 Ball
Magic 8 Ball does not have a video tutorial. Use the written instructions below to
complete the app.
Part
One:
Click
a
Button,
Hear
a
Sound
The final Magic 8-Ball App will deliver a prediction from a list that you have designed. To get started, first we'll
make a button with a picture on it, and program it to play a sound when the
button is clicked.
DESIGN: App Inventor Designer
1. To open the App Inventor Designer window, open a new tab or window in
your browser and go to http://newblocks.appinventor.mit.edu. See setup
instructions if you are not sure how to sign in.
2. If you have already made an app (such as Hello Purr), you will
automatically be directed to the Designer with the last project you worked
on showing. Click "Project" in the upper left corner of the screen and then
"My Projects", which will take you to your list of projects. Click "New
Project" and name your project something like "Magic8Ball" (note: spaces
are not allowed).
3. Download images and sounds that you will use in this tutorial at
http://www.studyoffice.org/appinventor/8BallImagesSounds.zip
4. On the left column of the Designer, the User Interface palette should be open. If it is not, click to open it.
Drag a Button component over to the Viewer (#1 below).
5. Set the button image to an 8-Ball image:
Click on your newly added button to see its properties in the Properties pane on the right. Under "Image"
click on the word "None..." and a small selection window will pop up (#2). Click the "Upload File" button and
browse to where you saved the 8-Ball image. Select the file, then click OK to close the selection window.
Click OK again on the properties pane to close the small popup window (#3).
Page 10
6. Go to the text field in the Properties pane and delete the display text of your button
component (#4).
7. From the Media palette, drag over a Sound component onto the Viewer pane (#1). Notice that since the
sound will not be a visible part of the app, it appears at the bottom of the Viewer pane, as a Non-visible
component.
8. Set the sound component's
source file:
Click on your newly added
sound component to see its
properties in the Properties pane
on the right. Under "Source"
click in the small box on the
word "None..." and a small
selection window will pop up
(#2). Click the "Upload File" button and browse to where you saved the sound file. Select the sound file, then
click OK to close the selection
window. Click OK again on the
properties pane to close the small
popup window (#3).
9. You have now completed the work in
the Designer for Part One of this
app. It's time now to go over to the
Blocks Editor to program the
behavior of these components.
BUILD: Blocks Editor
In the upper right corner of the Designer,
click on the Blocks button.
Now you are going to tell your app how to behave when the button is clicked. This is actually very simple in App
Inventor, because the "code" for the program only consists of two blocks!
Page 11
Once the Blocks Editor is open, there are several options running along the left side of the
screen. We refer to these as "Palettes" with Drawers.
From the blocks palette located under Screen1, click on the Button1 drawer. Drag the when Button1.Click block
into the work area (#1). From the blocks palette, click on the Sound1 drawer, drag the Sound1.Play block into the
work area and insert it into the when Button1.Click block (#2). They will click together like magnetic puzzle pieces.
Your blocks should now look like this:
That's it! You've written the program for Part One of Magic 8-Ball. Now it's time to test that it's working right.
TEST: Phone/Emulator
You have now built an app! To test that it works, you either have to launch an emulator, or connect to a phone.
Go back to the Setup Instructions if you do not have a phone or an emulator running.
Emulator: click on the picture, you will hear the sound play.
Phone: tap the picture, you will hear the sound play.
Note: If you don't hear the sound, first be sure you have the volume turned up on your device (or computer if using
emulator). Also, make sure your device has an SD card. App Inventor stores media files to the SD card. In some
devices, the Play component does not work correctly. You will need to use the Player component instead of the
Sound component.
Page 12
Inventor will know that you want to line
them up vertically (one on top of the
other).
3. From the Basic palette, drag over another Label component (Label2) into the Vertical Arrangement box so
that it sits right below Label1. Change the "Text" property of the Label2 to Touch the Magic 8-Ball to
receive your answer. Now drag the 8-Ball image so that it is also inside the Vertical Arrangement
component on top of the two labels. This will cause them to line up with each other in a vertical line. (Note:
this can be tricky mouse work, but get them in there just right and the vertical arrangement will resize itself to
fit everything.)
Now its time to go back into the Blocks Editor to program the components you just added to your project.
BUILD: Blocks Editor
Now for the fun part! You're going to make a list of predictions and program the button to pick one item from the
list and display it inside Label2. The button will also still play the sound that you programmed in Part One. Here's
how to do it...
1. From the blocks palette, click
on Label2 drawer to see all of
its associated blocks. Drag
over the green set
Label2.BackgroundColor and
insert it just above
the Sound1.Play block. Notice
that the when
Button1.Click block
automatically gets bigger to
accomodate the new block.
2. Clicking on the word
"BackgroundColor" will allow
you to change the property
that is being set. We want to
change the Text so our block will look like set Label2.Text .
Page 13
3. From the Built-In palette, click on the Lists drawer. Drag over the pick random
item block and connect it to the open socket of the set Label2.Text block.
4. From the Built-In palette, click on Lists again, then drag out the make a list block and plug it into the "list"
socket on the right side of the pick random item block.
5. From the Built-In palette, click on the Text drawer, drag out a " " block and connect it to the item socket of
the make a list block. Click directly on the space in the block. You can then type in text there. Think about
the sayings you want in your list of predictions for the Magic 8-Ball. Type the first prediction into this new
text block.
6. Notice after you plug in two text blocks, there are no more sockets to add more responses. To create more
sockets, you need to click the dark blue button on the block. Make a list is called a mutator block and thus
can be expanded or shrunk by clicking the blue button in the upper left corner.
7. Plug each text block into the pick random item block. (Ideas for
answers: http://en.wikipedia.org/wiki/Magic_8-Ball)
Blocks should look something like this:
Page 14
From the Sensors palette, drag over an AccelerometerSensor sensor component. Notice
that it automatically drops down to the Non-visible components area of the Viewer window. This is the only new
component you need, so go on over to the Blocks Editor to change your program.
BUILD: Blocks Editor
1. From the blocks drawer, click on AccelerometerSensor, then drag out the block for when
AccelerometerSensor.Shaking .
2. Disconnect all of the blocks from inside the Button1.Click block and move them inside
the AccelerometerSensor.Shaking block. NOTE: you can move whole sections of connected blocks by clicking
on the uppermost or leftmost block and dragging it. The connected blocks will come with it.
3. Delete the Button1.Click block to keep your work area tidy.
The blocks should look something like
this:
TEST: Phone/Emulator
Phone: When you shake the phone it
should show an answer and play a
sound.
Emulator: unfortunately, you can not
simulate shaking the phone when using
the emulator.
Package the App to Your Phone!
Your app would disappear if you were to disconnect your phone from the Blocks Editor. This is because the app
is still stored on the App Inventor server and not on your phone. Follow these instructions to package your app to
your phone or to make an ".apk" file that can be installed on any android phone. Or, if you want to make your app
even cooler, try the challenges below.
Make the image rotate when the phone is shaken or have several images that the app rotates through while the
phone is shaken. You could use this technique to make it look like the triangle piece inside the 8-ball window is
surfacing. You could also make different images for different predictions and display the correct image for each
prediction.
Make a similar app but for a different purpose. The phone could be used in place of dice or yahtzee letters. It
could simulate a coin toss or a random number or color generator for investigating probability.
Ask end users to add choices to the list of predictions.
Make the 8 Ball app a "server" so that anyone who sends a text to it will receive a text message prediction in
return.
Complete change the list to humorous choices (e.g. an app for teacher to use when a student has an excuse for
not doing homework), or for useful purposes like randomly selecting a name from amongst people in the class.
Page
15
9 - Weather App
This
app
uses
maps
from
the
Weather
Underground
and
weather.com.
All
together
it
shows
how
to
display
images
from
the
Internet,
take
pictures,
retrieve
images
from
the
gallery,
store
pictures
in
TinyDB,
resize
your
app
to
fit
any
device
and
more.
Watch
the
first
half
of
the
video
from
0:00
to
7:50
Part
1
Design
See
the
video
for
the
layout
of
the
controls
on
the
screen.
Part
2
Blocks
Page 16
10 Camera App
This
is
a
tutorial
for
an
app
that
shows
how
to
use
the
camera,
image
picker
and
TinyDB
with
App
Inventor.
Watch
part
two
of
the
video
from
7:50
to
end
Part
1
Design
Part
2
-
Blocks
Page 17
11 - Presidents Quiz
Step
1
The
app
preview
Step
2
Design
the
Interface
Add
an
Image
component
for
the
picture,
a
label
for
the
question,
and
a
Next
button.
There's
only
one
screen--
we'll
just
change
the
data
in
it.
Step
3:
Define
the
questions/pictures
and
program
the
Next
button
so
the
user
can
navigate
Create
lists
for
the
questions
and
pictures,
and
an
index
to
keep
track
of
your
place.
Then
program
the
NextButton.
Click
to
show
the
right
question
each
time.
Step
4:
Complete
the
navigation
code.
Complete
the
code
by
adding
an
if
block
that
checks
if
the
user
has
reached
the
end
of
the
list.
Page 18
step
5:
Let
the
user
answer,
then
check
it
Add
a
textbox
and
button
for
the
user's
answer,
then
use
an
if
block
to
check
whether
the
submitted
answer
is
correct
step
6:
Turn
the
quiz
into
multiple
choice
Add
a
ListPicker
component
and
code
it
so
the
user
chooses
an
answer
instead
of
typing
it.
step
7:
Change
it
so
there
are
different
answer
choices
for
each
question.
(click
for
details)
Add
an
AnswerChoices
list
which
is
a
list
of
lists,
where
each
sublist
is
the
answer
choices
for
that
question.
Page 19
Build It
step
2:
Build
a
simple
auto-
responder
When
a
text
comes
in,
send
a
text
back.
step
5:
Add
option
to
choose
whether
text
spoken
aloud.
Add
a
checkbox
Page 20
and
only
speak
text
aloud
if
it
is
checked.
Page 21
Page 22
To create this interface, put the following components into the Designer by dragging them
from the Component Palette into the Viewer.
Component
Type
Palette Group
Purpose of Component
Canvas
Drawing and
Animation
Canvas1
ImageSprite
Drawing and
Animation
PirateSprite
ImageSprite
Drawing and
Animation
ImageSprite2
ImageSprite
Drawing and
Animation
ImageSprite3
ImageSprite
Drawing and
Animation
ImageSprite4
ImageSprite
Drawing and
Animation
ImageSprite5
ImageSprite
Drawing and
Animation
ImageSprite6
Clock
User Interface
Clock1
Button
User Interface
ResetButton
Action
ResetButton
PirateSprite
ImageSprite(2,3,4,5,6)
Clock
Page 23
You may notice that PirateSprite.Flung takes in 6 attributes: x, y, xvel, yvel, speed, and
heading. We want to reassign PirateSprite's current heading to the heading given to us from PirateSprite.Flung.
This means that the user can now control the direction of the pirate ship with their fingers by flinging on the
screen.
To prevent the pirate from moving off the screen, we will also use PirateSprite.Bounce when an edge is reached.
Page 24
Detecting Collisions
App Inventor detects collisions by checking for an intersection between the bounding rectangles of each
ImageSprite. We call this rectangle-based collision detection. As you can see in the image below, sprites with
circular or polygon shape will appear to collide because of the rectangular bounds around them when they might
not actually be colliding.
We can use the PirateSprite.CollidedWith event handler to detect whenever the pirate ship collides with another
sprite or gold coin. You may notice that PirateSprite.CollidedWith takes in an argument. This argument is the object
that PirateSprite just collided with. We will be testing inside the handler for which object so the name of this
argument is not significant. You can name it other.
Whenever the pirate collides with a gold coin, we want the coin to disappear. We can do this by setting the coin's
visibility to false. To find which coin the pirate collided with, we will use the PirateSprite.CollidingWith .
We can use PirateSprite.CollidingWith to take in a component (each of the gold coin sprites) to detect which sprite
was hit. This is a component block and NOT a text block with the words ImageSprite inside. The component
block can be found in the drawer for each component. If a sprite was hit, we will set its visibility to false.
Page 25
Reset Button
After the user hits all of the gold sprites with the pirate ship, none of them will be visible. The reset button should
set all of the gold sprites' visibility to true.
Complete Program
Here's the complete GetTheGold program.
Page 26
Once you get this program running, you may want to do the following additional features to extend it. For
example,
Create a label to display the time that it took you to get all the gold
Change the speed of the ship or gold coins
Add an enemy sprite that when collided with, causes your pirate to lose speed
Use one of the phone's sensors to control movement of the pirate ship
Page 27
14 Pong
Build
the
classic
game
Pong
and
learn
how
to
animate
image
sprites,
deal
with
collisions,
keep
score,
and
define
procedures
to
make
your
code
better.
Build It
step
1:
Code
it
so
a
ball
moves
downward
(animated)
Add
blocks
so
that
clicking
on
the
start
button
enables
the
ball
and
sets
its
speed/heading
to
move
downward.
step
3:
Code
it
so
the
ball
bounces
off
edges
and
the
paddle
Program
the
ball.EdgeReached
event
and
use
the
Bounce
operation.
For
the
paddle,
program
CollidedWith
and
change
the
Heading.
Page 28
Paddle.Dragged
event
and
modify
only
the
X
property
of
the
paddle
step
5:
Code
it
so
you
get
a
point
every
time
the
paddle
hits
the
ball
Modify
the
ball.CollidedWith
to
modify
the
score.
Use
a
procedure
which
adds
one
to
the
score
and
updates
the
label
showing
the
score.
Be
sure
and
s
et
the
Score
to
0
at
proper
times.
Page 29
15 Space Invaders
Space Invaders
What You're Building
By building the Space Invaders App you will get practice with using Clock
components and Timers, using Animation components such as Image
Sprites and the Canvas, setting visibility, and detecting collisions in App
Inventor. You'll program an application that has a shooter ship whose goal
is to shoot all the flying saucers on the screen.
Getting Started
Connect to the App Inventor web site and start a new project. Name
it SpaceInvaders, and also set the screen's Title to "SpaceInvaders". Connect to a device or emulator.
Introduction
This tutorial introduces the following skills, useful for future game development:
Page 30
Component
Type
Canvas
Palette
Group
Drawing
and
Animation
ImageSprite
Drawing
and
Animation
RocketSprite
ImageSprite
Drawing
and
Animation
Drawing
and
Animation
User
Interface
SaucerSprite
Bullet
Clock1
Horizontal
Arrangement
Layout
HorizontalArrangement1
Label
User
Interface
User
Interface
Label1
User
Interface
ResetButton
BallSprite
Clock
Label
Button
Canvas1
ScoreLabel
Purpose of
Component
The background
that we will be
putting our
sprites on
The rocket ship
in our game
Action
Change Width property to "Fill parent"
and Height property to 300. Set
the BackgroundColor property to Black.
Now that you have all the essential properties configured, feel free to change the colors of any components that
you want to.
Page 31
Next, we want to make sure that the bullet appears again when we
shoot from the rocket. When we touch the rocket, we want the bullet
to start heading towards the saucer. We will do this by using
the RocketSprite.Touched event handler. When the rocket is touched,
we not only want to set the rocket to be visible, but we also want to
set the speed and heading of the rocket. Heading is a value from 0 to
360 that indicates what direction the sprite should be moving towards. 0/360 is to the left, 90 is up, 180 is right,
and 270 is down. The speed is measured in pixels/sec.
The last thing we need to
program is what happens
when the bullet hits the
saucer. We will use
the Bullet.CollidedWith event
handler. This event is called
whenever the bullet collides
with another sprite. Since our rocket sprite is locked into a Y at the bottom of the screen, the bullet will never
collide with the rocket and only with the saucer. On collision we want two things to happen. 1. The score should
increase by 1. 2. The bullet should become invisible.
Page 32
back to 0.
Complete Program
Here's the complete SpaceInvaders program.
Page 33
16 - Mini Golf
Fling, TouchUp, TouchDown Gestures for
sprites. This is a text tutorial, rather than
video.
To play this mini golf app, the player first positions his/her ball within
the confines of the tee, and then flings the ball toward the hole. The
ball will bounce off of the rectangular obstacle and the sides of the
course. For each fling of the ball, the stroke count goes up by one.
The total score is the number of strokes it takes to complete the
entire course.
This tutorial covers:
Page 34
Component
Type
Canvas
Palette
Group
Drawing
and
Animation
Ball
Drawing
and
Animation
Ball
Drawing
and
Animation
Clock
User
Interface
What
You'll
Name It
Purpose
Properties
Height: 300
Width: FillParent
BackgroundColor:
Green (or whatever you
like!)
GolfBall
Radius = 10
Color: White (or your
choice!)
Speed: 0
Interval: 1 (ms)
Z = 2 (when sprites are
overlapping, the one
with the higher z will
appear on top)
Hole
Radius = 15
Color: Black
Speed: 0
Clock1
Canvas1
Page 35
Program the behavior of the clock:
Use timer event to slow ball down so it doesnt bounce around forever.
Each time the clock fires, it will reduce the speed of the ball slightly. Notice that if the ball is not moving then
these blocks will do nothing. If you dont have this then the ball will just bounce forever.
You'll need to use the if mutator function to change the if block into an if-else block. For a summary of mutators,
check out the Mutators page
Program the Behavior of the Hole: When the ball collides with the hole, the ball disappears and resets at the
bottom of the screen.
Note: When you first drag out the GolfBall.CollidedWith event handler, the named parameter is called "other".
Notice that the if then block tests to see if the object involved in the collision with the golf ball ( other ) is the black
ball sprite representing the hole. You can't just put a text block with the word "Hole" in it, you must use
the Hole block, that can be found in the drawer for the Hole image sprite. Do not use a text block here.
Test this Behavior. Connect your device to AppInventor, or start the emulator to load your app. When you fling
the ball it should move in the direction of your fling, with a speed similar to the strength of your fling. The ball
should slow down as it moves, eventually stopping. When the ball hits the hole, the ball should reset at the bottom
of the screen and the hole should move to a new random location.
Page 36
Does your ball get stuck if it hits the edge?
This is easy to fix with the when EdgeReached event. Note that you can
find the "edge" value block by using a get block and selecting "edge"
from the dropdown.
Double check to make sure your code is right: fling the ball a few times
and see that that ball now bounces off the edges of the course.
Component Type
Palette
Group
Purpose
Properties
Horizontal
Arrangement
Layout
HorizontalArrangeme
nt1
Place at top
of screen
Label
User
Interface
LabelScore
Label
User
Interface
LabelStroke
In the Blocks Editor, you can program updates to the Score and Stroke labels. First, set two new global variables
called StrokeCount and Score , and set their initial values to 0.
Then add the following blocks to the GolfBall.Flung event (red rectangle indicates new blocks):
Page 37
Next add the following blocks to the Event that handles the ball hitting the hole:
Test the behavior. With these new changes, you should have a "Total
Strokes" count and "This Hole" count at the top of the screen. When you fling
the ball, the "This Hole" count and "Total Strokes" count should both
increase by one, and when you make the ball go into the hole the "This Hole"
count should reset to 0.
ImageSprite
Palette Group
What Youll
Name It
Purpose
Properties
Tee
A rectangular area in
which the player can
position their ball before
teeing off.
Page 38
ImageSprite
ImageSprite
LeftSprite
RightSprite
Upload the
right arrow
graphic
Program the size of the canvas, and the placement of the ball and image sprites on the canvas:
First, program the setup of these components on the screen. Its best to accommodate all different screen sizes
by placing the sprites on the screen relative to the size of the screen. The blocks below show how to set up the
screen dynamically so that everything fits the right way. We start off by making the canvas size based on the
screen size, and then we place each sprite in relation to the width and height of the canvas. We'll make a
procedure to do this for us. Try to understand all of these blocks before you move on.
Position the Golf Ball on the Tee using TouchUp and TouchDown on the Arrow sprites:
To handle this, first set up two global variables that are toggled each time an arrow is pressed.
Page 39
The left and right arrows are image sprites, so they come equipped with the ability to
know when the player is is holding his/her finger down on them. The following blocks toggle the global variables
based on whether the user is pressing either of these arrows.
Procedure MoveBallOnTee:
Make a new procedure moveBallOnTee that makes the golf ball move left or right on the tee depending on the
global variables. Although the math here looks complicated, its pretty simple. If the ball is supposed to move left,
you first check to make sure that moving the ball 2 pixels left will not exceed the left-most coordinate of the Tee.
If moving the golf ball to the right, you first check that moving the ball right 2 pixels will not move it past the rightmost coordinate of the Tee.
Note: if blocks look different in this image than on your own screen, this is because they were aligned differently. If
you right click on the blocks, a list of options will appear and one of them is external inputs. When you select this,
it will change how the blocks are configured. It does not change how the blocks function. If you want to change
this, right click again and select internal inputs.
Page 40
MoveBallOnCourse Procedure
Note that the blocks that we had inside the Clock1.Timer event are now moved over to a new procedure
called moveBallOnCourse:
On each new course, players can position the ball on the tee before
attempting to fling the ball toward the hole. To program this, you first have
to check to make sure this is a new course and the ball has not been
flung yet. If StrokeCount = 0 then we know this course is brand new and
the player has not yet attempted to get the ball into the hole.
As the blocks above show, after verifying that the StrokeCount is 0, you
then want to proceed to move the golf ball left or right depending on
which arrow is being pressed.
Test the behavior. Make sure your app is doing what you expect: play
the game on your device or emulator. Before you tee off, are you able to
move the ball left and right on the tee by using the left and right arrows? After you tee off, you should no longer be
able to use the left and right arrows (pressing them will do nothing). After the ball goes into the hole and the screen
resets, you should then be able to move the ball left and right on the tee before teeing off again.
Keep track of the number of holes played, and allow a game reset
The game is working pretty well now, but what about giving the player a way to reset the game? Also, it would be
nice to give the player some instructions so they know how to play the game. While were at it, lets also give an
indication of how many holes the player has completed. Add the following components in the Designer:
Component
Type
Palette
Group
What Youll
Name It
Purpose
Horizontal
Arrangement
Layout
Horizontal
Arrangement2
Button
User
ButtonNewGame
Properties
Page 41
Label
Label
Interface
with a score of 0.
User
Interface
Displays instructions
User
Interface
LabelHoleNum
LabelInstruct
Program the
"New Game"
buttons behavior,
which is pretty
simple. When the button is pressed, set up a new course and reset both
the hole stroke counter and total stroke counter to zero. Also set the
hole number back to 1, by displaying "Hole #1" in LabelHoleNum. The
blocks look like this:
Page 42
Test the behavior.
Go back to your device or emulator and play the game some more. Now you should see the Hole # displayed in the
lower right. Hitting "New Game" button should reset the game, returning both scores to 0, resetting the screen, and
setting the Hole number to #1.
ImageSprite
Palette
Group
Drawing and
Animation
What Youll
Name It
Purpose
Properties
ObstacleSprite1
Program the behavior of the obstacle in the blocks editor. First, set the behavior for when the ball hits the
obstacle. *Note: Using Heading = 0 - heading works because we are dealing with bouncing off of horizonal
surfaces, this will not work for bouncing off of vertical or inclined surfaces. For our purposes, it works all right.
See Challenge #2 below for more information.
Each time the course is reset, position the obstacle will be positioned randomly. Add these blocks to
the setupNewHole procedure:
Page 43
Test the behavior. Play the game again. Notice that the ball bounces off when it hits the
obstacle. When the ball goes into the hole, or when the New Game button is pressed, the obstacle appears in a new
location somewhere between the tee and the hole.
Thats it! Share your game with friends by building an APK or by downloading the source and sharing the zip file
with other App Inventors!
Part V: Challenges
Here are some extra challenges to make your game better.
Challenge 1: Program the Ball to Hole collision so that the ball only goes into the hole if the golf balls speed is
not too fast. In real mini golf, the ball will bounce right over the hole if you hit the ball too hard.
Challenge 2: There is a slight bug when the ball hits the vertical sides of obstacle. Figure out how to program the
ball to obstacle collision so that it bounces the way you would expect when the ball hits the vertical sides.
Challenge 3: Limit the number of holes per game. Keep track of the number of holes and end the game after a
set number. (A typical mini golf course has 18 holes.)
Below is a summary of all of the components:
Page 44
17 Stock Market
The
Stock
Market
app
displays
the
current
price
of
any
stock
you
enter.
You'll
learn
how
to
web-enable
your
app
and
communicate
with
Web
APIs,
in
this
case
Yahoo
Finance
Build It
Follow
the
video
steps
to
build
the
app
yourself.
step 1:
Create
an
app
that
shows
current
Google
stock
price
Use
the
Web
component,
call
Web.Get,
and
then
process
the
response
in
Web.GotText
step
2:
Parse
the
returned
data
to
show
only
the
price
Put
the
returned
data
into
a
list,
then
extract
the
first
item
only
step
3:
Change
the
app
so
that
the
user
can
enter
any
stock
symbol
Add
a
Textbox
then
build
the
API
call
by
joining
the
fixed
part
with
the
user's
entry
Page 45
Build
It
Follow
the
video
steps
below
to
build
the
app
yourself.
step
2:
Professor
Wolber
introduces
the
Logo
Challenge
Learn
about
the
app
and
how
to
get
started.
Page
46
19 Voice Recorder
In
this
tutorial
we
make
an
Android
Beat
Box
App.
It
could
also
be
converted
into
a
voice
note
app,
or
anything
else
that
would
benefit
from
being
able
to
record
and
later
play
back
sounds.
Ill
specifically
cover
how
to
use
the
Android
SoundRecorder,
Player,
take
another
look
at
using
list,
teach
more
about
logic
and
incremental
programming.
All
of
the
blocks
used
can
be
found
below.
The
answer
for
the
Reset
Button
homework
is
also
down
there.
Watch
the
video
to
see
the
design
view
(buttons
and
other
controls).
Page 47
20 Contact Database
Through
making
this
app
I
will
cover
most
everything
about
using
Lists,
List
Pickers,
TinyDB,
TinyWebDB,
Fusion
Tables,
and
Texting.
I
start
off
simply
here
by
focusing
on
creating
Lists
through
an
interface.
Part
1
Screen
Design
Page 48
Part
2
Blocks
Page
49
21 - Chat App
In
this
part
of
my
App
Inventor
tutorial,
I
will
provide
an
App
Inventor
TinyWebDB
Example.
It
will
allow
you
to
chat
with
anyone
who
also
has
the
app.
TinyWebDB
is
one
of
several
methods
for
saving
data
on
a
server
which
allows
apps
to
communicate
with
each
other.
Part
1
Display
Page 50
Part
2
Blocks
Page 51
Page 52
3.
You will be given a few different options for
the new table. Select Create an empty table.
4. You will see that the new table automatically comes with four columns. Change the
column names for your Pizza app by going to Edit > Change Columns.You'll rename the
four default columns
to Date (type=Date), Name (type=Text), Pizza (type=Text), Drink (type=Text). Click save and
then add a fifth column by going to the Edit > Add Column. Name this fifth
column Comment (type=Text). .
5. Leave this window open so that you can come back and get the URL, which you'll need
when you set up the properties of the WebViewer component in your app.
6.
Click on the Share button (top right) to modify the table's permissions. For this
tutorial, you can specify a few friends who will use the app. Only people who are explicitly
given permission will be able to enter pizza party preferences through your app.
NOTE about Sharing
Fusion Tables: To share a
FusionTable with others, you
have to share it with each
person individually, or you
can share with a Google
Group the same way you
would share a private google
doc. There is no way to
let all the app users know how to join the group (maybe
through the web page for your app). From the moment
you create your app, you share the Fusion Table once
with your Google Group (using its email address), and
make sure to give to the group editing rights. Every user
who joins the group will inherit the editing rights automatically.
Page 53
Getting an API Key
In order to use the FusiontablesControl Component you need to acquire a Google Applications Programming
Interface (API) key, an API Key. To get an API key, follow these instructions:
Page 54
Component Type
Palette
Group
What you'll
name it
Purpose of
Component
Label
User
Interface
LabelName
TextBox
User
Interface
TextBoxUserNa
me
HorizontalArrang
ement1
Contains Name
Label and
Textbox
HorizontalArrangem
ent
ListPicker
Layout
User
Interface
ListPickerPizza
Settings of
Component
Page 55
Anchovies, Hawaiian"
Set the Width
property to Fill Parent
ListPickerDrink
Label
User
Interface
LabelComment
TextBox
User
Interface
TextBoxComme
nts
ListPicker
User
Interface
Contains
HorizontalArrangem
ent
Button
WebViewer
Layout
User
Interface
User
Interface
HorizontalArrang
ement2
Comments Label
and Textbox
ButtonSubmit
Displays Fusion
Table
WebViewer1
Manages
interactions with
FusiontablesControl
Storage
Clock
User
Interface
Notifier
User
Interface
FusiontablesCon
trol1
Clock1
Used to provide
a timestamp
each time an
order is placed.
Notifier1
Page 56
1. In your browser, navigate to the new Fusion Table you just created.
2. Go to the menu and select Tools > Publish.
3. You'll see a notice saying: "This table is private and will not be visible". Click the blue link
that says "Change Visibility".
4. In the list of "Who Has Access", click the blue "Change..." link next to "Private - Only
people listed below..."
5. Choose "Public on the Web" or "Anyone with the link". Either of these
settings will work for this tutorial. In the future, you should decide this
setting based on the sensitivity of your
data.
6. Click the Save button, then the Done
button.
7. Back on the Fusion Table page, go to
the menu bar and select Tools >
Publish. Select the URL from the top text box (labeled "Send in an email or IM"), copy
the URL and return to App Inventor. You will paste the URL into the definition block for the
TABLE_URL (see below).
8. You can find the Table ID by browsing to your table, then selecting File>About this
table in the menu.
Blocks Editor
Open the Blocks Editor so you can program the app's behavior. First, you will describe the app's variables.
Variables whose names are ALL_CAPS are constants -- that is, variables whose values do not change while the
program is running. It is good to get into the habit of using this naming convention. Define the following variables
and give them the initial values shown in the table.
Block type
Drawer
Purpose
Variables
Variables
Variables
Initialize this global variable to your own API Key for Google
Fusion Tables. See instructions above.
initialize global
TABLE_URL
initialize global
TABLE_ID
initialize global
API_KEY
Page 57
initialize global
UserName
Variables
Variables
Stores the pizza choice input by the user. (Starts off as an empty
text string.)
Variables
Stores the drink choice input by the user. (Starts off as an empty
text string.)
Variables
initialize global
pizza
initialize global
drink
initialize global
comment
Set up the resetForm procedure as shown below. After recording an entry, this procedure resets the interface
back to the original state.
Page 58
List Picker Blocks
In the designer, you set the choices for the pizza and drink types by filling in the "Selection" property with comma
separated lists. These pre-programmed choices will be displayed on the user interface so the user can select
their food and drink. Their selections are stored in the pizza and drink variables.
Submitting Data
Once the user has entered their name, food choices, and comments, they will click the Submit button. The app
tests to make sure that the name, pizza, and drink fields have values in them (not blank), and prompts the user to
try again if any of the required answers are missing. Notice that the compare texts = block is used (find it under
Built-in palette, Text drawer). This block compares two strings of text to see if they are equal. If all required
information is present, it calls the procedure InsertDataInTable (see below). The blocks for
the ButtonSubmit.Click are shown here:
The
FusiontablesControl
component
is
used
to
send
the
data
to
the
Fusion
Table.
This
action
will
create
a
new
row
in
the
Fusion
Table,
setting
the
values
of
the
various
columns
involved.
App
Inventor
makes
this
easy
to
do,
but
you
have
to
be
careful
that
the
insert
query
is
formatted
correctly.
This
procedure
involves
two
steps:
(1)
constructing
the
insert
query
and
then
(2)
sending
the
query
to
Google's
Fusion
Table
service.
The
query
we
want
to
send
will
take
this
format:
INSERT INTO (,
,
...)
VALUES
(,
,
...)
The
words
in
CAPS
are
part
of
the
query's
syntax.
The
words
in
parentheses
are
values
that
we
need
to
plug
in.
First
there
is
a
list
of
(column
names)
followed
by
VALUES
followed
by
a
list
of
(value
names).
The
order
of
the
column
names
and
value
names
must
be
in
the
same
order
so
that
Page 59
they
match
up.
An
example
of
what
this
might
look
like
is
shown
below.
Notice
that
the
values
must
be
enclosed
in
single
quotes:
To construct the query we use App Inventor's join text block. Be sure to PUT SPACES where needed, such as before and
after the words INSERT INTO and VALUES:
Page 60
Did
you
remember
to
put
a
space
after
the
word
INTO
and
before
and
after
the
word
VALUES?
For
this
app,
the
column
names
must
match
the
column
names
of
the
table
we
created
earlier
(with
columns
Date,
Name,
Pizza,
Drink,
Comment).
Their
respective
values
are
taken
from
the
procedure's
global
variables.
Note:
If
you
did
not
use
these
exact
words
for
your
table's
columns,
then
be
sure
to
use
your
table's
column
names
when
you
build
your
query.
Don't
forget
the
FusiontablesControl.SendQuery
command
at
the
very
end
of
this
procedure.
It's
small
in
size
compared
to
rest
of
the
procedure,
but
very
important.
A
note
about
Invalid
Query/Parse
Error
Messages
There
are
a
few
different
reasons
your
app
may
get
a
response
from
Fusion
Tables
that
gives
an
Error
related
to
Parsing
or
Invalid
Query.
This
could
be
because
you
are
missing
spaces
in
the
query
string
or
have
not
handled
single
quotes
(see
quotify
procedure
above).
It
may
also
be
that
you
have
used
one
of
the
Fusion
Table
RESERVED
WORDS
as
a
column
name
(More
info
about
reserved
words)
Handling the Response from the Fusion Tables Service
The
FusiontablesControl.GotResult
event
will
be
fired
when
the
app
receives
a
response
from
Google's
Fusion
Tables
Service.
For
an
insert
query
the
service
will
return
the
rowID
of
the
new
row
that
was
inserted
or
an
error
message
if
something
went
wrong.
In
this
simple
example,
we
use
the
"contains"
block
(
(find
it
under
Built-in
palette,
Text
drawer)
to
check
whether
the
result
string
has
the
rowID
in
it.
If
so,
then
we
know
that
the
rowID
was
received,
and
we
then
invoke
the
WebViewer.GoHome
procedure,
which
reloads
the
"HomeURL"
as
specified
in
the
WebViewer's
properties.
Note
that
this
set
of
blocks
also
calls
the
resetForm
procedure.
After
recording
an
entry,
it
resets
the
interface
back
to
the
original
state.
You're
done!
Package
the
app
by
going
to
Package
for
Phone
on
the
Designer.
You
can
now
test
the
App
for
the
purposes
of
the
pizza
party.
Once
you
understand
this
tutorial,
you'll
be
ready
to
make
new
Fusion
Tables
and
modify
the
app
to
collect
different
types
data
from
users.
Remember,
you
have
to
give
each
user
permission
to
access
the
Fusion
Table.
You
do
this
through
the
Google
Page 61
Fusion
Tables
interface,
not
through
App
Inventor.
Luckily,
this
means
you
don't
have
to
change
the
app
in
order
to
add
more
users
who
can
access
the
table.
Challenges
This app has the Fusion Table hard-coded into the blocks. Find a way to let users specify their own fusion table ID so that they
can host their own Pizza Party.
Variations
Now that you have a simple app that uses fusion tables and a webviewer working, you might want to build some other apps
with Fusion Tables. For example:
Include
a
LocationSensor
so
that
the
user's
location
can
be
added
to
the
Fusion
Table
to
create
a
map
with
notes
Make
the
WebViewer
display
something
other
than
the
table
of
stored
values;
perhaps
a
map
or
a
chart
Troubleshooting
If you are using a Google Apps for Education account, and you are not able to create a new fusion table (in the "Create" menu
of Google Drive you won't even see an option for Fusion Tables), you will need to ask your system administrator to turn this
option on for you. Or, you can switch to a standard gmail account. Fusion Tables are not automatically turned on for Google
Apps for Education Accounts, your system administrator must make Fusion Tables available to the accounts in your domain.
If you are receiving errors when trying to submit to the Fusion Table, especially if the error mentions Authentication, be sure
that you have put the correct API Key into the API Key property field on the FusionTables component in the Design Window.
To familiarize yourself with fusion tables, have a look around the Fusion Tables Web Site.
http://support.google.com/fusiontables/bin/answer.py?hl=en&answer=2571232 Check out the example
gallery to see what kinds of things are possible. Work through this Fusion Table tutorial
http://earth.google.com/outreach/tutorial_fusion_sample.html , which shows how import some data, create a
Fusion Table, and view the data on a map with your browser. You'll need to log in with your Google account.
NOTE about Sharing: To share a FusionTable with many people, rather than by entering email addresses individually, you
can create a dedicated Google Group for your app and let all the app users know how to join the group (maybe through
the web page for your app). From the moment you create your app, you share the Fusion Table once with your Google Group
(using its email address), and make sure to give to the group editing rights. Every user who joins the group will inherit the
editing rights automatically.
Page 62
23 - Advanced
Weather App
Mostly
sunny
with
a
high
near
40
Page 63
Page 64
Page 65
Page 66
Page
67
24 - Wheres My Car?
You parked somewhere near the stadium, but when the concert ends you don't have
a clue where the car is. The friends you came with are equally as clueless.
Fortunately you haven't lost your Android phone that never forgets anything, and you
remember you have the hot new app, Android, Where's My Car?. With this app, you
click a button when you park your car, and the Android uses its location sensor to
record the car's GPS coordinates and address. Later, when you reopen the app, it
shows you a map from where you are to the remembered location-- problem solved!
Getting Started
The app demonstrates how to communicate with the Android location sensor, how to record data in the phone's
long-term memory (database), and how you can open the Google Maps app from your app to show directions
from one one location to another. It makes use of the following App Inventor components:
Location Sensor
TinyDB -- to store the data
ActivityStarter -- to open a map
The User Interface
Here are the components for the Android, Where's My Car? app, as shown in the Component Designer:
Page 68
The user interface consists of labels to show location data and buttons to initiate events.
Some labels just show static text, e.g., GPSLabel is the text "GPS:" that appears in the user interface. Others,
such as CurrentLatLabel, will display dynamic data one the location sensor gets its readings. For these labels, a
default value is set (0) here in the Component Designer.
The ActivityStarter1 component is used to launch the map when the user asks for directions. Its properties are
only partially shown above. Here is how they should be specified:
Property
Value
Action
android.intent.action.VIEW
ActivityClass
com.google.android.maps.MapsActivity
ActivityPackage
com.google.android.apps.maps
Page 69
Let's examine the four different event-handlers of the app, starting in the top-left and working around in counterclockwise order.
LocationSensor1.LocationChanged : This event occurs when the phone's location sensor first gets a reading, or
when the phone is moved to produce a new reading. The event-handler just places the readings--latitude,
longitude, and current (street) address-- into the corresponding "Current" labels so that they appear on the
phone. The RememberButton is also enabled in this event-handler. Its enabled setting should be unchecked in
the Component Designer because there is nothing for the user to remember until the sensor gets a reading.
RememberButton.Click : When the user clicks the RememberButton , the location sensor's current readings are put
into the "remember" labels and stored to the database as well. The DirectionsButton is enabled as it now makes
sense for the user click on it to see a map (though it will make more sense once the user changes location).
DirectionsButton.Click : When the user clicks the DirectionsButton , the event-handler builds a URL for a map and
calls ActivityStarter to launch the Maps application and load the map. join is used to build the URL to send to the
Maps application. The resulting URL consists of the Maps domain along with two crucial parameters, saddr and
daddr , which specify the start and destination for the directions. For this app, the saddr is set to the latitude and
longitude of the current location, and the daddr is set to the latitude and longitude of the location that was
"remembered" (the location of your car!).
Screen1.Initialize : This event is always triggered when an app opens. To understand it, you have to envision the
user recording the location of the car, then closing the app, then later re-opening the app. When the app reopens, the user expects that the location remembered earlier should appear on the phone. To facilitate this, the
event-handler queries the database ( call TinyDB.GetValue ). If there is indeed a remembered address stored in the
Page 70
database-- the length of the stored address is greater than zero--the remembered
latitude, longitude, and street addres are placed in the corresponding labels.
Variations
Create "Android, Where is Everyone?", an app that lets a group of people track each other's
whereabouts. Whether your hiking or at the park, this app could help save time and even lives.
Create a "breadcrumb" app that tracks your (phone's) whereabouts by recording each location
change. One interesting refinement would be to only record a new "breadcrumb" if the
location has changed by a certain amount.
Review
Here are some of the ideas covered in this tutorial:
The LocationSensor component can report the phone's latitude, longitude, and current street
address. Its LocationChanged event is triggered when sensor gets its first reading and when
the reading changes (the phone has moved).
The ActivityStarter component can launch any app including Google Maps. For Maps, you
set the DataUri property to the URL of the map you want to display. If you want to show
directions, the URL will be of the
form: http://maps.google.com/maps/?saddr=0.1,0.1&daddr=0.2,0.2, where the numbers are
GPS coordinates.
join is used to piece together (concatenate) separate text items into a single text object. It
allows you to concatenate dynamic data with static text. With the Maps URL, the GPS
coordinates are the dynamic data.
TinyDB allows you to store data persistently in the phone's database. Whereas the data in a
variable or property is lost when an app closes, the data you store in the database can be
loaded into your app each time it is opened.
Page 71
25 - Map Locations
Map
It:
Displaying
Locations
on
a
Google
Map
This tutorial shows how you can develop an app
that allows you to record list of addresses and
view the address on the Google Maps. It will
also show you how view your current location
on the Google Map. This tutorial assumes you
have completed the basic tutorials of App
Inventor.
The figure below shows how the components are arranged in the
design editor. It also shows you the non-visible components (e.g.
TinyDb, ActivityStarter, LocationSensor, Notifier) that are used in the
app.
Page 72
Blocks
We define 2 global variables.
tagAddress a variable
that is a constant and
will be used, as a tag, for
storing and retrieving
data from our database.
listLocations a variable
that can be used to store
and manipulate list of
addresses.
We now create a procedure
that can be invoked when the
app is started (initialized). The
procedure sets up the initial
state of some of the
Page 73
components. Some of these settings could have been done from the design editor, but for
demo purpose and clarification, we are using a procedure. In the procedure, we also check our database to find
out if there are any stored addresses. If no data, then we just use an empty list.
When AddLocationButton is clicked, we make our address data entry visible (using screen arrangement), allowing
user to enter address. If user clicks on Cancel, we make the arrangement hidden again. Using this approach, we
keep the screen simple and avoid the clutter. We also provide the SubmitButton to allow the user to indicate that
they want to store data.
When the user clicks on SubmitButton, we perform basic validation to ensure data has been submitted. If
validation does not pass, we display an error message. Otherwise, we invoke a procedure that appends the new
address to our list. We also store the updated list into our database. Once address is added, we hide our
arrangement again. The blocks below show how this logic is done:
Page 74
Selecting an Addresses
When the user clicks on
ListPicker1 Select Location
and selects an address, this
action calls the blocks below:
Page 75
The above blocks will open the map and the output will be like image below:
Page 76
26 - Friend Locator
In
this
activity
you
design
your
own
app.
Build
an
app
that
stores
the
GPS
location
of
you
and
your
group
of
friends
in
an
online
database.
Update
every
5
minutes.
Your
app
reads
the
location
of
other
friends
who
use
the
app.
An
icon
appears
on
a
Google
Maps
screen
to
show
their
location.
Use
the
techniques
in
assignments
21
(chat
app),
24
(Wheres
my
car?)
and
25
(Map
Locations)
to
complete
this
assignment.
Online
database
(FusionTable)
to
store
GPS
coordinates,
name
and
time.
Report
your
GPS
location
Read
GPS
locations
for
people
in
your
group.
Page 77