You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Support percentage-based coordinates for input actions
This commit updates the application to support percentage-based coordinates (e.g., "50%", "25.5%") in addition to pixel-based coordinates for various input actions like `tapAtCoordinate` and coordinate-based scroll commands.
Changes include:
- Modified `Command.kt` to store coordinate values as Strings in relevant command data classes (`TapCoordinates`, `ScrollDownFromCoordinates`, etc.).
- Updated `CommandParser.kt` to correctly parse these string coordinates, including those with a '%' suffix. Regex patterns and parsing logic were adjusted accordingly.
- Introduced a `convertCoordinate(String, Int): Float` helper method in `ScreenOperatorAccessibilityService.kt` to convert coordinate strings (either pixel or percentage) into absolute pixel values based on screen dimensions.
- Updated the `executeCommand` method in `ScreenOperatorAccessibilityService.kt` to use `convertCoordinate` before dispatching actions.
- Added comprehensive unit tests for the new parsing logic in `CommandParserTest.kt` and for the `convertCoordinate` method in `ScreenOperatorAccessibilityServiceTest.kt`, covering various valid inputs, percentages, pixel values, and error conditions.
This enhancement provides you with greater flexibility when specifying coordinates for screen interactions.
val xPx = serviceInstance!!.convertCoordinate(command.x, screenWidth)
165
+
val yPx = serviceInstance!!.convertCoordinate(command.y, screenHeight)
166
+
Log.d(TAG, "Scrolling down from coordinates (${command.x} -> $xPx, ${command.y} -> $yPx) with distance ${command.distance} and duration ${command.duration}ms")
167
+
showToast("Trying to scroll down from position ($xPx, $yPx)", false)
val xPx = serviceInstance!!.convertCoordinate(command.x, screenWidth)
172
+
val yPx = serviceInstance!!.convertCoordinate(command.y, screenHeight)
173
+
Log.d(TAG, "Scrolling up from coordinates (${command.x} -> $xPx, ${command.y} -> $yPx) with distance ${command.distance} and duration ${command.duration}ms")
174
+
showToast("Trying to scroll up from position ($xPx, $yPx)", false)
val xPx = serviceInstance!!.convertCoordinate(command.x, screenWidth)
179
+
val yPx = serviceInstance!!.convertCoordinate(command.y, screenHeight)
180
+
Log.d(TAG, "Scrolling left from coordinates (${command.x} -> $xPx, ${command.y} -> $yPx) with distance ${command.distance} and duration ${command.duration}ms")
181
+
showToast("Trying to scroll left from position ($xPx, $yPx)", false)
val xPx = serviceInstance!!.convertCoordinate(command.x, screenWidth)
186
+
val yPx = serviceInstance!!.convertCoordinate(command.y, screenHeight)
187
+
Log.d(TAG, "Scrolling right from coordinates (${command.x} -> $xPx, ${command.y} -> $yPx) with distance ${command.distance} and duration ${command.duration}ms")
188
+
showToast("Trying to scroll right from position ($xPx, $yPx)", false)
0 commit comments