Skip to content

Commit c2d5b93

Browse files
committed
- Fixed View.getXY()
- Modified development-settings-show-running-processes
1 parent 0c0c74c commit c2d5b93

2 files changed

Lines changed: 28 additions & 14 deletions

File tree

AndroidViewClient/examples/development-settings-show-running-processes.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,32 @@
2222

2323
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
2424

25-
STATUS_BAR = 38
26-
TITLE = 40
27-
CHECK_BOX = 50
2825

2926
# 01-04 18:23:42.000: I/ActivityManager(4288): Displayed com.android.development/.DevelopmentSettings: +379ms
3027
package = 'com.android.development'
31-
activity = '.DevelopmentSetting'
28+
activity = '.DevelopmentSettings'
3229
componentName = package + "/" + activity
33-
device = MonkeyRunner.waitForConnection(60)
30+
device = MonkeyRunner.waitForConnection(60, "emulator-5554")
3431
if not device:
3532
raise Exception('Cannot connect to device')
3633

3734
device.startActivity(component=componentName)
35+
MonkeyRunner.sleep(5)
36+
3837
vc = ViewClient(device)
3938
vc.dump()
40-
print vc.getViewIds().keys()
4139

4240
showCpu = vc.findViewById("id/show_cpu")
4341
showLoad = vc.findViewById("id/show_load")
4442
alwaysFinish = vc.findViewById("id/always_finish")
4543

46-
if showLoad.isChecked() == 'false':
44+
if not showLoad.isChecked():
4745
showLoad.touch()
4846

49-
if alwaysFinish['isChecked()'] == 'false':
47+
if not alwaysFinish.isChecked():
5048
alwaysFinish.touch()
5149

50+
if not showCpu.isChecked():
51+
# WARNING: Show CPU usage is de-activated as soon as it's activated, that's why it seems it
52+
# is never set
53+
showCpu.touch()

AndroidViewClient/src/com/dtmilano/android/viewclient.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import socket
1111
import os
1212

13-
DEBUG = True
13+
DEBUG = False
1414

1515
ANDROID_HOME = os.environ['ANDROID_HOME'] if os.environ.has_key('ANDROID_HOME') else '/opt/android-sdk'
1616
VIEW_SERVER_HOST = 'localhost'
@@ -26,6 +26,10 @@ class View:
2626
'''
2727

2828
def __init__(self, map, device):
29+
'''
30+
Constructor
31+
'''
32+
2933
self.map = map
3034
self.device = device
3135

@@ -34,7 +38,7 @@ def __getitem__(self, key):
3438

3539
def __getattr__(self, name):
3640
if DEBUG:
37-
print "__getattr__(%s)" % (name)
41+
print >>sys.stderr, "__getattr__(%s)" % (name)
3842

3943
# I should try to see if 'name' is a defined method
4044
# but it seems that if I call locals() here an infinite loop is entered
@@ -80,16 +84,24 @@ def __call__(self, *args, **kwargs):
8084
print "__call__(%s)" % (args if args else None)
8185

8286
def getXY(self):
87+
'''
88+
Returns the coordinates of this View
89+
'''
90+
8391
# FIXME: it's not always a CheckBox
84-
x = int(map['layout:mLeft']) + int(map['layout:layout_leftMargin']) + CHECK_BOX/2
85-
y = int(map['layout:mTop']) + int(map['layout:layout_topMargin']) + STATUS_BAR + TITLE + CHECK_BOX/2
92+
x = int(self.map['layout:mLeft']) + int(self.map['layout:layout_leftMargin']) + CHECK_BOX/2
93+
y = int(self.map['layout:mTop']) + int(self.map['layout:layout_topMargin']) + STATUS_BAR + TITLE + CHECK_BOX/2
8694
return (x, y)
8795

8896
# FIXME: should be MonkeyDevice.DOWN_AND_UP
89-
def touch(self, type="DOWN_AND_UP"):
97+
def touch(self, type="DOWN_AND_UP"):
98+
'''
99+
Touches this View
100+
'''
101+
90102
(x, y) = self.getXY()
91103
if DEBUG:
92-
print "should click @ (%d, %d)" % (x, y)
104+
print >>sys.stderr, "should click @ (%d, %d)" % (x, y)
93105
self.device.touch(x, y, type)
94106

95107
def allPossibleNamesWithColon(self, name):

0 commit comments

Comments
 (0)