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

LibGDX's Android Keyboard input not working with the "Samsung Keyboard" #3896

Closed
1 of 6 tasks
AshGDS opened this issue Mar 3, 2016 · 51 comments
Closed
1 of 6 tasks

Comments

@AshGDS
Copy link

AshGDS commented Mar 3, 2016

Issue details

On Samsung's keyboard, there is a glitch where it does not process the command InputType.NULL sent by the Android App and therefore shows predictive text above the keyboard, which breaks LibGDX's keyboard input.

I think this may be temporarily fixed if we can modify the InputType of the on screen keyboard. This would allow us to set the keyboard's input type as a visible password, which would prevent predictive text appearing.

I know this is not necessarily an issue with LibGDX, it is more Samsung's issue. It was reported to Samsung a while ago but I don't think they will be fixing it anytime soon.

Reproduction steps/code

Create a game that uses an InputProcessor to receive keyboard input.

Load the game on a Samsung Galaxy S5, S6, S6 Edge or Note 5 that uses the Samsung Keyboard app. Make sure predictive text is enabled on the keyboard settings.

Try to type something and no input will be registered.

Version of LibGDX and/or relevant dependencies

Please provide the version(s) affected.
I have only tested with 1.6 and 1.9.3

Please select the affected platforms

  • Android
  • iOS
  • HTML/GWT
  • Windows
  • Linux
  • MacOS
@bazola
Copy link

bazola commented Mar 15, 2016

I've just run into this issue on the S7. If you tap on the checkmark or one of the other options in the predictive text, the text will be input into the TextField, but otherwise nothing shows up.

@danielbse
Copy link

I have this issue aswell. Text appears when using the keyboard on Android Studios emulator but on my Phone, a S6 Edge you have to hit enter for it to show up.

@emmett-deen
Copy link

I also have this issue on my note 5. Please lmk if you guys find a work around or a fix is released. I think this is very important because a large amount of android users are on Samsung devices.

@AshGDS
Copy link
Author

AshGDS commented Apr 3, 2016

Yesterday I tried to contact Samsung via twitter about it but I think I confused them...we might get a better response if more people enquire them about it:

https://twitter.com/AshleyABurnett/status/716392983986315264

As for a fix through LibGDX:I'm not sure I did this properly but I tried to edit the AndroidInput.java in gdx-backend-android,jar and append this code to the EditText variable called "input":

input.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);

I got that code from this answer: http://stackoverflow.com/a/16997434

However that did not work. I'm sure I did it incorrectly though because all I did was extract the class using 7-zip, edit it and then re-add it to the .jar using 7-zip.

@intrigus
Copy link
Contributor

intrigus commented Apr 3, 2016

As a workaround you can use Reflection to get the AndroidOnscreenKeyboard from

private final AndroidOnscreenKeyboard onscreenKeyboard;

than you can get the TextView from

and than you can set the input type on it (also via reflection).

@emmett-deen
Copy link

@intrigus could you give us a code example? I dont understand what you mean by use reflection. Thanks so much!

@sjosegarcia
Copy link

The reflection api allows you to manipulate classes in real time. So he
wants you to use the reflection api and get that variable.
On Apr 3, 2016 7:12 PM, "Emmett" notifications@github.com wrote:

@intrigus https://github.com/intrigus could you give us a code example?
I dont understand what you mean by use reflection. Thanks so much!


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#3896 (comment)

@AshGDS
Copy link
Author

AshGDS commented Apr 4, 2016

Thanks for the advice, at least we know a solution is possible now. I'm new to the reflection API and I can't seem to get it to work properly. The furthest I got was with this error:

Error: java.lang.Class<com.badlogic.gdx.backends.android.AndroidOnscreenKeyboard> is not accessible from java.lang.Class<com.ash98.game.android.AndroidLauncher>

