Softkeyboard

Anything libgdx related goes here!

Softkeyboard

Postby japhias » Sat Apr 13, 2013 11:20 am

Hi all,

I have a few issues with the android onscreen-keyboard. I made the keyboard visible with Gdx.input.setOnscreenKeyboardVisible(true);
3 questions:
- Is it possible to switch the type of the keyboard? I need only numbers and no letters
- How can I set the textfield that will recieve the input?
- How can I catch the input of the keyboard?

Or is there any good documentation?

Thank you for help

Regards Jan
japhias
 
Posts: 16
Joined: Tue Apr 09, 2013 6:55 am

Re: Softkeyboard

Postby Ultroman » Tue Apr 16, 2013 6:49 am

You could try using InputEvent to register the keypresses.
Ultroman
 
Posts: 13
Joined: Tue Nov 20, 2012 3:45 am

Re: Softkeyboard

Postby japhias » Tue Apr 16, 2013 8:52 pm

Okay thanks, I think I can manage this.
But my main question: How to enable a number-keyboard?
japhias
 
Posts: 16
Joined: Tue Apr 09, 2013 6:55 am

Re: Softkeyboard

Postby Ultroman » Tue Apr 16, 2013 9:13 pm

I am sorry, but my Google-searching has not lead me to an answer to this very good question. I know it can be done in the regular Android API, but I'm not sure how that works inside libgdx, or if they've even got it on their list of things to implement. For a game-library, I don't think it's highest priority.

But this is from at person who is a semi-n00b at libgdx, so I may be talking out of my ass ^^
Ultroman
 
Posts: 13
Joined: Tue Nov 20, 2012 3:45 am

Re: Softkeyboard

Postby BurningHand » Tue Apr 16, 2013 9:23 pm

We currently provide no way to set the input type on the keyboard. I know how to make it work but haven't done it yet because it will take some rearranging of things.
IRC: nexsoftware / mobidevelop; GitHub: MobiDevelop;
BurningHand
 
Posts: 2812
Joined: Mon Oct 25, 2010 4:35 am

Re: Softkeyboard

Postby flogy » Sat Sep 06, 2014 11:07 pm

I noticed an issue with the soft keyboard on a HTC One X Plus device with Android 4.2.2:
Whenever a scene2d TextField is clicked, the soft keyboard that shows up has the last used keyboard input type. E.g. when a digits-only keyboard was used in another application before, it will show a digits-only type keyboard. If a QWERTY-keyboard was used last, it shows a QWERTY-keyboard. This is very nasty, since the player should enter his username in my app, which is hard when there are only digits to choose from :)

Therefore I was searching for a way to define the input type, just as the thread starter did. But I could not find a solution... According to this article, it is not possible to do so without using an Android UI EditText: http://stackoverflow.com/questions/1269 ... t-edittext

BurningHand wrote:We currently provide no way to set the input type on the keyboard. I know how to make it work but haven't done it yet because it will take some rearranging of things.


So, I was wondering if you remember how you would have made this work? Using the solution in the article above? Or some easier and cleaner way?

Thanks in advance,
flogy
flogy
 
Posts: 8
Joined: Thu Nov 14, 2013 10:21 am
Location: Switzerland

Re: Softkeyboard

Postby BurningHand » Sun Sep 07, 2014 4:35 am

I changed (in the Android backend) the options in the onCreateInputConnection where the IME options are set.
IRC: nexsoftware / mobidevelop; GitHub: MobiDevelop;
BurningHand
 
Posts: 2812
Joined: Mon Oct 25, 2010 4:35 am

Re: Softkeyboard

Postby flogy » Sun Sep 07, 2014 4:33 pm

Thanks for your reply.
I have now tested that by directly setting the IME to text type class (inside onCreateInputConnection in GLSurfaceViewAPI20 class:

Code: Select all
outAttrs.imeOptions = EditorInfo.TYPE_CLASS_TEXT;


Unfortunately, this did not work. Anyway, it would be great if that could be defined separately for each TextField element.

I think, I'll proceed using native Android UI elements for the text inputs for now.
flogy
 
Posts: 8
Joined: Thu Nov 14, 2013 10:21 am
Location: Switzerland

Re: Softkeyboard

Postby flogy » Wed Sep 10, 2014 9:32 pm

I gave that problem some more tries as I like scene2d UI a lot and don't really want to go for native Android UI (also because of the Desktop compatibility loss)...

So I thought about putting a hidden EditText field onto the screen, where I then could define the input type. When the user clicks on a scene2d TextField, the focus would be programmatically set to that hidden EditText, so the keyboard shows up. Finally, the key events need to be caught and the entered text is then filled back into the scene2d TextField.

After some research I found an old LibGDX github revision: https://github.com/libgdx/libgdx/commit ... bdf46cac3f where - as I understand - exactly that was tried (see also the now unused AndroidOnscreenKeyboard.java class)!

Now, my questions are:
- Does someone remember that AndroidOnscreenKeyboard class and knows if it ever worked, or why this approach was never pursued?
- I tried to implement this approach my own way and it all works to the point where I try to catch the key events. I tried to do that by setting AndroidInput as the EditText's OnKeyListener (as it is also done for the LibGDX view in AndroidInput's constructor). Later, I found out, setOnKeyListener does not work for the soft keyboard on all devices... That's why I wondered, why it does work in scene2d's TextField, since it is the exact same way to get the key events? Or might this be a so far undetected problem in scene2d?
flogy
 
Posts: 8
Joined: Thu Nov 14, 2013 10:21 am
Location: Switzerland

Re: Softkeyboard

Postby flogy » Fri Oct 10, 2014 12:14 am

I finally implemented the "hidden TextView" as a temporary fix for this problem: https://github.com/libgdx/libgdx/pull/2446
In long-term view I'd suggest to implement this mechanism using some interface that then can be implemented on iOS too.
flogy
 
Posts: 8
Joined: Thu Nov 14, 2013 10:21 am
Location: Switzerland


Return to Libgdx

Who is online

Users browsing this forum: Google [Bot], MSN [Bot] and 1 guest