STARTING OUT WITH
x^i^^'n^-AJ itf%&^\^J ' 5 ^'•if^'i-sM'A 4-'i, "!•
-
, S L
feMl£ J-L J CO Hi
Tony Gaddis
and
Rebecca Halsey
PEARSON
Boston Columbus Indianapolis New York San Francisco
UpperSaddleRiver Amsterdam CapeTown Dubai London Madrid Milan Munich Paris Montreal Toronto Delhi MexicoCity SaoPaulo Sydney
Hong Kong Seoul Singapore Taipei Tokyo
Chapter
1 Introduction toProgramming
andApp
Inventor 251.1 Introduction 25
1.2 WhatIsaComputer Program? 28
1.3 Introducing App Inventor 32
TUTORIAL 1-1: Starting AppInventorand Creatinga
NewProject 32
1.4 GettingHands-On with App Inventor 46
tutorial 1-2: Creatingthe Screen for the Hello WorldApp 61
tutorial 1-3: Completing the Hello WorldApp 75
tutorial 1-4: Creatingthe Good MorningTranslatorApp 79
ReviewQuestions 88
Chapter
2Working
with Media 972.1 Displaying Images 97
tutorial 2-1: Changingthe Screen'sBackgroundImage 100
tutorial2-2: Switchingthe Screen'sBackground Image
in Code 104
tutorial 2-3: UsingtheImageComponent 109
tutorial2-4: CreatingtheFlags App 114
2.2 Duplicating Blocks and Using Dropdowns 120
2.3 Sounds 123
tutorial 2-5: Creatingthe Guitar App 126
tutorial 2-6: Makingthe Phone Vibrate 130
2.4 Color Blocks 133
2.5 Layout Components 136
tutorial 2-7: Using Layout Components andColor Blocks 140
2.6 Commenting Blocks 143
tutorial 2-8: AddingComments 144
ReviewQuestions 145
7
8 Contents
Chapter
3Input, Variables,
and Calculations 1533.1 The TextBoxComponent 153
3.2 Performing Calculations 159
TUTORIAL 3-1: CalculatingFuelEconomy 162
TUTORIAL 3-2: Creatingthe RestaurantTipCalculatorApp 168
3.3 StoringDatawith Variables 173
TUTORIAL 3-3: Creatingthe KilometerConverterApp 182
TUTORIAL 3-4: CreatingtheChange CounterApp 193
3.4 Creating Blocks withTypeblocking 198
3.5 The SliderComponent 200
3.6 Math Functions 204
ReviewQuestions 206
Chapter
4 Decision Blocks and BooleanLogic
2114.1 Introductionto Decision Blocks 211
4.2 Relational Operators and the ifBlock. 216
tutorial 4-1: TheTestAverage App 218
4.3 The if then else Block 226
tutorial4-2: ModifyingtheTestAverageApp 227
tutorial 4-3: Creating theWages App 229
4.4 A FirstLookAtComparing Strings 236
4.5 Logical Operators 237
tutorial 4-4: Creating the RangeCheckerApp 240
4.6 Nested Decision Blocks 242
tutorial 4-5: Creatingthe GraderApp 243
4.7 The if then else if Block 245
4.8 Workingwith Random Numbers 248
tutorial 4-6: Simulating Coin Tosses 250
4.9 The Screen's initialize Event 253
4.10 The ListPickerComponent 254
tutorial 4-7: Creatingthe Time ZoneApp 256
4.11 The CheckBoxComponent 259
ReviewQuestions 265
Chapter
5Repetition Blocks,
Times, and Dates 2715.1 The Notifier Component 271
5.2 Thewhile Loop 279
TUTORIAL 5 1: TheEndingBalanceApp 282
5.3 The for each Loop 287
tutorial 5-2: Calculatinga Sumof Consecutive Numbers 291
5.4 TheClockComponent 294
tutorial5-3: Creatinga Clock App 297
5.5 The DatePickerComponent 303
Review Questions 306
Chapter
6 Procedures and Functions 3116.1 ModularizingYour Code With Procedures 311
6.2 Procedures 312
tutorial6-1: CreatingtheLights App ' 316
6.3 Passing ArgumentstoProcedures 322
tutorial6-2: Creatingthe AreaCircle App 327
6.4 ReturningValues From Procedures 331
tutorial 6-3: TheCupsTo OuncesApp 334
ReviewQuestions 338
Chapter
7 Lists 3437.1 Creating a List 343
TUTORIAL 71: CreatingaList 345
7.2 Iterating Over aList with thefor each Loop 350
TUTORIAL 7-2: IteratingOver aListwith thefor eachLoop 353
7.3 Selecting an Item 356
tutorial 7-3: SelectinganItem ina List 356
TUTORIAL 7-4: Usingthelength of list Function 361
7.4 Inserting andAppending Items 365
tutorial 7-5: AddItemstoaList 367
7.5 Removing Items 372
7.6 Replacing Items 374
tutorial 7-6: ReplacingandRemovingList Items 376
7.7 Searchingforan Item 384
tutorial7-7: CreatingaNumber-GuessingGame 385
7.8 Other List Functions 390
Review Questions 391
Chapter
8Storing
Data on the Device 3958.1 App Inventor Storage Components 395
8.2 TheApplication Sandbox 396
8.3 FileComponent 396
tutorial8-1: Creatinga File 399
8.4 Retrieving a File 402
TUTORIAL8-2:Retrievinga File 402
tutorial 8-3: AppendingaFile 405
8.5 TinyDB 407
8.6 Tag-Value Pairs 408
8.7 Storing aTag-ValuePair 409
10 Contents
tutorial 8-4: StoringNames and Phone Numbers 409
8.8 Retrievinga Value 410
tutorial 8-5: Storingand RetrievingValues 411
8.9 Tag-ValuePairs when the Value isa List 413 tutorial 8-6: Storinga Listas aValue in aTag-ValuePair 414
8.10 TinyDBAcross MultipleScreens 421
TUTORIAL 8-7: TinyDBacross MultipleScreens 423
ReviewQuestions 433
Chapter
9Graphics
and Animation 4399.1 The Canvas Component 439
tutorial 9-1:Drawingon the Canvas 442
9.2 The Ball and ImageSprite Component 448
tutorial 9-2:BouncingBall 448
tutorial 9-3: Fishbowl- Using theImageSprite Component 456
9.3 Usingthe ClockComponentto Create Animations 458
tutorial 9-4: Crack the Egg 458
9.4 Dragging Sprites 463
tutorial 9-5: Drag BallSpriteExample 463
tutorial 9 6: Drag the Ballinto the Box 464
9.5 DetectingCollisions 469
tutorial 9-7: PoppingBalloons 471
ReviewQuestions 479
Chapter
10Working
with Text 48510.1 Concatenating Strings 485
10.2 Comparing Strings 491
tutorial10-1: Comparing Strings 494
10.3 Trimming a String 499
10.4 Converting Case 500
tutorial10-2: Trim and Convertto FormatTags 501
10.5 Finding aSubstring 505
tutorial 10-3: ValidateanEmail Address 508
10.6 Replacinga Substring 513
10.7 Extracting a Substring 513
10.8 Splittinga Substring 515
tutorial 10-4: Validating Email-Valid Name andTop-LevelDomain ... 519
ReviewQuestions -529
Chapter
11 Text toSpeech
and TextMessaging
53311.1 TheTextToSpeech Component 533
tutorial il l: Textto Speech 536
11.2 TheTexting Component 540
11.3 ReceivingTextMessages 543
tutorial n-2: Creatingthe Speak Messagesfrom FamilyApp 544
11.4 Sending Text Messages 547
tutorial 113: ReplytoFamily 548
ReviewQuestions 550
Chapter
12 Sensors 55512.1 The LocationSensor 555
tutorial 12-1: DisplayLocation 559
12.2 The OrientationSensor 566
tutorial12-2: Cat and Mouse 569
12.3 The Accelerometer 574
TUTORIAL 12-3: ShaketoClear Canvas 576
12.4 Using theActivityStarter Componentto launch Google Maps 578
tutorial 12-4: Open Google Maps 580
ReviewQuestions 581
Chapter
1 3 OtherApp
InventorCapabilities
58513.1 RecordingAudio 585
tutorial 13-1: Record andPlayBackAudio 587
13.2 Taking a Photo with the Phone's Camera 591
13.3 The Camcorder Component 592
13.4 Using the ImagePicker Component 593
tutorial 13-2: UsingtheImagePicker 593
13.5 PlayingVideo 596
tutorial 13-3: PlayingVideo 597
13.6 Selecting Contacts from theContact List and Placing PhoneCalls... 600
tutorial 13-4: Usingthe Contact and Phone Number Pickers 601
tutorial 13-5: Usingthe PhoneCallcomponent 604
13.7 Scanning a Barcode 608
13.8 Using VoiceRecognition 609
tutorial 13-6: Speak aTextMessage 609
13.9 Connecting to aTwitterAccount 613
tutorial 13-7: BuildingaTwitterApplication 614
13.10TinyWebDB 616
ReviewQuestions 617
Appendix
ASetting Up App
Inventor 621Appendix
BConnecting
an Android Device toApp
Inventor 62712 Contents
Appendix
CUploading
YourApplication
toApp
InventorGallery
andGoogle Play
Store 637Appendix
DComponent
Reference 643Appendix
E Answers toCheckpoints
673Index 685