WC2012 Programming Mobile Devices

# WC2012 Programming Mobile Devices

Télécharger la présentation

## WC2012 Programming Mobile Devices

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
##### Presentation Transcript

1. WC2012Programming Mobile Devices Intermediate AppInventor Many examples in this section from http://turing.cs.trincoll.edu/~ram/cpsc110/tutorials/ And http://www.appinventorblocks.com/home

2. Impressions so far?

3. A couple to try • From I “heart” my smartphone handout • Lesson 6 Tossing a coin • Lesson 7 Wiff-Waff game • These are from • http://www.royalsoced.org.uk/1035_MobileAppDevelopment.html

4. So What is AppInventor Good For? Intro to programming concepts Logical design/critical thinking Intro to Object concepts, event handling and other common areas of difficulty Intro to Mobile App development Starting point on a migration through a whole class in App Development Summer Camps for HS students Other?

5. Some Interesting Resources • KATE Workshops • https://docs.google.com/document/d/1L7PEy_NdiiRTfIIEADHTBTMYO-ifHIPD-WkzgvabaEk/edit • Vocabulary Builder • Classroom Management

6. List and Loops Repeating operations is important and also using lists of data Consider this simple app which will display an increasingly long list of numbers each time NEW LIST is pressed

7. Lists and Loops

8. Lists and Loops Lets look at the whole thing

9. ForRange loops

10. ForEach Loop

11. Try Challenge 1: Magic 8 Ball using a list

12. Orientation Sensor • Measure which way the phone is pointed and its movement. • Working with the sensors requires math and understanding of reading parameters. For Orientation Sensor: • Yawis the compass heading in degrees, range 0 to 360 ( 0 = North, 90 = East, 180 = South, 270 = West ) • Pitch indicates the tilt of the top of the device, with range -90 to 90. Positive values indicate that the bottom of the device is tilted up and negative values indicate the top of the device is tilted up. • Rollindicates the side to side tilt of the device, with range -90 to 90. Positive values indicate that the left side of the device is tilted up and negative values indicate the right side of the device is tilted up. • There are also Angle and Magnitude attributes you can use

13. Challenge Try Challenge 2 Bouncing Ball Try Challenge 3 Breakout

14. Persistent Storage • On The Phone using TinyDB • Persistent on your phone and tied to App • Can be cleared on phone • Won’t be “persistent” while testing in emulator once you close the emulator • “In the Cloud” using TinyWebDB • Stored in a cloud DB using web services • By default, the TinyWebDB component stores data on a test service provided by App Inventor, limited to 1000 entries • Can create your own web service as well on the appspot.com server provided by Google

15. TinyDB Basics Local Storage that is persistent can be placed in a database using the TinyDB component. This persists until you delete it, even beyond running of the app These work well in conjunctions with lists TinyDBstores data in a tag-value scheme. The tag is used as a key by which the data can be retrieved. For example: Tag Value One This is the first string Two This is another string

16. Storing in TinyDB Tag is always text, but value can be text, number, string or even a list

17. Retrieving in TinyDB Example to plot points of interest on the canvas. Later we will add a map to the canvas DBList Example This will also illustrate using a list picker

18. Video Tutorials on Storage • http://android.jwtyler.com/?page_id=7 • Other good tutorials here also • Another good tutorial source • https://sites.google.com/site/stevozip/ • Other good resources • http://www.tair.info/

19. Location Sensor 1 deg of latitude is approx 69.047 miles or 111.12 km 1 deg of longitude is 69.047 x Cos (current lat) Global Positioning System (GPS) GPS data comes from the Global Positioning System, a satellite system maintained by the US government. To get a GPS reading your phone must have an unobstructed line-of-sight to three satellits. A GPS reading consists of three data: latitude, longitude, and altitude. Your latitude is your distance in degrees north or south of the equator, with north positive and south negative. The range is -90 to +90. Your longitude is your distance east or west of the Prime Meridian, which goes through Greenwich England. East coordinates have positive values and west coordinates are negative. The values range from -180 to +180. Values on the Meridian are 0. Android's Location Sensor There are three ways that your Android phone can determine its location: GPS Satellites are accurate to within a few meters, but they only work out doors. WiFi: If you are on a WiFi network, the phone can use the location of the WiFi hot spot as its location. Cell Towers can also be used to locate the phone based on a calculation of the phone's proximity to known cell phone towers.

20. Using the Location Sensor

21. Location sensor methods

22. Enable/Disable Location Sensor

23. Simple Lab Example • Lesson 5 Virtual Map Tour • Uses Location sensor • Also introduces the ActvityStarter • This lets one app start up another app

24. Location Services – one example • Where’s my Car? • Source on Wiki • Uses location services to record a “remembered” spot and then help you get from current location to remembered spot. • Uses map services as well • Assignment variations • Breadcrumb app that logs all location changes and can show route on map • Hike/Walk/Jog tracker that shows legs of a journey with approx distances and total distance

25. Compass and Orientation Sensor Example • Where is North Example • Could you make this better? • Improve graphics • Provide more useful info like a north/south line marker • Turn it into a “guess where north is” game?

26. A little More Difficult Challenge Write an Android application that uses the location sensor in an interesting way. Here are some ideas: a. HELP ME! Write an Android app that sends a text to someone with your latitude and longitude in the message. Use the text.join block to build the message. Warning: Only send the message when the user clicks a button, and only enable the button when the latitude and longitude are set. Test this application in class, then play hide and go seek: have one person go somewhere on campus, and see if the other person can find them. b. TRAIL ME! Write an app that records the addresses the sensor identifies as you walk around. The app can list them on the phone display and also either twitter them or use tinywebdb to record them. Record the time of each address as well using Clock.Now.

27. Using Communication Tools • Let’s look at a couple of texting applications • TextGroup2 Tutorial • Source available on Wiki • How do I get it and load it? • Uses local persistent storage (i.e. TinyDB) • Texting Raffle • Users send text message to apps phone number and are put in list. When the Luck button is pressed on of the numbers is selected at random to win a prize • What changes could we make to these?

28. Automatic Responses • Detect when a text message comes in and send an automatic response • Like your email autoresponder • No Text While Driving Tutorial • Source on Wiki • Try a variation like • Custom responses for particular phone numbers • Custom responses based on location • Variations on a theme… • No Texting While Driving 2 • Reads the message to you so you don’t miss anything • Also on Wiki