Swipe from start to end coordinates. Args: start_x: Starting X coordinate. start_y: Starting Y coordinate. end_x: Ending X coordinate. end_y: Ending Y coordinate. duration_ms: Duration of swipe in milliseconds (auto-calculated if None). devic
(
start_x: int,
start_y: int,
end_x: int,
end_y: int,
duration_ms: int | None = None,
device_id: str | None = None,
delay: float | None = None,
)
| 159 | |
| 160 | |
| 161 | def swipe( |
| 162 | start_x: int, |
| 163 | start_y: int, |
| 164 | end_x: int, |
| 165 | end_y: int, |
| 166 | duration_ms: int | None = None, |
| 167 | device_id: str | None = None, |
| 168 | delay: float | None = None, |
| 169 | ) -> None: |
| 170 | """ |
| 171 | Swipe from start to end coordinates. |
| 172 | |
| 173 | Args: |
| 174 | start_x: Starting X coordinate. |
| 175 | start_y: Starting Y coordinate. |
| 176 | end_x: Ending X coordinate. |
| 177 | end_y: Ending Y coordinate. |
| 178 | duration_ms: Duration of swipe in milliseconds (auto-calculated if None). |
| 179 | device_id: Optional HDC device ID. |
| 180 | delay: Delay in seconds after swipe. If None, uses configured default. |
| 181 | """ |
| 182 | if delay is None: |
| 183 | delay = TIMING_CONFIG.device.default_swipe_delay |
| 184 | |
| 185 | hdc_prefix = _get_hdc_prefix(device_id) |
| 186 | |
| 187 | if duration_ms is None: |
| 188 | # Calculate duration based on distance |
| 189 | dist_sq = (start_x - end_x) ** 2 + (start_y - end_y) ** 2 |
| 190 | duration_ms = int(dist_sq / 1000) |
| 191 | duration_ms = max(500, min(duration_ms, 1000)) # Clamp between 500-1000ms |
| 192 | |
| 193 | # HarmonyOS uses uitest uiInput swipe |
| 194 | # Format: swipe startX startY endX endY duration |
| 195 | _run_hdc_command( |
| 196 | hdc_prefix |
| 197 | + [ |
| 198 | "shell", |
| 199 | "uitest", |
| 200 | "uiInput", |
| 201 | "swipe", |
| 202 | str(start_x), |
| 203 | str(start_y), |
| 204 | str(end_x), |
| 205 | str(end_y), |
| 206 | str(duration_ms), |
| 207 | ], |
| 208 | capture_output=True, |
| 209 | ) |
| 210 | time.sleep(delay) |
| 211 | |
| 212 | |
| 213 | def back(device_id: str | None = None, delay: float | None = None) -> None: |
nothing calls this directly
no test coverage detected