Here is my amateur code that I put in the onCreate() method of AndroidLauncher.java

 try {
 AndroidInput input = new AndroidInput(this, this.getContext(), this.gameView, config);
 Field field = input.getClass().getDeclaredField("onscreenKeyboard");
 field.setAccessible(true);
 Class c = field.getType();
 Constructor constructor = c.getDeclaredConstructor(Context.class, Handler.class, AndroidInput.class);
 Object o = c.newInstance();
 Field textView = o.getClass().getDeclaredField("textView");
 textView.setAccessible(true);
 TextView text = new TextView(this);
 text.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
 textView.set(text, o);
 } catch (Throwable e) {
 System.out.println("Error: " + e.getMessage());
 }

@intrigus
Copy link
Contributor

intrigus commented Apr 4, 2016

My fault, AndroidOnscreenKeyboard isn't used at all.
I know a workaround but this means that you'll have to work with the source.

I'm going to post this workaround tomorrow.

Anyway, libgdx should update its input mechanism.

@AshGDS
Copy link
Author

AshGDS commented Apr 4, 2016

Thanks, looking forward to the fix, might put an end to the 1 star reviews on my game.

@intrigus
Copy link
Contributor

intrigus commented Apr 5, 2016

Try adding

outAttrs.inputType = InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD  | InputType.TYPE_NULL;

right after https://github.com/libgdx/libgdx/blob/master/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLSurfaceView20API18.java#L74
so it should be

if (outAttrs != null) {
    outAttrs.imeOptions = outAttrs.imeOptions | EditorInfo.IME_FLAG_NO_EXTRACT_UI;
    if(isSamsungKeyboard()){            
        outAttrs.inputType = InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD  | InputType.TYPE_NULL;
    }
}

Do the same here.

Have a look at http://stackoverflow.com/a/14371088 to see how you can implement a isSamsungKeyboard() method.

It may be possible that this also doesn't work. In this case you are currently out of luck.
You could ask your users to change their default IME.

If you don't have access to a Samsung device you can try http://developer.samsung.com/remotetestlab/rtlDeviceList.action

@AshGDS
Copy link
Author

AshGDS commented Apr 5, 2016

Thanks for the help again. I tried to implement it. I didn't use an isSamsungKeyboard() method as this is just a test build, but I couldn't get it to work using the S7. I had been using remote test lab previously but thanks for the advice.

All I'm doing is extracting the relevant classes out of the gdx-backend-android-1.6.0-sources.jar using 7-zip, editing the code in the classes, and then dragging the files back in. Then I go into my project structure and change the gdx-backend-android-1.6.0-sources.jar on the Android module in IntelliJ to the one I modified. Is this the correct way to edit the source? I'm assuming this isn't, it seems too easy.

@intrigus
Copy link
Contributor

intrigus commented Apr 5, 2016

Have a look at the wiki, there should be an article "Working with the source".
Do what they say. To check if it works you can than run gdx-tests-android. If this works, you can directly edit the source. Not sure if it works with IntelliJ you might have to use Eclipse.
I'll try to find a better solution, but I'm busy :)

@congatobu
Copy link

congatobu commented Apr 26, 2016

Thanks intrigus

I edit two class GLSurfaceView20API18.class, GLSurfaceView20.class at com.badlogic.gdx.backends.android.surfaceview
add
outAttrs.inputType = InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD | InputType.TYPE_NULL;

if (outAttrs != null) {
outAttrs.imeOptions = outAttrs.imeOptions | EditorInfo.IME_FLAG_NO_EXTRACT_UI;
outAttrs.inputType = InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD | InputType.TYPE_NULL;

}
and it work.

@AshGDS
Copy link
Author

AshGDS commented Apr 26, 2016

congatobu, i'm assuming you worked with the libgdx source?

@congatobu
Copy link

@Ash98
I work with libgdx source.

@carlislefox
Copy link

Is there any news on this being fixed in libgdx itself? Text input is broken on a lot of devices, does this have any priority? If not I can take a crack at it next week.

@Aperico-com
Copy link

A fix for this would be great since it affect most of the newer Samsung phones and getting a 1-star rating because users can not even create an account and login is no good. The best would be if you can set a per TextField input type (android:inputMethod) instead of for all input as the suggestion above.

@carlislefox
Copy link

