-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
make the virtual keyboard accept various languages #2015
Conversation
@@ -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; |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering that:
-
TYPE_CLASS_TEXT equals 1.
-
TYPE_TEXT_VARIATION_NORMAL equals 0.
Then 1 | 0 = 1
, so I think it's a good idea to remove TYPE_TEXT_VARIATION_NORMAL
:
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering that:
-
TYPE_CLASS_TEXT equals 1.
-
TYPE_TEXT_VARIATION_NORMAL equals 0.
Then 1 | 0 = 1
, so I think it's a good idea to remove TYPE_TEXT_VARIATION_NORMAL
:
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.
I confirmed that. The cause probably is because 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()
If you look at the source, you can see there is no code that listening to So I believe |
Nice! I tested it and, as you told, Also, I realised that 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. |
Thanks. |
@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. |
@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. |
@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. |
close the pr due to #2057 |
Do you mean I have to register my downloaded font before I can use the emoji in it? |
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.