Skip to content

Commit e252e19

Browse files
Matt Gumbelintelmatt
authored andcommitted
Make View.getXY() work w/ UIAutomator
UIAutomator xml file returns bounds of view in global (screen) coords, not relative to parent window(s), view(s), or statusbar. View.getXY() is adapted to not do coordinate translation when UIAutomator is being used. Tests done: 4.2.0 nexus phone - sample-ui-toggle-buttons.py 4.2.0 nexus phone - apidemos-app-alert_dialog-list_dialog-command_three.py 4.2.0 nexus phone - browser-open-url.py (Fails both with and without patch) 4.2.0 nexus phone - development-settings-show-running-processes.py (Fails both with and without patch) 4.2.0 emulator - sample-ui-toggle-buttons.py 4.0.3 emulator - sample-ui-toggle-buttons.py 4.0.3 emulator - apidemos-app-alert_dialog-list_dialog-command_three.py 4.0.3 emulator - browser-open-url.py 4.0.3 emulator - development-settings-show-running-processes.py Signed-off-by: Matt Gumbel <[email protected]>
1 parent 45aa68e commit e252e19

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

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

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -452,22 +452,24 @@ def getXY(self):
452452
hx = 0
453453
hy = 0
454454

455-
if not self.useUiAutomator:
456-
if DEBUG_COORDS: print >> sys.stderr, " getXY: not using UiAutomator, calculating parent coordinates"
457-
while parent != None:
458-
if DEBUG_COORDS: print >> sys.stderr, " getXY: parent: %s %s <<<<" % (parent.getClass(), parent.getId())
459-
if SKIP_CERTAIN_CLASSES_IN_GET_XY_ENABLED:
460-
if parent.getClass() in [ 'com.android.internal.widget.ActionBarView',
461-
'com.android.internal.widget.ActionBarContextView',
462-
'com.android.internal.view.menu.ActionMenuView',
463-
'com.android.internal.policy.impl.PhoneWindow$DecorView' ]:
464-
if DEBUG_COORDS: print >> sys.stderr, " getXY: skipping %s %s (%d,%d)" % (parent.getClass(), parent.getId(), parent.getX(), parent.getY())
465-
parent = parent.parent
466-
continue
467-
if DEBUG_COORDS: print >> sys.stderr, " getXY: parent=%s x=%d hx=%d y=%d hy=%d" % (parent.getId(), x, hx, y, hy)
468-
hx += parent.getX()
469-
hy += parent.getY()
470-
parent = parent.parent
455+
if self.useUiAutomator:
456+
return (x, y)
457+
458+
if DEBUG_COORDS: print >> sys.stderr, " getXY: not using UiAutomator, calculating parent coordinates"
459+
while parent != None:
460+
if DEBUG_COORDS: print >> sys.stderr, " getXY: parent: %s %s <<<<" % (parent.getClass(), parent.getId())
461+
if SKIP_CERTAIN_CLASSES_IN_GET_XY_ENABLED:
462+
if parent.getClass() in [ 'com.android.internal.widget.ActionBarView',
463+
'com.android.internal.widget.ActionBarContextView',
464+
'com.android.internal.view.menu.ActionMenuView',
465+
'com.android.internal.policy.impl.PhoneWindow$DecorView' ]:
466+
if DEBUG_COORDS: print >> sys.stderr, " getXY: skipping %s %s (%d,%d)" % (parent.getClass(), parent.getId(), parent.getX(), parent.getY())
467+
parent = parent.parent
468+
continue
469+
if DEBUG_COORDS: print >> sys.stderr, " getXY: parent=%s x=%d hx=%d y=%d hy=%d" % (parent.getId(), x, hx, y, hy)
470+
hx += parent.getX()
471+
hy += parent.getY()
472+
parent = parent.parent
471473

472474
(wvx, wvy) = self.__dumpWindowsInformation()
473475
if DEBUG_COORDS:

0 commit comments

Comments
 (0)