carlislefox commented Jan 14, 2017

So I've hacked around this for my own game but its messy as hell... is there any initiative in the LibGDX team to upgrade the Keyboard support? I feel like its a real thorn in the side of an otherwise excellent set of API.

Even if it's just to implement the workaround congatobu highlighted? I dislike working from source as you are then forever out of sync with the core project.

@johnnyapol
Copy link
Member

I'm coming out of the silence for a moment to weigh in here. The problem with Android in general, especially the input backend, is the sheer amount of fragmentation. Like, this doesn't happen with the Google Keyboard, but Samsung has to break things (not much of a surprise here.) It doesn't mean it is acceptable because as you all have pointed out, users don't want to switch their keyboard for a game.

The fragmentation, sadly, goes both ways - before we can deploy a fix in the master branch, we need to ensure that we don't break things further or cause other major changes. Breaking input is a big deal. It's a little bit of a Catch-22. (You can argue that input is already broken but that's a different subject matter).

I can try to integrate @congatobu 's suggestion in my local testing branch and see what it does but I'd have to borrow my friend's phone since I lack a Samsung phone. However, I've been away from the project for a long time so it would be better if a core member could look into it.

In conclusion, we'd love to fix and streamline input, it's just one of those things where you patch one things around and another issue arises.

@johnnyapol johnnyapol added the bug label Jan 15, 2017
@carlislefox
Copy link

carlislefox commented Jan 15, 2017

Thanks for taking the time to write up such a detailed response, I understand and agree with you completely.

In my eyes I would say the current keyboard issue with the auto-complete on Samsung phones should be viewed as a severe input issue as it literally makes the keyboard totally unusable.

From my perspective if the submitted workaround in this ticket does what it says on the tin, if that could make it into master I'd be over the moon and happy for this ticket to be closed. As someone earlier in the thread posted, its pretty heartbreaking to have people one star rating your app because they can't create an account >.<

I get that a lot of games likely don't have keyboard input so its an easy issue to sideline, but in my case my game is an MMO so communication is a big part of the experience, I have gotten fairly hammered on this issue and its such a silly thing to let the experience down :(

This is the only issue I personally have with LibGDX right now that is affecting end users so I am massively biased towards it being addressed, if someone official could find the time to have a look I would give you all the cookies.

Liam

@hoboris
Copy link

hoboris commented Mar 2, 2017

Is there some update regarding fixing this issue with congatobu's workaround? Samsung represents the majority of Android phones, so it is a bit crippling to have all the games using a keyboard that don't work on these phones.

@mitrakov
Copy link

mitrakov commented Aug 8, 2017

The solution suggested by @intrigus indeed works well (I added flag TYPE_TEXT_VARIATION_VISIBLE_PASSWORD and re-build LibGDX from sources).
But it works until a user changes the language! After switching the language Samsung Keyboard again pops up suggestions and everything breaks down again.
If a user hides the keyboard and gets it shown again, it starts to work again until switching the language.

Are there workaround for this?

@Emperorlou
Copy link
Contributor

It's 2020 and I'm getting reports of this issue still happening from my users. Is it a regression? All the comments here ended in 2017!

@carlislefox
Copy link

This is still a massive issue to be honest, I think I lose a lot of players simply because they can't create an Account.

It's on my whiteboard now so I will be looking into fixing it in the coming weeks, if I remember correctly it requires a complete rework of how keyboard input works on Android which should be fun ._.

@carlislefox
Copy link

carlislefox commented Apr 18, 2020

Alright, going back over this thread I saw there was a workaround posted that was not implemented due to hesitation around it causing other issues.

With that in mind, I have a playerbase of around 50k active users and I figured screw it, so I've put congatobu's fix in to my own fork of 1.9.6 and gave it to my users to test if they wanted.

I've had over 500 players test the client with this change and none have had keyboard issues - I appreciate the caution around putting things in but this looks fine, fixes a really problematic issue with the keyboard for a broad range of devices and really should just go in.

I'll submit a merge request shortly - commence finger crossing.

Edit: I see the issue you have highlighted with the fix being reverted once a language change occurs mitrakov, I'll take a look.

@Emperorlou
Copy link
Contributor

Emperorlou commented Apr 18, 2020 via email

@Emperorlou
Copy link
Contributor

@carlislefox Any update on the status of this?

@bitdream
Copy link

It's year 2020 but it's still there...

@Emperorlou
Copy link
Contributor

I thought more people were using this game engine tbh

@bitdream
Copy link

I just made a decision... using urgly Gdx.input.getText() when detected phone is from Samsung otherwise the normal way. @carlislefox I am waiting for you saving me from this urgly solution😢

@wheelergames
Copy link
Contributor

I've just come across this after encountering the same issue. My app is a word game, so it's kinda important that people can see what they're entering! I've looked into the backend of libgdx and it's all based on using OnKeyListener which intercepts hardware keyboard presses but not necessarily soft keyboard presses. It's down to the individual keyboard app maker to fire this event if they want to. It appears that the Samsung keyboard app doesn't do this.

@bitdream what is this Gdx.input.getText() workaround you have? Could you post it? @carlislefox did you get any further with this?

I'm trying to understand how AndroidOnscreenKeyboard works as that possibly uses the underlying Android Editable which might be able to detect ALL keyboard presses, but I'm not getting any luck yet with any breakpoints firing

@wheelergames
Copy link
Contributor

So I've just added @congatobu fix, and tried changing language and it appears to still work. @mitrakov - any chance you can test it again on latest build of Libgdx (I forked 1.9.10 i think...i have so many diff branches it's hard to keep track). But if this works we can potentially get a PR in.

