App Inventor 2, 2nd Edition

Book description

Yes, you can create your own apps for Android devices—and it’s easy to do. This extraordinary book introduces you to App Inventor 2, a powerful visual tool that lets anyone build apps. Learn App Inventor basics hands-on with step-by-step instructions for building more than a dozen fun projects, including a text answering machine app, a quiz app, and an app for finding your parked car!

The second half of the book features an Inventor’s Manual to help you understand the fundamentals of app building and computer science. App Inventor 2 makes an excellent textbook for beginners and experienced developers alike.

  • Use programming blocks to build apps—like working on a puzzle
  • Create custom multi-media quizzes and study guides
  • Design games and other apps with 2D graphics and animation
  • Make a custom tour of your city, school, or workplace
  • Control a LEGO® MINDSTORMS® NXT robot with your phone
  • Build location-aware apps by working with your phone’s sensors
  • Explore apps that incorporate information from the Web

Publisher resources

View/Submit Errata

Table of contents

  1. Foreword
  2. Preface
    1. A Blocks Language for Mobile Phones
    2. What Can You Do with App Inventor?
    3. Why App Inventor Works
    4. What Kind of Apps Can You Build?
    5. Who Can Build Apps?
    6. Conventions Used in This Book
    7. Using Code Examples
    8. Safari® Books Online
    9. How to Contact Us
    10. Acknowledgments
  3. I. AI2 Tutorials
  4. 1. HelloPurr
    1. What You’ll Learn
    2. The App Inventor Environment
    3. Designing the Components
      1. Making a Label
      2. Adding the Button
      3. Adding the Meow Sound
    4. Live Testing
    5. Adding Behaviors to the Components
      1. Making the Kitty Meow
      2. Adding a Purr
      3. Shaking the Device
    6. Downloading the App to Your Android Device
    7. Sharing the App
    8. Variations
    9. Summary
  5. 2. PaintPot
    1. What You’ll Learn
    2. Getting Started
    3. Designing the Components
      1. Creating the Color Buttons
      2. Using Arrangements for Better Layouts
      3. Adding the Canvas
      4. Arranging the Bottom Buttons and the Camera Component
    4. Adding Behaviors to the Components
      1. Adding the Touch Event to Draw a Dot
      2. Adding the Drag Event That Draws a Line
      3. Changing the Color
      4. Letting the User Take a Picture
      5. Changing the Dot Size
      6. Referencing the dotSize Variable in DrawCircle
      7. Changing the Value of dotSize
    5. The Complete App: PaintPot
    6. Variations
    7. Summary
  6. 3. MoleMash
    1. What You’ll Build
    2. What You’ll Learn
    3. Getting Started
    4. Designing the Components
      1. Placing the Action Components
      2. Placing the Label Components
    5. Adding Behaviors to the Components
      1. Moving the Mole
      2. Creating the MoveMole Procedure
      3. Calling MoveMole When the App Starts
      4. Calling MoveMole every Second
      5. Keeping Score
      6. Procedural Abstraction
      7. Resetting the Score
      8. Vibrating When the Mole Is Touched
    6. The Complete App: MoleMash
    7. Variations
    8. Summary
  7. 4. No Texting While Driving
    1. What You’ll Learn
    2. Getting Started
    3. Designing the Components
    4. Adding Behaviors to the Components
      1. Auto-Responding to a Text
      2. Entering a Custom Response
      3. Storing the Custom Response Persistently
      4. Retrieving the Custom Response When the App Opens
      5. Speaking the Incoming Texts Aloud
      6. Adding Location Information to the Response
      7. Sending the Location as Part of the Response
    5. The Complete App: No Texting While Driving
    6. Variations
    7. Summary
  8. 5. Ladybug Chase
    1. What You’ll Build
    2. What You’ll Learn
    3. Designing the Components
      1. Getting Started
      2. Placing the Initial Components
    4. Adding Behaviors to the Components
      1. Moving the Ladybug
      2. Displaying the Energy Level
      3. Starvation
      4. Adding an Aphid
      5. Programming the Ladybug to Eat the Aphid
      6. Detecting a Ladybug-Aphid Collision
      7. The Return of the Aphid
      8. Adding a Restart Button
      9. Adding the Frog
    5. The Return of the Ladybug
    6. Adding Sound Effects
    7. The Complete App: Ladybug Chase
    8. Variations
    9. Summary
  9. 6. Paris Map Tour
    1. What You’ll Learn
    2. Designing the Components
    3. Setting the Properties of ActivityStarter
    4. Adding Behaviors to the Components
      1. Creating a List of Destinations
      2. Letting the User Choose a Destination
      3. Opening Maps with a Search URL
    5. The Complete App: Map Tour with Activity Starter
      1. A Virtual Tour with the Web Viewer
      2. Finding the URL for Specific Maps
      3. Defining the URLs List
      4. Modifying the ListPicker.AfterPicking Behavior
    6. The Complete App: Map Tour (Web Viewer)
    7. Variations
    8. Summary
  10. 7. Android, Where’s My Car?
    1. What You’ll Learn
    2. Getting Started
    3. Designing the Components
    4. Adding Behaviors to the Components
      1. Displaying the Current Location
      2. Recording the Current Location
      3. Displaying Directions to the Remembered Location
      4. Storing the Remembered Location Persistently
      5. Retrieving the Remembered Location When the App Launches
    5. The Complete App: Android, Where’s My Car?
    6. Variations
    7. Summary
  11. 8. Presidents Quiz
    1. What You’ll Learn
    2. Getting Started
    3. Designing the Components
    4. Adding Behaviors to the Components
      1. Defining the Question and Answer Lists
      2. Defining the Index Variable
      3. Displaying the First Question
      4. Iterating Through the Questions
      5. Making the Quiz Easy to Modify
      6. Switching the Image for Each Question
      7. Checking the User’s Answers
    5. The Complete App: The Presidents Quiz
    6. Variations
    7. Summary
  12. 9. Xylophone
    1. What You’ll Build
    2. What You’ll Learn
    3. Getting Started
    4. Designing the Components
    5. Creating the Keyboard
      1. Creating the First Note Buttons
      2. Adding the Sound Component
      3. Connecting the Sounds to the Buttons
      4. Instructing Android to Load the Sounds
      5. Implementing the Remaining Notes
    6. Recording and Playing Back Notes
      1. Adding the Components
      2. Recording Notes and Times
      3. Playing Back Notes
      4. Playing Back Notes with Proper Delays
    7. The Complete App: Xylophone
    8. Variations
    9. Summary
  13. 10. MakeQuiz and TakeQuiz
    1. What You’ll Learn
    2. Getting Started
    3. Designing the Components
    4. Adding Behaviors to the Components
      1. Creating Empty Question and Answer Lists
      2. Recording the User’s Entries
      3. Blanking Out the Question and Answer
      4. Displaying Question-Answer Pairs on Multiple Lines
      5. Calling the displayQAs Procedure
      6. Saving the QAs Persistently on the Web
      7. Loading Data from the Database
    5. The Complete App: MakeQuiz
    6. TakeQuiz: An App for Taking the Quiz in the Database
      1. How the Blocks Work
    7. The Complete App: TakeQuiz
    8. Variations
    9. Summary
  14. 11. Broadcast Hub
    1. What You’ll Learn
    2. Getting Started
    3. Designing the Components
    4. Adding Behaviors to the Components
      1. Responding to Incoming Texts
      2. Adding Numbers to the Broadcast List
      3. Broadcasting the Messages
      4. Beautifying the List Display
      5. Logging the Broadcasted Texts
      6. Storing the BroadcastList in a Database
      7. Loading the BroadcastList from a Database
    5. The Complete App: Broadcast Hub
    6. Variations
    7. Summary
  15. 12. Robot Remote
    1. What You’ll Learn
    2. Getting Started
    3. Designing the Components
      1. Non-Visible Components
      2. Visible Components
    4. Adding Behaviors to the Components
      1. Connecting to the NXT
      2. Displaying the List of Robots
      3. Making the Bluetooth Connection
      4. Disconnecting from the NXT
    5. Driving the NXT
    6. Using the Ultrasonic Sensor to Detect Obstacles
    7. Variations
    8. Summary
  16. 13. Amazon at the Bookstore
    1. What You’ll Learn
    2. What is an API?
    3. Getting Started
    4. Designing the Components
    5. Programming the App’s Behavior
      1. Searching by Keyword
      2. Searching by ISBN
      3. Don’t Leave Your Users Hanging
      4. Scanning a Book
      5. Improving the Display
    6. The Complete App: Amazon at the Bookstore
    7. Customizing the API
    8. Variations
    9. Summary
  17. II. Inventor’s Manual
  18. 14. Understanding an App’s Architecture
    1. Components
    2. Behavior
    3. An App as a Recipe
    4. An App as a Set of Event Handlers
    5. Event Types
      1. User-Initiated Events
      2. Initialization Events
      3. Timer Events
      4. Animation Events
      5. External Events
    6. Event Handlers Can Ask Questions
    7. Event Handlers Can Repeat Blocks
    8. Event Handlers Can Remember Things
    9. Event Handlers Can Interact with the Web
    10. Summary
  19. 15. Engineering and Debugging an App
    1. Software Engineering Principles
    2. Solve Real Problems
    3. Build a Prototype and Show Users
    4. Incremental Development
    5. Design Before Coding
    6. Comment Your Code
    7. Divide, Layer, and Conquer
    8. Understand Your Language: Tracking with Pen and Paper
    9. Debugging an App
    10. Watching Variables
    11. Testing Individual Blocks
    12. Incremental Development with Do It
    13. Disabling Blocks
    14. Summary
  20. 16. Programming Your App’s Memory
    1. Named Memory Slots
    2. Properties
    3. Defining Variables
    4. Setting and Getting a Variable
    5. Setting a Variable to an Expression
    6. Incrementing a Variable
    7. Building Complex Expressions
    8. Displaying Variables
    9. Local Variables
    10. Summary
  21. 17. Creating Animated Apps
    1. Adding a Canvas Component to Your App
    2. The Canvas Coordinate System
    3. Animating Objects with Timer Events
    4. Creating Movement
    5. Speed
    6. Collision Detection
    7. EdgeReached
    8. CollidingWith and NoLongerCollidingWith
    9. Interactive Animation
    10. Specifying Sprite Animation Without a Clock Timer
    11. Summary
  22. 18. Programming Your App to Make Decisions: Conditional Blocks
    1. Testing Conditions with if and else if Blocks
    2. Programming an Either/Or Decision
    3. Programming Conditions Within Conditions
    4. Programming Complex Conditions
    5. Summary
  23. 19. Programming Lists of Data
    1. Creating a List Variable
    2. Selecting an Item in a List
    3. Using an Index to Traverse a List
    4. Example: Traversing a List of Paint Colors
    5. Creating Input Forms and Dynamic Data
    6. Defining a Dynamic List
    7. Adding an Item
    8. Displaying a List
    9. Removing an Item from a List
    10. Lists of Lists
    11. Summary
  24. 20. Repeating Blocks
    1. Controlling an App’s Execution: Branching and Looping
    2. Iterating Functions on a List with for each
    3. A Closer Look at Looping
    4. Writing Maintainable Code
    5. Using for each to Display a List
    6. The while-do Block
    7. Using while-do to Compute a Formula
    8. Summary
  25. 21. Defining Procedures and Reusing Blocks
    1. Eliminating Redundancy
    2. Defining a Procedure
    3. Calling a Procedure
    4. The Program Counter
    5. Adding Parameters to Your Procedure
    6. Returning Values from a Procedure
    7. Reusing Blocks Among Apps
    8. The distanceBetweenPoints Procedure
    9. Summary
  26. 22. Working with Databases
    1. Storing Persistent Data in TinyDB
    2. Retrieving Data from TinyDB
    3. Shared Data and TinyWebDB
      1. Storing Data by Using TinyWebDB
      2. Requesting and Processing Data with TinyWebDB
      3. GetValue-GotValue in Action
      4. A More Complex GetValue/GotValue Example
    4. Requesting Data with Various Tags
    5. Setting Up a Web Database
    6. Summary
  27. 23. Reading and Responding to Sensors
    1. Creating Location-Aware Apps
      1. The Global Positioning System
      2. Sensing Location with App Inventor
      3. Checking Boundaries
      4. Location Information Providers: GPS, WiFi, and Cell ID
    2. Using the Orientation Sensor
      1. Using the Roll Parameter to Move an Object
      2. Moving in Any Direction by Using Heading and Magnitude
      3. Using the Phone As a Compass
    3. Using the Accelerometer
      1. Responding to the Device Shaking
      2. Using the AccelerometerSensor’s Readings
      3. Detecting Free Fall
    4. Summary
  28. 24. Communicating with the Web
    1. The WebViewer Component
    2. The Web Component
      1. Stock Market Sample
    3. TinyWebDB and TinyWebDB-Compliant APIs
    4. Summary
  29. Index

Product information

  • Title: App Inventor 2, 2nd Edition
  • Author(s): David Wolber, Hal Abelson, Ellen Spertus, Liz Looney
  • Release date: October 2014
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781491907221