Skip to content
This repository
Browse code

Added startviewserver argument to ViewClient

- Start the server if specified
- Eat optional command line arguments
- Added UML
  • Loading branch information...
commit 357e6b548717e3b17c59671653fd5dfe2c03aa8d 1 parent 19b3db9
Diego Torres Milano authored
4 .gitignore
@@ -10,3 +10,7 @@
10 10 # vi files #
11 11 ############
12 12 .*.swp
  13 +
  14 +# other files #
  15 +##########
  16 +*~
11 AndroidViewClient/examples/temperature-converter-get-conversion.py
@@ -35,8 +35,13 @@
35 35
36 36 from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
37 37
38   -
39   -device, serialno = ViewClient.connectToDeviceOrExit()
  38 +print sys.argv
  39 +localViewServer = False
  40 +if len(sys.argv) > 1 and sys.argv[1] == '--localViewServer':
  41 + localViewServer = True
  42 + sys.argv.pop(1)
  43 +
  44 +device, serialno = ViewClient.connectToDeviceOrExit(ignoresecuredevice=localViewServer)
40 45
41 46 FLAG_ACTIVITY_NEW_TASK = 0x10000000
42 47 package = 'com.example.i2at.tc'
@@ -50,7 +55,7 @@
50 55 device.type("123")
51 56 MonkeyRunner.sleep(3)
52 57
53   -vc = ViewClient(device, serialno)
  58 +vc = ViewClient(device, serialno, startviewserver=(not localViewServer))
54 59
55 60 # obtain the views by id
56 61 celsius = vc.findViewByIdOrRaise("id/celsius")
32 AndroidViewClient/examples/viewserveractivity-new-activity.py
... ... @@ -0,0 +1,32 @@
  1 +#! /usr/bin/env monkeyrunner
  2 +'''
  3 +Copyright (C) 2012 Diego Torres Milano
  4 +Created on Feb 3, 2012
  5 +
  6 +@author: diego
  7 +'''
  8 +
  9 +
  10 +import sys
  11 +import os
  12 +
  13 +# This must be imported before MonkeyRunner and MonkeyDevice,
  14 +# otherwise the import fails.
  15 +# PyDev sets PYTHONPATH, use it
  16 +try:
  17 + for p in os.environ['PYTHONPATH'].split(':'):
  18 + if not p in sys.path:
  19 + sys.path.append(p)
  20 +except:
  21 + pass
  22 +
  23 +try:
  24 + sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
  25 +except:
  26 + pass
  27 +
  28 +from com.dtmilano.android.viewclient import ViewClient
  29 +
  30 +device, serialno = ViewClient.connectToDeviceOrExit(ignoresecuredevice=True)
  31 +vc = ViewClient(device=device, serialno=serialno, startviewserver=False)
  32 +vc.findViewWithTextOrRaise("New activity").touch()
18 AndroidViewClient/src/com/dtmilano/android/viewclient.py
@@ -683,7 +683,7 @@ class ViewClient:
683 683 mapping is created.
684 684 '''
685 685
686   - def __init__(self, device, serialno='emulator-5554', adb=os.path.join(ANDROID_HOME, 'platform-tools', ADB), autodump=True):
  686 + def __init__(self, device, serialno='emulator-5554', adb=os.path.join(ANDROID_HOME, 'platform-tools', ADB), autodump=True, startviewserver=True):
687 687 '''
688 688 Constructor
689 689
@@ -695,18 +695,21 @@ def __init__(self, device, serialno='emulator-5554', adb=os.path.join(ANDROID_HO
695 695 @param adb: the path of the C{adb} executable
696 696 @type autodump: boolean
697 697 @param autodump: whether an automatic dump is performed at the end of this constructor
  698 + @type startviewserverparam: boolean
  699 + @param startviewserverparam: Whether to start the B{global} ViewServer
698 700 '''
699 701
700 702 if not device:
701 703 raise Exception('Device is not connected')
702 704 if not os.access(adb, os.X_OK):
703 705 raise Exception('adb="%s" is not executable. Did you forget to set ANDROID_HOME in the environment?' % adb)
704   - if not self.serviceResponse(device.shell('service call window 3')):
705   - try:
706   - self.assertServiceResponse(device.shell('service call window 1 i32 %d' %
  706 + if startviewserver:
  707 + if not self.serviceResponse(device.shell('service call window 3')):
  708 + try:
  709 + self.assertServiceResponse(device.shell('service call window 1 i32 %d' %
707 710 VIEW_SERVER_PORT))
708   - except:
709   - raise Exception('Cannot start View server.\n'
  711 + except:
  712 + raise Exception('Cannot start View server.\n'
710 713 'This only works on emulator and devices running developer versions.\n'
711 714 'Does hierarchyviewer work on your device ?')
712 715
@@ -775,6 +778,9 @@ def connectToDeviceOrExit(timeout=60, verbose=False, ignoresecuredevice=False):
775 778 '''
776 779
777 780 progname = os.path.basename(sys.argv[0])
  781 + # eat all the extra options the invoking script may have added
  782 + while len(sys.argv) > 1 and sys.argv[1][0] == '-':
  783 + sys.argv.pop(1)
778 784 serialno = sys.argv[1] if len(sys.argv) > 1 else 'emulator-5554'
779 785 if verbose:
780 786 print 'Connecting to a device with serialno=%s with a timeout of %d secs...' % (serialno, timeout)
BIN  AndroidViewClient/uml/AndroidViewClient.zargo
Binary file not shown

0 comments on commit 357e6b5

Please sign in to comment.
Something went wrong with that request. Please try again.