Designer and Blocks Editor - Lab5
Designer and Blocks Editor - Lab5
Introduction:
This unit walks you through the creation of No Texting While Driving, a “text
answering machine” app that auto-responds to text messages you receive while you’re
driving (or in the office, etc.), speaks text messages aloud, and even sends location
information as part of the automated text reply. The app demonstrates how you can
control some of the great features of an Android phone, including SMS texting, text-to-
speech, persistent data, and GPS location sensing.
1. The Texting component for sending texts and processing received texts.
2. An input form for submitting the custom response message.
3. The TinyDB database component for saving the customized message even after
the app is closed.
4. The Screen.Initialize event for loading the custom response when the app
launches.
5. The TextToSpeech component for speaking texts aloud.
6. The LocationSensor component for reporting the driver’s current location.
Materials
The user interface for the app is relatively simple: it has a label instructing the user
how the app works, a label that displays the text that is to be automatically sent in
response to incoming texts, a text box for changing the response, and a button for
submitting the change. You’ll also need to drag in a Texting component, a TinyDB
component, a TextToSpeech component, and a LocationSensor component, all of which
will appear in the “Non-visible components” area.
1) Auto-response to a Text
Next, let’s add blocks so the user can enter her own custom response. In
the Component Designer, you added a TextBox component named
NewResponseTextbox; this is where the user will type the custom response. When
the user clicks on the SubmitResponseButton, you need to copy the entry
(NewResponseTextbox) into the ResponseLabel, which is used to respond to
texts.
Your user can now customize the auto-response, but there is one catch: if the user
enters a custom response and then closes the app and relaunches it, the custom
response will not appear (instead, the default response will). This behavior is not what
your users will expect; they’ll want to see the custom response they entered when they
restart the app. To make this happen, you need to store that custom response
persistently. Placing data in the ResponseLabel.Text property is technically storing it, but
the issue is that data stored in component properties is transient data. Transient data is
like your short-term memory; the phone “forgets” it as soon as an app close. If you want
your app to remember something persistently, you have to transfer it from short-term
memory (a component property or variable) to long-term memory. To store data
persistently in App Inventor, you use the TinyDB component, which stores data in a table
on the Android device. TinyDB provides two functions: StoreValue and GetValue. With
1) Store data to the database each time the user submits a new value.
2) When the app launches, load the data from the database into a variable or
property.
The reason for storing the custom response in the database is so that it can be
loaded back into the app the next time the user opens it. App Inventor provides a special
event block that is triggered when the app opens: Screen1.Initialize. If you drag this event
block out and place blocks in it, those blocks will be executed immediately when the app
launches. For this app, your Screen1.Initialize event handler will load the custom
response from the database by using the TinyDB.GetValue function.
In this section, you’ll modify the app so that when you receive a text, the sender’s
phone number, along with the message, is spoken aloud. The idea here is that when
you’re driving and hear a text come in, you might be tempted to check the text even if you
know the app is sending an auto-response. With text-to-speech, you can hear the
incoming texts and keep your hands on the wheel. Android devices provide text-to-speech
capabilities, and App Inventor provides a component, TextToSpeech, that will speak any
text you give it. Note that the “Text” in TextToSpeech refers to a sequence of letters,
digits, and punctuation, not an SMS text. The TextToSpeech component is very simple
For the No Texting While Driving app, you’ll need to provide a more complicated
message to be spoken, one that includes both the text received and the phone number
of the person who sent it. Instead of plugging in a static text object such as the “Hello
World” text block, you’ll plug in a join block. A commonly used function, join, makes it
possible for you to combine separate pieces of text (or numbers and other characters)
into a single text object.
Check-In apps help people track one another’s location. There are major privacy
concerns with such apps, one reason being that location tracking kindles people’s fear of
a “Big Brother” apparatus that a totalitarian government might set up to track its citizens’
whereabouts. But apps that use location information can be quite useful. Think of a lost
child, or hikers who’ve gone on the trail in the woods. In the No Texting While Driving app,
you can use location tracking to convey a bit more information in the auto-response to
incoming texts. Instead of just “I’m driving,” the response message can be something like,
“I’m driving and I’m currently at 3413 Cherry Avenue.” For someone awaiting the arrival
of a friend or family member, this extra information can be helpful. App Inventor provides
the LocationSensor component for interfacing with the phone’s GPS (or Global
Positioning System). Besides latitude and longitude information, the LocationSensor can
also tap into Google Maps to provide the driver’s currrent street address. It’s important to
note that LocationSensor doesn’t always have a reading. For this reason, you need to
take care to use the component properly. Speci„ cally, your app should respond to the
LocationSensor.LocationChanged event handler. A Location.Changed event occurs
when the phone’s location sensor first gets a reading, and when the phone is moved to
generate a new reading.
• Texting
• TinyDB
• Location Sensor
• Text To Speech
Instructions: