Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Futo Android keyboard #40

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 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
75 changes: 62 additions & 13 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