Skip to content

make the virtual keyboard accept various languages #2015

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

Closed
wants to merge 1 commit into from
Closed

make the virtual keyboard accept various languages #2015

wants to merge 1 commit into from

Conversation

gottadiveintopython
Copy link
Member

@gottadiveintopython gottadiveintopython commented Nov 1, 2019

Currently, Japanese (and Chinese) keyboard doesn't show up on Android 9. (I don't know about other versions, but at least it does show up on Android 5.0.3). This PR fix it.

Please take a look at this discussion.

@@ -2002,7 +2002,7 @@ public boolean onKeyPreIme (int keyCode, KeyEvent event) {
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
ic = new SDLInputConnection(this, true);

outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does TYPE_TEXT_VARIATION_NORMAL really have to be explicit? According to Android documentation, it is the default variation of TYPE_CLASS_TEXT.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, it doesn't have to be. I'll test it when I have time.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering that:

Then 1 | 0 = 1, so I think it's a good idea to remove TYPE_TEXT_VARIATION_NORMAL:

Suggested change
outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL;
outAttrs.inputType = InputType.TYPE_CLASS_TEXT;

By the way, keyboards with predictive text have a non-desirable behavior with this PR: written text (containing just letters) does not appear in TextInput. Only symbols, numbers, and text selected from suggested words are visible.

Test it and tell me if you can reproduce the bug, please. I'll try to fix it.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can reproduce the bug.

I do not see any difference in behavior with or without TYPE_TEXT_VARIATION_NORMAL

When prediction is provided, the text does not appear in the TextInput until it is selected from the bar or "confirmed" with space character. Only some keyboard, like Swiftkey, selects the word on space character, others do not (Gboard?).
In most of the cases, on backspace, the text is first deleted from this invisible "buffer" and then from the TextInput.
Symbols and numbers behavior varies depending on a keyboard and whether the keyboard tries to predict numeric input.

Swipe on Swiftkey keyboard inserts the word twice, Gboard does not inserts anything (or inserts a space character? maybe it has something to do with the space character behavior)

@@ -2002,7 +2002,7 @@ public boolean onKeyPreIme (int keyCode, KeyEvent event) {
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
ic = new SDLInputConnection(this, true);

outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering that:

Then 1 | 0 = 1, so I think it's a good idea to remove TYPE_TEXT_VARIATION_NORMAL:

Suggested change
outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL;
outAttrs.inputType = InputType.TYPE_CLASS_TEXT;

By the way, keyboards with predictive text have a non-desirable behavior with this PR: written text (containing just letters) does not appear in TextInput. Only symbols, numbers, and text selected from suggested words are visible.

Test it and tell me if you can reproduce the bug, please. I'll try to fix it.

@gottadiveintopython
Copy link
Member Author

gottadiveintopython commented Dec 8, 2019

keyboards with predictive text have a non-desirable behavior with this PR

I confirmed that. The cause probably is because TextInput doesn't listen to on_texteditevent. I ran the following code on Android:

from kivy.app import App
from kivy.lang import Builder
from kivy.factory import Factory

KV_CODE = '''
BoxLayout:
    TextInput:
    Button:
'''

class SampleApp(App):
    def build(self):
        return Builder.load_string(KV_CODE)
    def on_start(self):
        from kivy.core.window import Window
        Window.bind(
            on_textedit=lambda __, text: print('on_textedit:', text),
            on_textinput=lambda __, text: print('on_textinput:', text),
            )

if __name__ == '__main__':
    SampleApp().run()
  1. I typed e. The text didn't appear but on_textedit: e was printed.
  2. Then I typed r. The text still didn't appear but on_textedit: er was printed.
  3. Then I selected error, one of suggestions. error appeared and on_textinput: error and on_textinput: were printed.
# over all prints
on_textedit: e
on_textedit: er
on_textinput: error
on_textinput:

If you look at the source, you can see there is no code that listening to on_textedit. Only on_textinput is listened to. That's why the text doesn't appear until the user finalize(commit) it.

So I believe TextInput needs quite change.

@ghost
Copy link

ghost commented Dec 8, 2019

Nice! I tested it and, as you told, on_textedit is the responsible. I'll take a look on how to implement it on textinput.py and focus.py.

Also, I realised that with TYPE_CLASS_TEXT you can insert emojis, but after doing it, the app crashes with:

File "kivy/core/window/_window_sdl2.pyx", line 682, in kivy.core.window._window_sdl2._WindowSDL2Storage.poll
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xed in position 0: invalid continuation byte

I tried with multiple emojis and I always get the same error.

@gottadiveintopython
Copy link
Member Author

gottadiveintopython commented Dec 8, 2019

Thanks. SDL_TEXTEDITING brings two arguments, which currently being ignored. That might be related to that error.
https://github.com/kivy/kivy/pull/6498/files
I'll test it tomorrow.

@gottadiveintopython
Copy link
Member Author

@franccisco I can't reproduce the error. Emojis appear as tofu but no error. It might depends on the OS. Which version do you use? Mine is Fire OS 7, which derived from Android 9.

@ghost
Copy link

ghost commented Dec 30, 2019

@gottadiveintopython Yes, it depends on the OS version. In older Android versions, the app crashes.

Well, there are two issues that needs fix at the moment: keyboard suggestions and emojis.

@ghost
Copy link

ghost commented Jan 5, 2020

@gottadiveintopython The tofu you're watching is because the font used by Kivy (Roboto, unless you changed it) does not support emojis. There are some fonts that already do (I think Noto is useful in this case, as it supports emojis and is a font intended for all languages). As far as I know, Kivy only allows to register the regular, italic and bold variations of a font (https://github.com/kivy/kivy/blob/b1c643c8a6d3d4750dc2fa9a0232354dfcecd3a1/kivy/core/text/__init__.py#L291), so this file may need a modification too.

@gottadiveintopython
Copy link
Member Author

close the pr due to #2057

@Azag3077
Copy link

@gottadiveintopython The tofu you're watching is because the font used by Kivy (Roboto, unless you changed it) does not support emojis. There are some fonts that already do (I think Noto is useful in this case, as it supports emojis and is a font intended for all languages). As far as I know, Kivy only allows to register the regular, italic and bold variations of a font (https://github.com/kivy/kivy/blob/b1c643c8a6d3d4750dc2fa9a0232354dfcecd3a1/kivy/core/text/__init__.py#L291), so this file may need a modification too.
Hi....

Do you mean I have to register my downloaded font before I can use the emoji in it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants