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

SoftInput (Software Keyboard) support #1823

Open
Tracked by #64 ...
semtexzv opened this issue Jan 10, 2021 · 15 comments
Open
Tracked by #64 ...

SoftInput (Software Keyboard) support #1823

semtexzv opened this issue Jan 10, 2021 · 15 comments
Labels
DS - android S - api Design and usability

Comments

@semtexzv
Copy link
Contributor

On android, the application should be able to request showing & hiding of soft input.

This is available through ndk_glue for android.

But this strangely feels like functionality that should be attached to window.
eg. for desktop we have cursor grabbing, for mobile, having methods for showing keyboard seems similar.

@msiglreith msiglreith added DS - android S - api Design and usability labels Jan 20, 2021
@torokati44
Copy link
Contributor

Yeah, this would be really useful. Especially since so far I have been completely unable to pop up the virtual keyboard on winit's NativeActivity.
I does not appear when addingandroid:windowSoftInputMode="stateAlwaysVisible|adjustResize" to the <activity> entry in AndroidManifest.xml, nor when calling ndk_glue::native_activity().show_soft_input(true); from Rust.

@Fancyflame
Copy link

So... does any guy have any ideas? ndk_glue::native_activity() is deprecated, it says using ndk_context::android_context().vm() instead, but what next? I'm a noob at Android programming.

@msiglreith
Copy link
Member

Not sure what's up with the NDK function but here is an example going trough jni: https://github.com/msiglreith/pixels-android/blob/master/src/lib.rs#L30 which shows the keyboard when tapping the screen.
It uses current main branch as virtual keycode have just been added recently for Android, otherwise it will just return empty ):

@Fancyflame
Copy link

This example can work on my device. But do you mean this method has a compatibility problem?

@msiglreith
Copy link
Member

Sry, I referred to the Android winit platform implementation not Android itself: #2226
Should work with older Android versions as well

@Fancyflame
Copy link

Thanks. That's okay if it only needs update winit to the latest version. 😃
To be honest, I cannot understand what you wrote due to my lack of knowledge about Android and Java.... Can I copy your implementation to my project? I'll mark your repo.

@Fancyflame
Copy link

@msiglreith Then, how to hide it?

@msiglreith
Copy link
Member

Can I copy your implementation to my project?

Feel free. I will probably look into opening a PR for this in the next days if there are no further issues with the JNI implementation.

Then, how to hide it?

I pushed a small change in the meantime to the repository from above which implements it (hides when tapping the screen again).

@Fancyflame
Copy link

@msiglreith Thanks for your example. I'm sorry for bothering you again, but... I have another two questions:

  • How to popup and hide safe keyboard on Android for password input, just like <input type="password"> does in HTML?
  • How to prevent the IME from popping up sometimes when press keys on PC (Windows 10)? (Sorry if not related to this issue)

屏幕截图 2022-04-29 013655

@msiglreith
Copy link
Member

How to popup and hide safe keyboard on Android for password input, just like does in HTML?

I think that's more tricky and not something which can be easily implemented. I would assume creating a custom View which will set the corresponding input type but that requires interfacing/compiling Java, which would require support on the tooling front in general...

How to prevent the IME from popping up sometimes when press keys on PC (Windows 10)? (Sorry if not related to this issue)

I haven't tried IME myself - you might want to look at #2243 which seems to add more functionality for it (in particular enabling/disabling IME)

@ElhamAryanpur
Copy link

are there any plans for implementation? workarounds posted here doesn't work anymore either

@madsmtm
Copy link
Member

madsmtm commented Apr 2, 2024

There's been some progress on iOS in #3571, and some progress on Android in #2993, and finally we've been having some discussion with the Xilem folks about it. I think there are vague plans to work on it in/post v0.31, but that's all I can say.

@kchibisov
Copy link
Member

I'd add that if people are willing to put work into it, I'm all for having it. It's just should be just a little bit consistent with the rest of IME we have around, but that's about it.

@ElhamAryanpur
Copy link

I see, I'd love to help but I honestly don't know anything about JNI. will look further to see if theres some parts I can contribute to. Thank you!

@mvvvv
Copy link

mvvvv commented May 6, 2024

I tested the Android keyboard launched via JNI on the Meta Quest2. It works exactly like any Android device.
https://github.com/mvvvv/StereoKit-rust/blob/master/src/tools/os_api.rs#L191

Indeed winit 0.30 blocks many characters including accented characters which it replaces completely with a backspace and erases the character typed previously. I made a short video: https://youtu.be/os8cucfF3D8

If you need to test I have an environment for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DS - android S - api Design and usability
Development

No branches or pull requests

8 participants