@Emperorlou
Copy link
Contributor

Emperorlou commented Jul 13, 2020 via email

@bitdream
Copy link

I've just come across this after encountering the same issue. My app is a word game, so it's kinda important that people can see what they're entering! I've looked into the backend of libgdx and it's all based on using OnKeyListener which intercepts hardware keyboard presses but not necessarily soft keyboard presses. It's down to the individual keyboard app maker to fire this event if they want to. It appears that the Samsung keyboard app doesn't do this.

@bitdream what is this Gdx.input.getText() workaround you have? Could you post it? @carlislefox did you get any further with this?

I'm trying to understand how AndroidOnscreenKeyboard works as that possibly uses the underlying Android Editable which might be able to detect ALL keyboard presses, but I'm not getting any luck yet with any breakpoints firing

When use Gdx.input.getText(), a very ugly and wired android native TextFild dialog will promote. I really don't recommend this if you could fix it.

@wheelergames
Copy link
Contributor

When use Gdx.input.getText(), a very ugly and wired android native TextFild dialog will promote. I really don't recommend this if you could fix it.

Got it. Well I think the original fix works well for me. I tried changing language as @mitrakov said that reset it, but it didn't for me. (I changed language using the keyboard/spacebar, not sure if there is another way that breaks it)

@bitdream
Copy link

@wheelergames it will be helpful if you could merge it to master. Someone in this thread said he will do it long before but he didn't 🤦‍♀️

@wheelergames
Copy link
Contributor

so 2 problems with that

  1. I don't, and no-one as far as I know on this thread, has merge permissions, all we can do is create a pull request and ask and wait
  2. I would want to get confirmation from @mitrakov or even @carlislefox that the change language issue doesn't break things.

I can make the PR sometime today though, and add the language comment, to see if more people can test it. Or if you want to help yourself you can try and run it from source yourself (if you know how?)

@wheelergames
Copy link
Contributor

wheelergames commented Jul 15, 2020

@bitdream @Emperorlou - maybe you can pull my fork and test it for yourselves? or at least comment on the PR to help try and bump it up the list and get some attention.

EDIT - had to redo the PR, it's now #6104 below

@bitdream
Copy link

bitdream commented Jul 15, 2020

@bitdream @Emperorlou - maybe you can pull my fork and test it for yourselves? or at least comment on the PR to help try and bump it up the list and get some attention.

EDIT - had to redo the PR, it's now #6104 below

