diff --git a/snippet_uiautomator/android/app/src/main/java/com/google/android/mobly/snippet/uiautomator/UiObject2Snippet.java b/snippet_uiautomator/android/app/src/main/java/com/google/android/mobly/snippet/uiautomator/UiObject2Snippet.java index ae28910..3e4d58d 100644 --- a/snippet_uiautomator/android/app/src/main/java/com/google/android/mobly/snippet/uiautomator/UiObject2Snippet.java +++ b/snippet_uiautomator/android/app/src/main/java/com/google/android/mobly/snippet/uiautomator/UiObject2Snippet.java @@ -302,12 +302,34 @@ public boolean pinchOpen(Selector selector, int percent, @RpcOptional Integer sp @Rpc(description = "Performs a scroll gesture in pixels per second on this object.") public boolean scroll( - Selector selector, String directionStr, int percent, @RpcOptional Integer speed) + Selector selector, + String directionStr, + int percent, + @RpcOptional Integer speed, + @RpcOptional Integer gestureMargin, + @RpcOptional Integer gestureMarginPercent) throws SelectorException { - Direction direction = Direction.valueOf(directionStr); - return speed == null - ? operate(selector, uiObject2 -> uiObject2.scroll(direction, percent / 100f)) - : operate(selector, uiObject2 -> uiObject2.scroll(direction, percent / 100f, speed)); + final Direction direction = Direction.valueOf(directionStr); + final UiObject2 uiObject2 = selector.toUiObject2(); + if (uiObject2 == null) { + return false; + } + if (gestureMargin != null) { + Log.i("Setting gesture margin to " + gestureMargin); + uiObject2.setGestureMargin(gestureMargin); + } else if (gestureMarginPercent != null) { + Log.i("Setting gesture margin percentage to " + gestureMarginPercent); + uiObject2.setGestureMarginPercentage(gestureMarginPercent / 100f); + } + try { + if (speed == null) { + return uiObject2.scroll(direction, percent / 100f); + } else { + return uiObject2.scroll(direction, percent / 100f, speed); + } + } finally { + uiObject2.recycle(); + } } @Rpc(description = "Scrolls to the end of a scrollable layout element.") diff --git a/snippet_uiautomator/android/app/uiautomator.apk b/snippet_uiautomator/android/app/uiautomator.apk index 45f2ecc..5285d8a 100644 Binary files a/snippet_uiautomator/android/app/uiautomator.apk and b/snippet_uiautomator/android/app/uiautomator.apk differ diff --git a/snippet_uiautomator/uiobject2.py b/snippet_uiautomator/uiobject2.py index 2d7b18a..0f477b8 100644 --- a/snippet_uiautomator/uiobject2.py +++ b/snippet_uiautomator/uiobject2.py @@ -321,7 +321,12 @@ def __call__( ) elif percent is not None and not kwargs: return self._ui.scroll( - self._selector.to_dict(), self._direction, percent, speed + self._selector.to_dict(), + self._direction, + percent, + speed, + self._margin, + self._percent, ) else: raise errors.ApiError(