Advertisement
gregwa

Article 34 Code - FCM62 - atest.py

Jun 6th, 2012
733
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.73 KB | None | 0 0
  1. import android
  2. droid = android.Android()
  3. uname = droid.dialogGetInput("Hello","What's your name?")
  4. droid.makeToast("Hello %s from python on Android!" % uname.result)
  5. droid.dialogCreateAlert(uname.result,"Would you like to play a game?")
  6. droid.dialogSetPositiveButtonText('Yes')
  7. droid.dialogSetNegativeButtonText('No')
  8. droid.dialogShow()
  9.  
  10. while True: #wait for events for up to 10 seconds...
  11.     response = droid.eventWait(10000).result
  12.     if response == None:
  13.         break
  14.     if response["name"] == "dialog":
  15.         break
  16. droid.dialogDismiss()
  17.  
  18. if response==None:
  19.     print "Timed out."
  20. else:
  21.     rdialog=response["data"]
  22.     if rdialog.has_key("which"):
  23.         result=rdialog["which"]
  24.         if result=="positive":
  25.             droid.dialogCreateAlert("Play a Game","Select a game to play")
  26.             droid.dialogSetItems(['Checkers','Chess','Hangman','Thermal Nuclear War']) # 0,1,2,3
  27.             droid.dialogShow()
  28.             resp = droid.dialogGetResponse()
  29.             # resp is a dictionary
  30.             if resp.result.has_key("item"):
  31.                 sel = resp.result['item']
  32.                 if sel == 0:
  33.                     droid.makeToast("Enjoy your checkers game")
  34.                 elif sel == 1:
  35.                     droid.makeToast("I like Chess")
  36.                 elif sel == 2:
  37.                     droid.makeToast("Want to 'hang around' for a while?")
  38.                 else:
  39.                     droid.makeToast("The only way to win is not to play...")
  40.         elif result=="negative":
  41.             droid.makeToast("Sorry.  See you later.")
  42.     elif rdialog.has_key("canceled"):
  43.         print "Sorry you can't make up your mind."
  44.     else:
  45.         print "unknown response=",response
  46. print "Done"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement