Skip to content

Commit

Permalink
added Android Futo support
Browse files Browse the repository at this point in the history
  • Loading branch information
QADavidCalvo committed Jun 17, 2024
1 parent 90d4a2c commit 10b93e7
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 17 deletions.
6 changes: 3 additions & 3 deletions kebbie/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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.",
)

Expand Down Expand Up @@ -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)
77 changes: 63 additions & 14 deletions kebbie/emulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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}`, "
Expand Down Expand Up @@ -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("<android.widget.FrameLayout"):
if f"{KEYBOARD_PACKAGE[FUTO]}" in data and "<android.view.View index=\"0\"" in data:
sections = data.split("<android.view.View index=\"0\"")
for section in sections:
m = re.search(r"content-desc=\"([^\"]*)\"", section)
if m:
content_desc = m.group(1)
if "Open Actions" not in content_desc and "Voice Input" not in content_desc:
suggestions.append(html.unescape(content_desc))
break

return suggestions


class FleksyLayoutDetector(LayoutDetector):
"""Layout detector for the Fleksy keyboard. See `LayoutDetector` for more
information.
Expand Down Expand Up @@ -1215,4 +1264,4 @@ def get_suggestions(self) -> List[str]:
if m:
suggestions.append(html.unescape(m.group(1)))

return suggestions
return suggestions

0 comments on commit 10b93e7

Please sign in to comment.