|
3 | 3 | Copyright (C) 2012 Diego Torres Milano |
4 | 4 | Created on Feb 3, 2012 |
5 | 5 |
|
| 6 | +This example starts the TemperatureConverter activity then type '123' into the 'Celsius' field. |
| 7 | +Then a ViewClient is created to obtain the view dump and the current values of the views with |
| 8 | +id/celsius and id/fahrenheith are obtained and the conversion printed to stdout. |
| 9 | + |
6 | 10 | @author: diego |
7 | 11 | ''' |
8 | 12 |
|
|
39 | 43 | vc = ViewClient(device) |
40 | 44 | vc.dump() |
41 | 45 |
|
| 46 | +# obtain the views by id |
42 | 47 | celsius = vc.findViewById("id/celsius") |
43 | 48 | fahrenheit = vc.findViewById("id/fahrenheit") |
| 49 | + |
44 | 50 |
|
45 | | -c = float(celsius.mText()) |
46 | | -f = float(fahrenheit.mText()) |
| 51 | +# in android-15 this is text:mText while in previous versions it was just mText |
| 52 | +try: |
| 53 | + c = float(celsius.text_mText()) |
| 54 | + f = float(fahrenheit.text_mText()) |
| 55 | + |
| 56 | + print "%.2f C => %.2f F" % (c, f) |
| 57 | +except: |
| 58 | + try: |
| 59 | + c = float(celsius.mText()) |
| 60 | + f = float(fahrenheit.mText()) |
| 61 | + |
| 62 | + print "%.2f C => %.2f F" % (c, f) |
| 63 | + except: |
| 64 | + print "Unexpected error:", sys.exc_info()[0] |
| 65 | + |
| 66 | +# obtain the views by tag |
| 67 | +celsius = vc.findViewByTag("celsius") |
| 68 | +fahrenheit = vc.findViewByTag("fahrenheit") |
| 69 | + |
| 70 | +# in android-15 this is text:mText while in previous versions it was just mText |
| 71 | +try: |
| 72 | + c = float(celsius.text_mText()) |
| 73 | + f = float(fahrenheit.text_mText()) |
47 | 74 |
|
48 | | -print "%.2f C => %.2f F" % (c, f) |
| 75 | + print "%.2f C => %.2f F" % (c, f) |
| 76 | +except: |
| 77 | + try: |
| 78 | + c = float(celsius.mText()) |
| 79 | + f = float(fahrenheit.mText()) |
49 | 80 |
|
| 81 | + print "%.2f C => %.2f F" % (c, f) |
| 82 | + except: |
| 83 | + print "Unexpected error:", sys.exc_info()[0] |
0 commit comments