Skip to content

Commit

Permalink
Change default click position to close keyboard (#1374)
Browse files Browse the repository at this point in the history
If Image found on the website (big logo in the middle) take middle coords of that.
  • Loading branch information
JabLuszko authored and Grennith committed Dec 19, 2023
1 parent 333f639 commit 5719ef1
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions mapadroid/ocr/screenPath.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,18 @@ async def __handle_ptc_login(self) -> ScreenType:
bounds: str = ""
accept_x: Optional[int] = None
accept_y: Optional[int] = None
# On some resolutions (100, 100) position that MAD clicks by default to close keyboard
# ended on clicking Firefox SSL certifcate icon and it nuked whole flow by opening something else
# Changing it to (300, 300), but also detecting big logo image on website and taking this as new coords
exit_keyboard_x: int = 300
exit_keyboard_y: int = 300
for item in xmlroot.iter('node'):
if item.attrib["class"] == "android.widget.Image":
bounds = item.attrib['bounds']
match = re.search(r'^\[(\d+),(\d+)\]\[(\d+),(\d+)\]$', bounds)
logger.debug("Logo image Bounds {}", item.attrib['bounds'])
exit_keyboard_x = int(match.group(1)) + ((int(match.group(3)) - int(match.group(1))) / 2)
exit_keyboard_y = int(match.group(2)) + ((int(match.group(4)) - int(match.group(2))) / 2)
if item.attrib["resource-id"] == "email":
bounds = item.attrib['bounds']
logger.info("Found email/login field, clicking, filling, clicking")
Expand All @@ -471,7 +482,7 @@ async def __handle_ptc_login(self) -> ScreenType:
await self._communicator.click(int(click_x), int(click_y))
await asyncio.sleep(2)
await self._communicator.enter_text(self._worker_state.active_account.username)
await self._communicator.click(100, 100)
await self._communicator.click(exit_keyboard_x, exit_keyboard_y)
await asyncio.sleep(2)
if item.attrib["resource-id"] == "password":
bounds = item.attrib['bounds']
Expand All @@ -483,7 +494,7 @@ async def __handle_ptc_login(self) -> ScreenType:
await self._communicator.click(int(click_x), int(click_y))
await asyncio.sleep(2)
await self._communicator.enter_text(self._worker_state.active_account.password)
await self._communicator.click(100, 100)
await self._communicator.click(exit_keyboard_x, exit_keyboard_y)
await asyncio.sleep(2)
if item.attrib["resource-id"] == "accept":
bounds = item.attrib['bounds']
Expand Down

0 comments on commit 5719ef1

Please sign in to comment.