From 10b93e7f6b0f0f801794ac672ea06926d6667c8c Mon Sep 17 00:00:00 2001 From: David Calvo Date: Mon, 17 Jun 2024 16:44:26 +0200 Subject: [PATCH 1/3] added Android Futo support --- kebbie/cmd.py | 6 ++-- kebbie/emulator.py | 77 +++++++++++++++++++++++++++++++++++++--------- 2 files changed, 66 insertions(+), 17 deletions(-) diff --git a/kebbie/cmd.py b/kebbie/cmd.py index e230fdd..4306285 100644 --- a/kebbie/cmd.py +++ b/kebbie/cmd.py @@ -31,7 +31,7 @@ def instantiate_correctors( Returns: The list of created Correctors. """ - if keyboard in ["gboard", "tappa", "swiftkey", "yandex"]: + if keyboard in ["gboard", "tappa", "swiftkey", "yandex", "futo"]: # Android keyboards return [ EmulatorCorrector( @@ -73,7 +73,7 @@ def common_args(parser: argparse.ArgumentParser): dest="keyboard", type=str, required=True, - choices=["gboard", "ios", "kbkitpro", "kbkitoss", "tappa", "fleksy", "swiftkey", "yandex"], + choices=["gboard", "ios", "kbkitpro", "kbkitoss", "tappa", "fleksy", "swiftkey", "yandex", "futo"], help="Which keyboard, to be tested, is currently installed on the emulator.", ) @@ -204,4 +204,4 @@ def cli(): # Save the keyboard elements to a file with open(args.page_source_file, "w", encoding="utf-8") as file: - file.write(page_source_str) + file.write(page_source_str) \ No newline at end of file diff --git a/kebbie/emulator.py b/kebbie/emulator.py index 60324ab..b46eac3 100644 --- a/kebbie/emulator.py +++ b/kebbie/emulator.py @@ -34,11 +34,13 @@ KBKITOSS = "kbkitoss" SWIFTKEY = "swiftkey" YANDEX = "yandex" +FUTO = "futo" KEYBOARD_PACKAGE = { GBOARD: "com.google.android.inputmethod.latin", SWIFTKEY: "com.touchtype.swiftkey", YANDEX: "ru.yandex.androidkeyboard", TAPPA: "com.tappa.keyboard", + FUTO: "org.futo.inputmethod.latin.playstore", } ANDROID_CAPABILITIES = { "platformName": "android", @@ -98,24 +100,42 @@ ] CONTENT_TO_RENAME = { "Shift": "shift", + "Mayús": "shift", + "More symbols": "shift", + "Keyboard Type - symbolic": "shift", + "Double tap for uppercase": "shift", + "Double tap for caps lock": "shift", + "Uppercase key.": "shift", + "Additional symbols.": "shift", "Delete": "backspace", "Backspace": "backspace", "Space": "spacebar", "space": "spacebar", "Space.": "spacebar", + "Espacio": "spacebar", + "Eliminar": "backspace", + "Delete.": "backspace", "Emoji button": "smiley", "Emoji": "smiley", + "Emojis": "smiley", "Keyboard Type - emojis": "smiley", "Search": "enter", "return": "enter", + "Return.": "enter", "Enter": "enter", - "Delete.": "backspace", + "Intro": "enter", + "Letter keyboard": "letters", + "Letters": "letters", + "Letras": "letters", + "Keyboard Type - auto": "letters", + "To letters.": "letters", "To symbols.": "numbers", - "Return.": "enter", + "Símbolos": "numbers", "Symbol keyboard": "numbers", "Symbols": "numbers", "Symbols and numbers": "numbers", "Keyboard Type - numeric": "numbers", + "Digit keyboard": "numbers", "Voice input": "mic", ",, alternatives available, Voice typing, long press to activate": "mic", "Close features menu": "magic", @@ -133,17 +153,7 @@ "Semicolon": ";", "Exclamation": "!", "Question mark": "?", - "Letter keyboard": "letters", - "Letters": "letters", - "Keyboard Type - auto": "letters", - "To letters.": "letters", - "Digit keyboard": "numbers", - "More symbols": "shift", - "Keyboard Type - symbolic": "shift", - "Double tap for uppercase": "shift", - "Double tap for caps lock": "shift", - "Uppercase key.": "shift", - "Additional symbols.": "shift", + "I mayúscula": "I", "capital Q": "Q", "capital W": "W", "capital E": "E", @@ -372,6 +382,9 @@ def __init__( # noqa: C901 elif self.keyboard == YANDEX: self.detected = YandexLayoutDetector(self.driver, self._tap) self.layout = self.detected.layout + elif self.keyboard == FUTO: + self.detected = FutoLayoutDetector(self.driver, self._tap) + self.layout = self.detected.layout else: raise ValueError( f"Unknown keyboard : {self.keyboard}. Please specify `{GBOARD}`, `{TAPPA}`, `{FLEKSY}`, " @@ -1168,6 +1181,42 @@ def get_suggestions(self) -> List[str]: return suggestions +class FutoLayoutDetector(LayoutDetector): + """Layout detector for the Futo keyboard. See `LayoutDetector` for more + information. + """ + + def __init__(self, *args, **kwargs): + super().__init__( + *args, + xpath_root=f"./*/*[@package='{KEYBOARD_PACKAGE[FUTO]}']", + xpath_keys=".//*[@class='android.inputmethodservice.Keyboard$Key'][@content-desc]", + **kwargs, + ) + + def get_suggestions(self) -> List[str]: + """Method to retrieve the keyboard suggestions from the XML tree. + + Returns: + List of suggestions from the keyboard. + """ + suggestions = [] + + # Get the raw content as text, weed out useless elements + for data in self.driver.page_source.split(" List[str]: if m: suggestions.append(html.unescape(m.group(1))) - return suggestions + return suggestions \ No newline at end of file From 4940b6c0faac3c77c86ce69b77e67a043fd5177a Mon Sep 17 00:00:00 2001 From: David Calvo Date: Mon, 17 Jun 2024 16:46:35 +0200 Subject: [PATCH 2/3] fixed lint --- kebbie/cmd.py | 2 +- kebbie/emulator.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/kebbie/cmd.py b/kebbie/cmd.py index 4306285..573be8e 100644 --- a/kebbie/cmd.py +++ b/kebbie/cmd.py @@ -204,4 +204,4 @@ def cli(): # Save the keyboard elements to a file with open(args.page_source_file, "w", encoding="utf-8") as file: - file.write(page_source_str) \ No newline at end of file + file.write(page_source_str) diff --git a/kebbie/emulator.py b/kebbie/emulator.py index b46eac3..aef5977 100644 --- a/kebbie/emulator.py +++ b/kebbie/emulator.py @@ -1204,8 +1204,8 @@ def get_suggestions(self) -> List[str]: # Get the raw content as text, weed out useless elements for data in self.driver.page_source.split(" List[str]: if m: suggestions.append(html.unescape(m.group(1))) - return suggestions \ No newline at end of file + return suggestions From 8c1709a69bfe513b33aa46028fac9acade22fbf2 Mon Sep 17 00:00:00 2001 From: David Calvo Date: Tue, 18 Jun 2024 07:55:43 +0200 Subject: [PATCH 3/3] coverage badge update --- .github/badges/coverage.svg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/badges/coverage.svg b/.github/badges/coverage.svg index 9029937..6c15cac 100644 --- a/.github/badges/coverage.svg +++ b/.github/badges/coverage.svg @@ -15,7 +15,7 @@ coverage coverage - 76% - 76% + 75% + 75%