Page 341 -
P. 341

manage your data




                              Let’s create a small Android app that interacts with your user twice. The first dialog asks the
                              user to confirm the web address and port to use for the web server. Assuming your user taps
                              the OK button on your dialog, a second dialog pops up to request the timing value to send to the
                              server. As with the first dialog, tapping the OK button continues execution by sending the newly
                              acquired timing value to the web server. Tapping Cancel at any time causes your app to exit.
                              Some of the code is provided for you. Your job is to complete the program. Write the code you
                              think you need under this code, and call your program get2inputsapp.py:


                         import android
                         from urllib import urlencode
                         from urllib2 import urlopen
           There’s
            nothing new   server_title  = 'Which server should I use?’
            here…you’ve   server_msg    = "Please confirm the server address/name to use for your athlete's timing data:"
            seen all of   timing_title  = 'Enter data'
            this code    timing_msg    = 'Provide a new timing value:'
            before.      web_server    = 'http://192.168.1.33:8080'

                         add_time_cgi  = '/cgi-bin/add_timing_data.py'

                         app = android.Android()

                         def send_to_server(url, post_data=None):
                             if post_data:
                                 page = urlopen(url, urlencode(post_data))
                             else:
                                 page = urlopen(url)
                             return(page.read().decode("utf8"))



























                                                                                      you are here 4    305
   336   337   338   339   340   341   342   343   344   345   346