Presentation is loading. Please wait.

Presentation is loading. Please wait.

No Texting While Driving. Introduction You'll design the app so that it sends a response to any text message received. You'll also allow the user to customize.

Similar presentations


Presentation on theme: "No Texting While Driving. Introduction You'll design the app so that it sends a response to any text message received. You'll also allow the user to customize."— Presentation transcript:

1 No Texting While Driving

2 Introduction You'll design the app so that it sends a response to any text message received. You'll also allow the user to customize the response sent. This Lessson introduces the following App Inventor concepts: The Texting component for sending texts and processing received texts. The TinyDB database component for saving the customized message even after the app is closed.

3 Set up the Components

4 Component TypePalette GroupWhat you'll name itPurpose of Component LabelBasicPromptLabel Let the user know how the app works TextBoxBasicMessageTextbox User will enter custom response here. Button Basic SubmitResponseButton User clicks this to submit response TextingSocialTexting1 The component that processes the texts TinyDBBasicTinyDB1 The component that will store the response in the database Set the properties of the components in the following way: Set the Text of PromptLabel to "The text below will be sent in response to all texts while this app is running." Set the Text of MessageTextbox to "I'm driving right now, I'll contact you shortly". Set the Text of SubmitResponseButton to "Modify Response".

5 Add behaviors to the components When a text is received, the message entered in MessageTextbox is sent as a text message response to the sender. When the user modifies the custom message in MessageTextbox and clicks the SubmitResponseButton, the new message is saved persisently in the phone's database. When the app begins, the custom message is loaded from the database into MessageTextbox.

6 Responding to a text When a text message is received by the phone, the Texting.MessageReceived event is triggered. Your app should handle this event by setting the PhoneNumberand Message properties of the Texting component appropriately and sending the response text.

7 U will need the following blocks: Block TypeDrawerPurpose Texting1.MessageReceivedTexting1 the event-handler that is triggered when phone received a text set Texting1.PhoneNumber to Texting1 set the PhoneNumber property before sending value numberMy Definitions this is the phone number of the person who sent the text set Texting1.Message to Texting1 set the Message property before sending MessageText.TextMessageTextThis is the message the user has entered. Texting1.SendMessage Texting send the message

8 The blocks will look like this:

9 Storing the custom response TinyDB provides two blocks: StoreValue and GetValue. The former allows you to store a tagged piece of information, while the latter let's you retrieve one.

10 You'll need the following blocks to store the custom message: Block TypeDrawerPurpose SubmitResponseButton.ClickSubmitResponseButton user clicks this button to submit new response message TinyDB1.StoreValue TinyDB1 store the custom message in the phone's database text ("responseMessage")Text use this as the tag for the data MessageTextbox.TextMessageTextbox the response message entered by the user is here

11

12 Retrieving the saved response message Block TypeDrawerPurpose def variable ("response") Definitions A temporary variable to hold the retrieved data text (blank)TextInitial value for the variable can be anything Screen1.InitializeScreen1This is triggered when app begins set response toMy Definitionsyou'll set the variable to the value retrieved from db TinyDB1.GetValueTinyDB1get the stored response text from the database text ("responseMessage")Text plug into tag slot of GetValue, make sure text is same as was used in StoreValue above if testControlto ask if the retrieved value has some text > blockMathcheck if length of retrieved value is greater than (>) 0 length textTextcheck if length of retrieved value is greater than 0 global responseMy Definitionsthis variable holds the value retrieved from GetValue number (0)Mathto compare with length of response set MessageTextbox.Text toMessageTextboxif we retrieved something, place it in MessageTextbox global responseMy Definitionsthis variable holds the value retrieved from GetValue

13 Blocks look:

14 No Text While Driving, Final Program


Download ppt "No Texting While Driving. Introduction You'll design the app so that it sends a response to any text message received. You'll also allow the user to customize."

Similar presentations


Ads by Google