I can learn to do it although I haven't done this before. How can I refer your fork in my project? Or should I download your code and make a test project to test it?

@wheelergames
Copy link
Contributor

I would, clone my fork to your local machine.

Then go through and change the version number from 1.9.11-SNAPSHOT to 1.9.11-bitdream-SNAPSHOT or something else unique (just because using the same version number can get cached a little on maven in my experience).

Once you've changed that in all the places, go to a terminal, navigate to the folder and run mvn install.

This should add the library to your local maven, and then in your project just add the bitdream version instead and make sure you have repositories { mavenLocal() } in your build.gradle (root)

@bitdream
Copy link

I would, clone my fork to your local machine.

Then go through and change the version number from 1.9.11-SNAPSHOT to 1.9.11-bitdream-SNAPSHOT or something else unique (just because using the same version number can get cached a little on maven in my experience).

Once you've changed that in all the places, go to a terminal, navigate to the folder and run mvn install.

This should add the library to your local maven, and then in your project just add the bitdream version instead and make sure you have repositories { mavenLocal() } in your build.gradle (root)
change the version number from 1.9.11-SNAPSHOT to 1.9.11-bitdream-SNAPSHOT => in which place?

@wheelergames
Copy link
Contributor

change the version number from 1.9.11-SNAPSHOT to 1.9.11-bitdream-SNAPSHOT => in which place?

In every place. Do a find replace all. I think it's 28 places

@bitdream
Copy link

bitdream commented Jul 16, 2020

I have leaved with the default 1.9.11-SNAPSHOT and tested on my Galaxy s10. It worked well. From the ponit view of users, it just turned off the auto compelte feature. I will test it on more phones later. I also tried switch between languages and found no problems.

@wheelergames
Copy link
Contributor

You mean the text entered and was visible as typing, and in addition the auto complete went away. My own goal is not to have auto complete go away, but just to get the keyboard working. I dont know if that would be a blocker to it getting merged? Thanks for testing the language swap though, at least that bit no longer appears to be broken.

Once tested, could you comment on the PR itself, and hopefully it'll get noticed. There's allegedly going to be a release of 1.9.11 this weekend, so it would be great if this could get merged before that!

@bitdream
Copy link

Text is always visible in my S10 but the auto complete feature makes the input messy. All the first auto complete clue are input in textfield even I didn't choose it and what's more, the backspace didn't work correctly.
So what you saw the bug is different from my side?!
Another thing I just noticed is that after your modification, the soft key board is not hiden even the focus is changed.
I suggest adding a flag to turn on this feature. The users can easily add their own isSamsung() method to turn on/off by themselves.

@wheelergames
Copy link
Contributor

For me the issue has always been, you type characters, and they don't appear until you close the keyboard, so people can't tell what they're entering. I've never attempted to use or hide the auto complete stuff. Are you saying that on your S10 you have never had this issue (before applying the fix?)

Also are you saying backspace doesn't work NOW, or it didn't work in the PAST?

How are you changing focus? By tapping somewhere else? Or doing something else?

So you would say add a turnOnFeature() that people can use to add this? Not a bad idea, though not sure how to remove those fields, but I'm sure it's doable

@bitdream
Copy link

I have just tested on another not-Samsung phone and it worked OK as before. So I released an update for my APP with your fix.
In S10, before the fix, when I type a letter and if there is an auto-complete-tip, all the tip will be inputed into textfield. Whne I typed backspace and since there are still auto-complete-tip, so an auto-complete-tip with one letter deleted will be inputed. Quite unusable.. And I never seen the problem your mentioned.
So far it's a good fix for me.
If it could be tested on enough devices, actually this turnOn/Off is not necessary.

@wheelergames
Copy link
Contributor

Ok, thanks. So the fix fixes something I have never seen, for you, and something you have never seen, for me! Sounds like it's getting better all the time!

@bitdream
Copy link

Thank you too I also learned how to use the source code and maybe in future I could do some contribution for this project😁

@NathanSweet
Copy link
Member

Closed by #6104

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

No branches or pull requests