Skip to content

Commit

Permalink
Make View.getXY() work w/ UIAutomator
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Matt Gumbel authored and intelmatt committed Dec 29, 2012
1 parent 45aa68e commit e252e19
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions AndroidViewClient/src/com/dtmilano/android/viewclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,22 +452,24 @@ def getXY(self):
hx = 0
hy = 0

if not self.useUiAutomator:
if DEBUG_COORDS: print >> sys.stderr, " getXY: not using UiAutomator, calculating parent coordinates"
while parent != None:
if DEBUG_COORDS: print >> sys.stderr, " getXY: parent: %s %s <<<<" % (parent.getClass(), parent.getId())
if SKIP_CERTAIN_CLASSES_IN_GET_XY_ENABLED:
if parent.getClass() in [ 'com.android.internal.widget.ActionBarView',
'com.android.internal.widget.ActionBarContextView',
'com.android.internal.view.menu.ActionMenuView',
'com.android.internal.policy.impl.PhoneWindow$DecorView' ]:
if DEBUG_COORDS: print >> sys.stderr, " getXY: skipping %s %s (%d,%d)" % (parent.getClass(), parent.getId(), parent.getX(), parent.getY())
parent = parent.parent
continue
if DEBUG_COORDS: print >> sys.stderr, " getXY: parent=%s x=%d hx=%d y=%d hy=%d" % (parent.getId(), x, hx, y, hy)
hx += parent.getX()
hy += parent.getY()
parent = parent.parent
if self.useUiAutomator:
return (x, y)

if DEBUG_COORDS: print >> sys.stderr, " getXY: not using UiAutomator, calculating parent coordinates"
while parent != None:
if DEBUG_COORDS: print >> sys.stderr, " getXY: parent: %s %s <<<<" % (parent.getClass(), parent.getId())
if SKIP_CERTAIN_CLASSES_IN_GET_XY_ENABLED:
if parent.getClass() in [ 'com.android.internal.widget.ActionBarView',
'com.android.internal.widget.ActionBarContextView',
'com.android.internal.view.menu.ActionMenuView',
'com.android.internal.policy.impl.PhoneWindow$DecorView' ]:
if DEBUG_COORDS: print >> sys.stderr, " getXY: skipping %s %s (%d,%d)" % (parent.getClass(), parent.getId(), parent.getX(), parent.getY())
parent = parent.parent
continue
if DEBUG_COORDS: print >> sys.stderr, " getXY: parent=%s x=%d hx=%d y=%d hy=%d" % (parent.getId(), x, hx, y, hy)
hx += parent.getX()
hy += parent.getY()
parent = parent.parent

(wvx, wvy) = self.__dumpWindowsInformation()
if DEBUG_COORDS:
Expand Down

0 comments on commit e252e19

Please sign in to comment.