Download
wc2012 programming mobile devices n.
Skip this Video
Loading SlideShow in 5 Seconds..
WC2012 Programming Mobile Devices PowerPoint Presentation
Download Presentation
WC2012 Programming Mobile Devices

WC2012 Programming Mobile Devices

106 Vues Download Presentation
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

  29. Web Databases The main tool for persistent data “in the cloud” is TinyWebDB By default, the TinyWebDB component stores data on the Google cloud on a server whose URL is http://appinvtinywebdb.appspot.com. The problem with storing your data there is that it is accessible to all App Inventor developers. Other developers could overwrite your data. Fortunately, it is relatively easy to create your own TinyWebDB database service using some code that Prof. Wolber of the University of San Francisco has created. You don't even need to know how to code-- you can just download some sample code and then upload it to the "cloud" with Google's App Engine. For instructions, see http://appinventorapi.com/program-an-api-python/. For this example and your exercises we will use a server that was created by another instructor, or you can use the google one. It's URL is http://ram8647-appinventortest.appspot.com. In the App Inventor Viewer, you will want to set the TinyWebDb's ServiceURL property to this address.

  30. Shopping with Friends example You go to the mall with some friends and want to share what you find

  31. Getting values Retrieval from TinyWebDB is asychronous so we do not know how long it will take and there is no wait so we have to use a separate event

  32. The Whole Example Shopping.zip

  33. Some Advanced Resources • Code Snippets and Tutorials • http://puravidaapps.com/snippets.php • Word Doc on Wiki with lots of other links

  34. Free Play • Have an idea for an App you would like to try? • Want to catch up on some of the variations from earlier? • Have Questions? • Want to take on some challenges? • Thanks tohttps://sites.google.com/site/appinventoredu For the challenges. You might also want to check out their section on Philosophy • Let’s use the rest of today to catch up on these things….